Class: TingYun::Agent::Dispatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events, after_forker = TingYun::Agent) ⇒ Dispatcher

Returns a new instance of Dispatcher.



8
9
10
11
12
13
14
15
16
17
# File 'lib/ting_yun/agent/dispatcher.rb', line 8

def initialize(events, after_forker=TingYun::Agent)
  # We intentionally don't set our pid as started at this point.
  # Startup routines must call mark_started when they consider us set!
  @starting_pid = nil
  @after_forker = after_forker

  if events
    events.subscribe(:start_transaction, &method(:on_transaction))
  end
end

Instance Attribute Details

#starting_pidObject

Returns the value of attribute starting_pid.



6
7
8
# File 'lib/ting_yun/agent/dispatcher.rb', line 6

def starting_pid
  @starting_pid
end

Instance Method Details

#mark_started(pid = Process.pid) ⇒ Object



29
30
31
# File 'lib/ting_yun/agent/dispatcher.rb', line 29

def mark_started(pid = Process.pid)
  @starting_pid = pid
end

#needs_restart?(pid = Process.pid) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/ting_yun/agent/dispatcher.rb', line 33

def needs_restart?(pid = Process.pid)
  @starting_pid != pid
end

#on_transaction(*_) ⇒ Object



19
20
21
22
23
# File 'lib/ting_yun/agent/dispatcher.rb', line 19

def on_transaction(*_)
  return unless restart_in_children_enabled? && needs_restart?

  restart_harvest_thread
end

#restart_harvest_threadObject



37
38
39
# File 'lib/ting_yun/agent/dispatcher.rb', line 37

def restart_harvest_thread
  @after_forker.after_fork(:force_reconnect => true)
end

#restart_in_children_enabled?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ting_yun/agent/dispatcher.rb', line 25

def restart_in_children_enabled?
  TingYun::Agent.config[:restart_thread_in_children]
end