class Octave::Agent
The agent handles managing the queue and dispatching the payload to each configured dispatcher.
Attributes
queue[R]
Public Class Methods
new()
click to toggle source
# File lib/octave/agent.rb, line 5 def initialize @queue = SizedQueue.new(Octave.config.max_queue) @running = false at_exit(&method(:stop)) end
Public Instance Methods
dispatch(payload)
click to toggle source
Adds the payload to the queue.
@param payload [Payload] the payload to be added to the queue.
# File lib/octave/agent.rb, line 15 def dispatch(payload) queue.push(payload) end
run()
click to toggle source
Loop to pass the payload to each dispatcher as the payload enters the queue.
# File lib/octave/agent.rb, line 37 def run while running? || !queue.empty? payload = queue.pop(false) call_dispatchers(payload) end end
running?()
click to toggle source
Determines whether the agent is running.
@return [Boolean]
# File lib/octave/agent.rb, line 59 def running? @running end
start()
click to toggle source
Start the agent process and begin dispatching events.
# 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()
click to toggle source
Stop the agent.
# File lib/octave/agent.rb, line 45 def stop return unless running? @queue.close @thread.exit dispatchers.each(&:close) @running = false true end
Private Instance Methods
call_dispatchers(payload)
click to toggle source
Submits the payload to each dispatcher.
# File lib/octave/agent.rb, line 68 def call_dispatchers(payload) dispatchers.each do |dispatcher| dispatcher.call(payload) end end
dispatchers()
click to toggle source
# File lib/octave/agent.rb, line 74 def dispatchers Octave.config.dispatchers end