Sha256: 63ae1ab5dbb22b25c5866a879d0424310f821d814d5b8240da070ca28d43f595

Contents?: true

Size: 845 Bytes

Versions: 21

Compression:

Stored size: 845 Bytes

Contents

require 'singleton'

# Queue that stores all the Jobs waiting to be processed or fully processed
module RestFtpDaemon
  class Counters
    include Singleton

    def initialize
      # Initialize values
      @stats = {}

      # Create mutex
      @mutex = Mutex.new
    end

    def set group, name, value
      @mutex.synchronize do
        @stats[group] ||= {}
        @stats[group][name] = value
      end
    end

    def get group, name
      @mutex.synchronize do
        @stats[group][name] if @stats[group].is_a? Hash
      end
    end

    def add group, name, value
      @mutex.synchronize do
        @stats[group] ||= {}
        @stats[group][name] ||= 0
        @stats[group][name] += value
      end
    end

    def increment group, name
      add group, name, 1
    end

    def stats
      return @stats.dup
    end

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rest-ftp-daemon-1.1.1 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.1.0 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.15 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.14 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.13 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.12 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.11 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.10 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.9 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.8 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.7 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.6 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.5 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.4 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.3 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.2 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-1.0.1 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.502.2 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.502.1 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.502.0 lib/rest-ftp-daemon/counters.rb