Sha256: a9cdbb643d6340c03b3b50b658fea69eda5bc4d5db91a5266b10bfbb01e74a3d

Contents?: true

Size: 846 Bytes

Versions: 25

Compression:

Stored size: 846 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

25 entries across 25 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.435.2 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.435.1 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.435.0 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.434.0 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.433.0 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.432.0 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.430.1 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.430.0 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.424.3 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.424.2 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.424.0 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.423.3 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.423.2 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.423.1 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.423.0 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.422.0 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.421.1 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.421.0 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.420.2 lib/rest-ftp-daemon/counters.rb
rest-ftp-daemon-0.420.1 lib/rest-ftp-daemon/counters.rb