Class: Reacter::RelayAgent

Inherits:
Agent
  • Object
show all
Defined in:
lib/reacter/agents/relay.rb

Instance Attribute Summary

Attributes inherited from Agent

#config, #type

Instance Method Summary collapse

Methods inherited from Agent

create

Constructor Details

#initializeRelayAgent

Returns a new instance of RelayAgent.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/reacter/agents/relay.rb', line 9

def initialize()
  super

  @_adapters = []
  @_signature = Util.signature(object_id.to_s(16).upcase)

  @config = (@config.is_a?(Hash) ? [@config] : [*@config])

  @config.each do |c|
    if c['type']
      adapter = Adapter.create(c['type'], c)
      adapter.connect({
        :mode => 'write'
      })
      @_adapters << adapter
      Util.info("Relaying messages via #{c['type']} adapter")
    end
  end

  @_adapter_cycle = @_adapters.cycle.each
end

Instance Method Details

#received(message) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/reacter/agents/relay.rb', line 31

def received(message)
  adapter = @_adapter_cycle.next

  if adapter
    message[:relayed_from] = @_signature unless (adapter.config['transparent'] === true)
    adapter.send(message, adapter.config['format'])
  else
    Util.warn("relay: Message received without an active relay adapter, dropping")
    return false
  end

  return message
end