Class: Octave::Agent

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeAgent

Returns a new instance of Agent.



5
6
7
8
9
10
# File 'lib/octave/agent.rb', line 5

def initialize
  @queue   = SizedQueue.new(Octave.config.max_queue)
  @running = false

  at_exit(&method(:stop))
end

Instance Method Details

#dispatch(payload) ⇒ Object

Adds the payload to the queue.

Parameters:

  • payload (Payload)

    the payload to be added to the queue.



15
16
17
# File 'lib/octave/agent.rb', line 15

def dispatch(payload)
  queue.push(payload)
end

#runObject

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.

Returns:

  • (Boolean)


59
60
61
# File 'lib/octave/agent.rb', line 59

def running?
  @running
end

#startObject

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

#stopObject

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