Class: MetOnTheMiddle::Collector
- Inherits:
-
Object
- Object
- MetOnTheMiddle::Collector
- Defined in:
- lib/met_on_the_middle/collector.rb
Constant Summary collapse
- MAX_QUEUE_SIZE_AUTOCLEAR =
100
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#sender ⇒ Object
Returns the value of attribute sender.
Instance Method Summary collapse
- #add(request) ⇒ Object
-
#initialize(sender) ⇒ Collector
constructor
A new instance of Collector.
- #submit ⇒ Object
Constructor Details
#initialize(sender) ⇒ Collector
Returns a new instance of Collector.
9 10 11 12 |
# File 'lib/met_on_the_middle/collector.rb', line 9 def initialize(sender) self.sender = sender @data = Hash.new end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/met_on_the_middle/collector.rb', line 5 def data @data end |
#sender ⇒ Object
Returns the value of attribute sender.
5 6 7 |
# File 'lib/met_on_the_middle/collector.rb', line 5 def sender @sender end |
Instance Method Details
#add(request) ⇒ Object
14 15 16 |
# File 'lib/met_on_the_middle/collector.rb', line 14 def add(request) @data[request.time]=request end |
#submit ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/met_on_the_middle/collector.rb', line 19 def submit Marshal.load(Marshal.dump(@data)).each do |k, v| self.sender.write(v) end self.clear rescue Exception => e if self.size>MAX_QUEUE_SIZE_AUTOCLEAR pre_clear = self.keys[self.size/2] self.reject! {|k, v| k<pre_clear} end end |