Class: TingYun::Agent::Dispatcher
- Inherits:
-
Object
- Object
- TingYun::Agent::Dispatcher
- Defined in:
- lib/ting_yun/agent/dispatcher.rb
Instance Attribute Summary collapse
-
#starting_pid ⇒ Object
Returns the value of attribute starting_pid.
Instance Method Summary collapse
-
#initialize(events, after_forker = TingYun::Agent) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
- #mark_started(pid = Process.pid) ⇒ Object
- #needs_restart?(pid = Process.pid) ⇒ Boolean
- #on_transaction(*_) ⇒ Object
- #restart_harvest_thread ⇒ Object
- #restart_in_children_enabled? ⇒ Boolean
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_pid ⇒ Object
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
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_thread ⇒ Object
37 38 39 |
# File 'lib/ting_yun/agent/dispatcher.rb', line 37 def restart_harvest_thread @after_forker.after_fork(:force_reconnect => true) end |