Class: RestFtpDaemon::Counters
- Inherits:
-
Object
- Object
- RestFtpDaemon::Counters
- Includes:
- Singleton
- Defined in:
- lib/rest-ftp-daemon/counters.rb
Instance Method Summary collapse
- #add(group, name, value) ⇒ Object
- #get(group, name) ⇒ Object
- #increment(group, name) ⇒ Object
-
#initialize ⇒ Counters
constructor
A new instance of Counters.
- #set(group, name, value) ⇒ Object
- #stats ⇒ Object
Constructor Details
#initialize ⇒ Counters
Returns a new instance of Counters.
8 9 10 11 12 13 14 |
# File 'lib/rest-ftp-daemon/counters.rb', line 8 def initialize # Initialize values @stats = {} # Create mutex @mutex = Mutex.new end |
Instance Method Details
#add(group, name, value) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rest-ftp-daemon/counters.rb', line 29 def add group, name, value @mutex.synchronize do @stats[group] ||= {} @stats[group][name] ||= 0 @stats[group][name] += value end end |
#get(group, name) ⇒ Object
23 24 25 26 27 |
# File 'lib/rest-ftp-daemon/counters.rb', line 23 def get group, name @mutex.synchronize do @stats[group][name] if @stats[group].is_a? Hash end end |
#increment(group, name) ⇒ Object
37 38 39 |
# File 'lib/rest-ftp-daemon/counters.rb', line 37 def increment group, name add group, name, 1 end |
#set(group, name, value) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/rest-ftp-daemon/counters.rb', line 16 def set group, name, value @mutex.synchronize do @stats[group] ||= {} @stats[group][name] = value end end |
#stats ⇒ Object
41 42 43 |
# File 'lib/rest-ftp-daemon/counters.rb', line 41 def stats return @stats.dup end |