Class: Carnivore::Utils::MessageRegistry
- Inherits:
-
Object
- Object
- Carnivore::Utils::MessageRegistry
- Defined in:
- lib/carnivore/utils/message_registry.rb
Overview
Registry used for preventing duplicate message processing
Instance Method Summary (collapse)
-
- (MessageRegistry) initialize
constructor
Create new instance.
-
- (self) push(item)
Register checksum into registry.
-
- (String) sha(thing)
Generate checksum for given item.
-
- (TrueClass, FalseClass) valid?(message)
Validity of message (not found within registry).
Constructor Details
- (MessageRegistry) initialize
Create new instance
8 9 10 11 |
# File 'lib/carnivore/utils/message_registry.rb', line 8 def initialize @store = [] @size = 100 end |
Instance Method Details
- (self) push(item)
Register checksum into registry
30 31 32 33 34 35 36 |
# File 'lib/carnivore/utils/message_registry.rb', line 30 def push(item) @store.push(item) if(@store.size > @size) @store.shift end self end |
- (String) sha(thing)
Generate checksum for given item
42 43 44 45 46 47 |
# File 'lib/carnivore/utils/message_registry.rb', line 42 def sha(thing) unless(thing.is_a?(String)) thing = MultiJson.dump(thing) end (Digest::SHA512.new << thing).hexdigest end |
- (TrueClass, FalseClass) valid?(message)
Validity of message (not found within registry)
17 18 19 20 21 22 23 24 |
# File 'lib/carnivore/utils/message_registry.rb', line 17 def valid?() checksum = sha() found = @store.include?(checksum) unless(found) push(checksum) end !found end |