Class: IoMonitor::Aggregator

Inherits:
Object
  • Object
show all
Defined in:
lib/io_monitor/aggregator.rb

Overview

Thread-safe payload size aggregator.

Defined Under Namespace

Classes: InputPayload

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sources) ⇒ Aggregator

Returns a new instance of Aggregator.



6
7
8
# File 'lib/io_monitor/aggregator.rb', line 6

def initialize(sources)
  @sources = sources
end

Instance Attribute Details

#sourcesObject (readonly)

Returns the value of attribute sources.



10
11
12
# File 'lib/io_monitor/aggregator.rb', line 10

def sources
  @sources
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/io_monitor/aggregator.rb', line 12

def active?
  InputPayload.active.present?
end

#get(source) ⇒ Object



31
32
33
34
# File 'lib/io_monitor/aggregator.rb', line 31

def get(source)
  InputPayload.state ||= empty_state
  InputPayload.state[source.to_sym]
end

#increment(source, val) ⇒ Object



24
25
26
27
28
29
# File 'lib/io_monitor/aggregator.rb', line 24

def increment(source, val)
  return unless active?

  InputPayload.state ||= empty_state
  InputPayload.state[source.to_sym] += val
end

#start!Object



16
17
18
# File 'lib/io_monitor/aggregator.rb', line 16

def start!
  InputPayload.active = true
end

#stop!Object



20
21
22
# File 'lib/io_monitor/aggregator.rb', line 20

def stop!
  InputPayload.active = false
end