Class: Octave::Agent
- Inherits:
-
Object
- Object
- Octave::Agent
- Defined in:
- lib/octave/agent.rb
Overview
The agent handles managing the queue and dispatching the payload to each configured dispatcher.
Instance Method Summary collapse
-
#dispatch(payload) ⇒ Object
Adds the payload to the queue.
-
#initialize ⇒ Agent
constructor
A new instance of Agent.
-
#run ⇒ Object
Loop to pass the payload to each dispatcher as the payload enters the queue.
-
#running? ⇒ Boolean
Determines whether the agent is running.
-
#start ⇒ Object
Start the agent process and begin dispatching events.
-
#stop ⇒ Object
Stop the agent.
Constructor Details
Instance Method Details
#dispatch(payload) ⇒ Object
Adds the payload to the queue.
15 16 17 |
# File 'lib/octave/agent.rb', line 15 def dispatch(payload) queue.push(payload) end |
#run ⇒ Object
Loop to pass the payload to each dispatcher as the payload enters the queue.
37 38 39 40 41 42 |
# File 'lib/octave/agent.rb', line 37 def run while running? || !queue.empty? payload = queue.pop(false) call_dispatchers(payload) end end |
#running? ⇒ Boolean
Determines whether the agent is running.
59 60 61 |
# File 'lib/octave/agent.rb', line 59 def running? @running end |
#start ⇒ Object
Start the agent process and begin dispatching events.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/octave/agent.rb', line 20 def start unless Octave.config.enabled? Octave.logger.warn do "Octave agent is disabled. Metrics will not be reported." end return end Octave.logger.info { "Starting Octave agent..." } @thread = Thread.new(&method(:run)) @running = true end |
#stop ⇒ Object
Stop the agent.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/octave/agent.rb', line 45 def stop return unless running? @queue.close @thread.exit dispatchers.each(&:close) @running = false true end |