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
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/thrift/processor.rb', line 155
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
103
|
# 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 = self.class.ancestors.each_with_object({}) do |klass, acc|
next unless klass.const_defined?(:METHODS, false)
klass::METHODS.each do |name, info|
acc[name] ||= build_processor(name, info)
end
end
end
|
#process(iprot, oprot) ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/thrift/processor.rb', line 119
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
105
106
107
108
109
110
|
# File 'lib/thrift/processor.rb', line 105
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
112
113
114
115
116
117
|
# File 'lib/thrift/processor.rb', line 112
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
|