class Object
We extend object in ruby 1.9 to define ‘instance_exec’
{blog.jayfields.com/2006/09/ruby-instanceexec-aka-instanceeval.html Further reference}
Public Instance Methods
dispatch_rjr_util_inspect(dispatcher)
click to toggle source
Add inspection methods to specified dispatcher
# 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_uuid()
click to toggle source
Return a random uuid
# 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
instance_exec(*args, &block)
click to toggle source
Execute the specified block in the scope of the local object @param [Array] args array of args to be passed to block @param [Callable] block callable object to bind and invoke in the local namespace
# File lib/rjr/core_ext.rb, line 31 def instance_exec(*args, &block) begin old_critical, Thread.critical = Thread.critical, true n = 0 n += 1 while respond_to?(mname="__instance_exec#{n}") InstanceExecHelper.module_eval{ define_method(mname, &block) } ensure Thread.critical = old_critical end begin ret = send(mname, *args) ensure InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil end ret end
select_stats(dispatcher, *filter)
click to toggle source
Helper method to process user params / select stats from a dispatcher
# 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