class StatHat::Reporter
Public Class Methods
new()
click to toggle source
# File lib/stathat.rb, line 97 def initialize @que = Queue.new @runlock = Mutex.new run_pool() end
Public Instance Methods
ez_post_count(stat_name, ezkey, count, timestamp, cb)
click to toggle source
# File lib/stathat.rb, line 132 def ez_post_count(stat_name, ezkey, count, timestamp, cb) args = { :stat => stat_name, :ezkey => ezkey, :count => count } args[:t] = timestamp unless timestamp.nil? enqueue(Common::EZ_URL, args, cb) end
ez_post_value(stat_name, ezkey, value, timestamp, cb)
click to toggle source
# File lib/stathat.rb, line 124 def ez_post_value(stat_name, ezkey, value, timestamp, cb) args = { :stat => stat_name, :ezkey => ezkey, :value => value } args[:t] = timestamp unless timestamp.nil? enqueue(Common::EZ_URL, args, cb) end
finish()
click to toggle source
# File lib/stathat.rb, line 103 def finish() stop_pool # XXX serialize queue? end
post_count(stat_key, user_key, count, timestamp, cb)
click to toggle source
# File lib/stathat.rb, line 116 def post_count(stat_key, user_key, count, timestamp, cb) args = { :key => stat_key, :ukey => user_key, :count => count } args[:t] = timestamp unless timestamp.nil? enqueue(Common::CLASSIC_COUNT_URL, args, cb) end
post_value(stat_key, user_key, value, timestamp, cb)
click to toggle source
# File lib/stathat.rb, line 108 def post_value(stat_key, user_key, value, timestamp, cb) args = { :key => stat_key, :ukey => user_key, :value => value } args[:t] = timestamp unless timestamp.nil? enqueue(Common::CLASSIC_VALUE_URL, args, cb) end
Private Instance Methods
enqueue(url, args, cb=nil)
click to toggle source
# File lib/stathat.rb, line 174 def enqueue(url, args, cb=nil) return false unless @running point = {:url => url, :args => args, :cb => cb} @que << point true end
run_pool()
click to toggle source
# File lib/stathat.rb, line 141 def run_pool @runlock.synchronize { @running = true } @pool = [] 5.times do |i| @pool[i] = Thread.new do while true do point = @que.pop # XXX check for error? begin resp = Common::send_to_stathat(point[:url], point[:args]) if point[:cb] point[:cb].call(resp) end rescue pp $! end @runlock.synchronize { break unless @running } end end end end
stop_pool()
click to toggle source
# File lib/stathat.rb, line 165 def stop_pool() @runlock.synchronize { @running = false } @pool.each do |th| th.join if th && th.alive? end end