Class: MetOnTheMiddle::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/met_on_the_middle/collector.rb

Constant Summary collapse

MAX_QUEUE_SIZE_AUTOCLEAR =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/met_on_the_middle/collector.rb', line 5

def data
  @data
end

#senderObject

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

#submitObject



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