Class: TimeWindowDropCollector
- Inherits:
-
Object
- Object
- TimeWindowDropCollector
- Defined in:
- lib/time_window_drop_collector.rb,
lib/time_window_drop_collector/version.rb,
lib/time_window_drop_collector/wrappers/mock.rb,
lib/time_window_drop_collector/wrappers/redis.rb,
lib/time_window_drop_collector/wrappers/memcache.rb,
lib/time_window_drop_collector/wrappers/rails_cache.rb
Defined Under Namespace
Modules: Config, Logger, Utils, Wrapper, Wrappers Classes: Results, Storage
Constant Summary collapse
- VERSION =
"0.3.3"
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
-
#wrapper ⇒ Object
readonly
Returns the value of attribute wrapper.
Instance Method Summary collapse
- #count(orig_keys) ⇒ Object
- #drop(keys, amount = 1) ⇒ Object
-
#initialize(&block) ⇒ TimeWindowDropCollector
constructor
A new instance of TimeWindowDropCollector.
- #pick(time, keys, amount = 1) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(&block) ⇒ TimeWindowDropCollector
Returns a new instance of TimeWindowDropCollector.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/time_window_drop_collector.rb', line 18 def initialize( &block ) TimeWindowDropCollector::Logger.log "INITIALIZING version: #{TimeWindowDropCollector::VERSION}" @config = { :window => 600, :slices => 10, :client => :memcache, :client_opts => "localhost:11211" } @config.merge!( TimeWindowDropCollector::Config.extract( block ) ) if block_given? TimeWindowDropCollector::Logger.log "CONFIG: #{config}" @wrapper = TimeWindowDropCollector::Wrapper.instance( config[:client], config[:client_opts] ) @storage = TimeWindowDropCollector::Storage.new( wrapper, config[:window], config[:slices] ) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/time_window_drop_collector.rb', line 16 def config @config end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
16 17 18 |
# File 'lib/time_window_drop_collector.rb', line 16 def storage @storage end |
#wrapper ⇒ Object (readonly)
Returns the value of attribute wrapper.
16 17 18 |
# File 'lib/time_window_drop_collector.rb', line 16 def wrapper @wrapper end |
Instance Method Details
#count(orig_keys) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/time_window_drop_collector.rb', line 53 def count( orig_keys ) keys = orig_keys.is_a?(Array) ? orig_keys : [orig_keys] keys = keys.map(&:to_s) TimeWindowDropCollector::Logger.log "COUNT keys: #{keys.join(", ")}" result = storage.count( keys ) result = TimeWindowDropCollector::Results.new( result ) result = result[orig_keys.to_s] unless orig_keys.is_a? Array TimeWindowDropCollector::Logger.log "COUNT result: #{result}" result end |
#drop(keys, amount = 1) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/time_window_drop_collector.rb', line 36 def drop( keys, amount=1 ) keys = [keys] unless keys.is_a? Array keys = keys.map(&:to_s) TimeWindowDropCollector::Logger.log "DROP keys: #{keys.join(", ")}, amount: #{amount}" storage.incr( keys, amount ) end |
#pick(time, keys, amount = 1) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/time_window_drop_collector.rb', line 44 def pick( time, keys, amount=1) keys = [keys] unless keys.is_a? Array keys = keys.map(&:to_s) TimeWindowDropCollector::Logger.log "PICK keys: #{keys.join(", ")}, amount: #{amount}" storage.decr( time, keys, amount ) end |
#reset ⇒ Object
68 69 70 |
# File 'lib/time_window_drop_collector.rb', line 68 def reset wrapper.reset end |