module Thrift::Processor

Public Class Methods

new(handler, middlewares = []) click to toggle source
   # File lib/thrift/processor.rb
22 def initialize(handler, middlewares = [])
23   @handler = handler
24   @middleware = Middleware.wrap(middlewares)
25 end

Public Instance Methods

process(iprot, oprot) click to toggle source
   # File lib/thrift/processor.rb
27 def process(iprot, oprot)
28   name, _type, seqid = iprot.read_message_begin
29   if respond_to?("process_#{name}")
30     begin
31       send("process_#{name}", seqid, iprot, oprot)
32     rescue => e
33       write_exception(e, oprot, name, seqid)
34     end
35     true
36   else
37     iprot.skip(Types::STRUCT)
38     iprot.read_message_end
39     write_exception(
40       ApplicationException.new(
41         ApplicationException::UNKNOWN_METHOD,
42         'Unknown function ' + name,
43       ),
44       oprot,
45       name,
46       seqid
47     )
48     false
49   end
50 end
read_args(iprot, args_class) click to toggle source
   # File lib/thrift/processor.rb
52 def read_args(iprot, args_class)
53   args = args_class.new
54   args.read(iprot)
55   iprot.read_message_end
56   args
57 end
write_exception(exception, oprot, name, seqid) click to toggle source
   # File lib/thrift/processor.rb
59 def write_exception(exception, oprot, name, seqid)
60   oprot.write_message_begin(name, MessageTypes::EXCEPTION, seqid)
61 
62   unless exception.is_a? ApplicationException
63     exception = ApplicationException.new(
64       ApplicationException::INTERNAL_ERROR,
65       "Internal error processing #{name}: #{exception.class}: #{exception}"
66     )
67   end
68 
69   exception.write(oprot)
70   oprot.write_message_end
71   oprot.trans.flush
72 end
write_result(result, oprot, name, seqid) click to toggle source
   # File lib/thrift/processor.rb
74 def write_result(result, oprot, name, seqid)
75   oprot.write_message_begin(name, MessageTypes::REPLY, seqid)
76   result.write(oprot)
77   oprot.write_message_end
78   oprot.trans.flush
79 end