Class: Stark::Rack::LoggingProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/stark/rack/logging_processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(handler, secondary = nil) ⇒ LoggingProcessor

Returns a new instance of LoggingProcessor.



7
8
9
10
# File 'lib/stark/rack/logging_processor.rb', line 7

def initialize(handler, secondary=nil)
  @handler = handler
  @secondary = secondary
end

Instance Method Details

#process(iprot, oprot) ⇒ Object



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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/stark/rack/logging_processor.rb', line 12

def process(iprot, oprot)
  name, type, seqid = iprot.read_message_begin
  x = nil
  if @handler.respond_to?("process_#{name}")
    begin
      @handler.send("process_#{name}", seqid, iprot, oprot)
    rescue StandardError => e
      Stark.logger.error "#{@handler.class.name}#process_#{name}: #{e.message}\n  " + e.backtrace.join("\n  ")
      x = Thrift::ApplicationException.new(
                       Thrift::ApplicationException::UNKNOWN,
                       "#{e.message} (#{e.class})")
      x.cause = e
      oprot.write_message_begin(name, Thrift::MessageTypes::EXCEPTION, seqid)
      x.write(oprot)
      oprot.write_message_end
      oprot.trans.flush
    end

    if s = @secondary
      if x
        s.error name, type, seqid, x
      else
        s.success name, type, seqid
      end
    end

    [name, type, seqid, x]
  else
    iprot.skip(Thrift::Types::STRUCT)
    iprot.read_message_end
    x = Thrift::ApplicationException.new(Thrift::ApplicationException::UNKNOWN_METHOD,
                                 "Unknown function: #{name}")
    oprot.write_message_begin(name, Thrift::MessageTypes::EXCEPTION, seqid)
    x.write(oprot)
    oprot.write_message_end
    oprot.trans.flush
    if s = @secondary
      s.error name, type, seqid, x
    end
    false
  end
end