Module: Thrift::Processor
Defined Under Namespace
Classes: BaseProcessor, BaseProcessorFunction, BaseStreamProcessor, BidiStreamProcessor, BinaryProcessor, BinaryProcessorFunction, InboundStreamProcessor, OutboundStreamProcessor, UnaryProcessor, UnaryProcessorFunction, UnkwonFunctionProcessor
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.write_exception(exception, oprot, name, seqid) ⇒ Object
.write_internal_error(exception, oprot, name, seqid) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/thrift/processor.rb', line 154
def self.write_internal_error(exception, oprot, name, seqid)
write_exception(
ApplicationException.new(
ApplicationException::INTERNAL_ERROR,
"Internal error processing #{name}: #{exception.class}: #{exception}"
),
oprot,
name,
seqid
)
end
|
Instance Method Details
#build_processor(name, info) ⇒ Object
#initialize(handler, middlewares = [], logger = nil) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/thrift/processor.rb', line 85
def initialize(handler, middlewares = [], logger=nil)
@handler = handler
if logger.nil?
@logger = Logger.new(STDERR)
@logger.level = Logger::WARN
else
@logger = logger
end
@middleware = Middleware.wrap(middlewares)
@processors = if self.class.const_defined? :METHODS
self.class::METHODS.reduce({}) do |acc, (name, info)|
acc.merge(name => build_processor(name, info))
end
else
{}
end
end
|
#process(iprot, oprot) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/thrift/processor.rb', line 118
def process(iprot, oprot)
name, type, seqid = iprot.read_message_begin
mth = "process_#{name}"
if respond_to?(mth)
begin
send(mth, seqid, iprot, oprot)
rescue StandardError => e
raise e if type == MessageTypes::ONEWAY
Processor.write_internal_error(e, oprot, name, seqid)
end
return true
end
(
@processors[name] || UnkwonFunctionProcessor.new(name)
).process(seqid, iprot, oprot)
end
|
#read_args(iprot, args_class) ⇒ Object
104
105
106
107
108
109
|
# File 'lib/thrift/processor.rb', line 104
def read_args(iprot, args_class)
args = args_class.new
args.read(iprot)
iprot.read_message_end
args
end
|
#write_result(result, oprot, name, seqid) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/thrift/processor.rb', line 111
def write_result(result, oprot, name, seqid)
oprot.write_message_begin(name, MessageTypes::REPLY, seqid)
result.write(oprot)
oprot.write_message_end
oprot.trans.flush
end
|