Class: Stark::Processor

Inherits:
Object
  • Object
show all
Includes:
ProtocolHelpers
Defined in:
lib/stark/processor.rb

Constant Summary

Constants included from ProtocolHelpers

Stark::ProtocolHelpers::COERCION_FROM_STRING, Stark::ProtocolHelpers::COERCION_TO_STRING, Stark::ProtocolHelpers::THRIFT_TO_RUBY

Instance Method Summary collapse

Methods included from ProtocolHelpers

#expect, #expect_list, #expect_map, #expect_set, #hash_cast, #valid_element_type?, #value_for_write

Constructor Details

#initialize(handler) ⇒ Processor

Returns a new instance of Processor.



7
8
9
# File 'lib/stark/processor.rb', line 7

def initialize(handler)
  @handler = handler
end

Instance Method Details

#process(iprot, oprot) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/stark/processor.rb', line 11

def process(iprot, oprot)
  name, type, seqid  = iprot.read_message_begin
  fail unless type == Thrift::MessageTypes::CALL

  x = nil
  if respond_to?("process_#{name}")
    send("process_#{name}", seqid, iprot, oprot)
    true
  else
    iprot.skip(::Thrift::Types::STRUCT)
    iprot.read_message_end
    x = ::Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD, 'Unknown function '+name)
    false
  end
rescue ::Exception => e
  Stark.logger.error "#{self.class.name}#process_#{name}: #{e.message}\n  " + e.backtrace.join("\n  ")
  x = Thrift::ApplicationException.new(Thrift::ApplicationException::INTERNAL_ERROR, e.message)
  false
ensure
  if x
    oprot.write_message_begin(name, ::Thrift::MessageTypes::EXCEPTION, seqid)
    x.write(oprot)
    oprot.write_message_end
    oprot.trans.flush
  end
end