Sha256: bccb8ea172beba256fef49f6eade2ee1a17216e30c5bbd024fb00eb3e0853977
Contents?: true
Size: 943 Bytes
Versions: 2
Compression:
Stored size: 943 Bytes
Contents
require 'thread' require 'logger' module Anschel class Stats def initialize interval, logger @logger = logger @interval = interval || 30 @stats = Hash.new @lock = Mutex.new @logger.info event: 'stats-loaded' end def read ; stats end def create name, init=0 with_lock do stats[name] = init stats end end def delete name with_lock do stats.delete name end end def inc name, by=1 with_lock do stats[name] += by end end def dec name, by=1 with_lock do stats[name] -= by end end def set name, to with_lock do stats[name] = to end end def get name with_lock do stats[name] end end private attr_reader :stats def with_lock &block @lock.synchronize do yield end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
anschel-0.7.11 | lib/anschel/stats.rb |
anschel-0.7.10 | lib/anschel/stats.rb |