Class: MyStuff::Fb303::ProxyHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/my_stuff/fb303/proxy_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ ProxyHandler

Returns a new instance of ProxyHandler.



6
7
8
# File 'lib/my_stuff/fb303/proxy_handler.rb', line 6

def initialize server
  @s = server
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



10
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
37
38
# File 'lib/my_stuff/fb303/proxy_handler.rb', line 10

def method_missing meth, *args
  @s.increment_counter "#{meth}.called"
  begin
    result = @s.send(meth, *args)
    @s.increment_counter "#{meth}.success"
    result
  rescue => e
    @s.increment_counter "#{meth}.exception"
    @s.increment_counter "#{meth}.exception.#{e.class.name}"

    if e.is_a? Thrift::Exception
      # Presumably defined in the Thrift interface file
      level = :warn
    else
      # Definitely not :(
      level = :error
    end

    begin
      # MyStuff::Logger exception, allowing us to specify the
      # backtrace.
      @s.logger.raw_log e.backtrace, level, e
    rescue NoMethoderror
      @s.logger.send level, e
    end

    raise
  end
end