Class: AppPerfAgent::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/app_perf_agent/dispatcher.rb

Instance Method Summary collapse

Constructor Details

#initializeDispatcher

Returns a new instance of Dispatcher.



7
8
9
10
# File 'lib/app_perf_agent/dispatcher.rb', line 7

def initialize
  @start_time = Time.now
  @queue = Queue.new
end

Instance Method Details

#add_event(event) ⇒ Object



12
13
14
# File 'lib/app_perf_agent/dispatcher.rb', line 12

def add_event(event)
  @queue << event
end

#dispatchObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/app_perf_agent/dispatcher.rb', line 33

def dispatch
  begin
    events = drain(@queue)
    dispatch_events(events.dup)
  rescue => ex
    ::AppPerfAgent.logger.error "#{ex.inspect}"
    ::AppPerfAgent.logger.error "#{ex.backtrace.inspect}"
  ensure
    reset
  end
end

#dispatch_intervalObject



20
21
22
# File 'lib/app_perf_agent/dispatcher.rb', line 20

def dispatch_interval
  30
end

#queue_empty?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/app_perf_agent/dispatcher.rb', line 16

def queue_empty?
  @queue.size.to_i == 0
end

#ready?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/app_perf_agent/dispatcher.rb', line 24

def ready?
  Time.now > @start_time + dispatch_interval.to_f && !queue_empty?
end

#resetObject



28
29
30
31
# File 'lib/app_perf_agent/dispatcher.rb', line 28

def reset
  @queue.clear
  @start_time = Time.now
end