class RestFtpDaemon::Counters

Public Class Methods

new() click to toggle source
# File lib/rest-ftp-daemon/counters.rb, line 8
def initialize
  # Initialize values
  @stats = {}

  # Create mutex
  @mutex = Mutex.new
end

Public Instance Methods

add(group, name, value) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/rest-ftp-daemon/counters.rb, line 37
def increment group, name
  add group, name, 1
end
set(group, name, value) click to toggle source
# 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() click to toggle source
# File lib/rest-ftp-daemon/counters.rb, line 41
def stats
  return @stats.dup
end