Top Level Namespace

Defined Under Namespace

Modules: Kernel, RJR Classes: Class, Object, String

Instance Method Summary collapse

Instance Method Details

#dispatch_rjr_util_inspect(dispatcher) ⇒ Object

Add inspection methods to specified dispatcher



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rjr/util/inspect.rb', line 54

def dispatch_rjr_util_inspect(dispatcher)
  # Retrieve all the dispatches this node served matching the specified criteri
  dispatcher.handle "rjr::dispatches" do |filter|
    select_stats(dispatcher, *filter) 
  end

  # Retrieve the number of dispatches this node served matching the specified criteria
  dispatcher.handle "rjr::num_dispatches" do |filter|
    select_stats(dispatcher, *filter).size
  end

  # Retrieve the internal status of this node
  dispatcher.handle "rjr::status" do
    nodes = []
    ObjectSpace.each_object RJR::Node do |node|
      nodes << node.to_s
    end

    {
      # nodes
      :nodes => nodes,

      # dispatcher
      :dispatcher => {
        :requests => dispatcher.requests.size,
        :handlers =>
          dispatcher.handlers.keys,
          #dispatcher.handlers.collect { |k,v|
          #  [k, v.source_location] },
        :environments => dispatcher.environments
      },

      # event machine
      :event_machine => { :running => EventMachine.reactor_running?,
                          :thread_status =>
                           (RJR::Node.em && RJR::Node.em.reactor_thread) ?
                                RJR::Node.em.reactor_thread.status : nil,
                          :connections => EventMachine.connection_count },

      # thread pool
      :thread_pool => { :running => RJR::Node.tp ? RJR::Node.tp.running? : nil }
    }
  end

  #:log =>
  #  lambda {},
end

#gen_uuidObject

Return a random uuid



11
12
13
14
# File 'lib/rjr/common.rb', line 11

def gen_uuid
  ["%02x"*4, "%02x"*2, "%02x"*2, "%02x"*2, "%02x"*6].join("-") %
      Array.new(16) {|x| rand(0xff) }
end

#select_stats(dispatcher, *filter) ⇒ Object

Helper method to process user params / select stats from a dispatcher



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rjr/util/inspect.rb', line 28

def select_stats(dispatcher, *filter)
  lf = []
  while q = filter.shift
    lf << 
      case q
      when 'on_node'    then
        n = filter.shift 
        lambda { |req| req.rjr_node_type.to_s == n}

      when "for_method" then
        m = filter.shift
        lambda { |req| req.rjr_method == m}

      when 'successful' then
        lambda { |req| req.result.success }

      when 'failed'     then
        lambda { |req| req.result.failed  }

      end
  end

  dispatcher.requests.select { |ds| lf.all? { |lfi| lfi.call(ds) } }
end