Class: Adhearsion::Process
- Includes:
- Singleton
- Defined in:
- lib/adhearsion/process.rb
Instance Attribute Summary collapse
-
#important_threads ⇒ Object
Returns the value of attribute important_threads.
Class Method Summary collapse
Instance Method Summary collapse
- #die_now! ⇒ Object
- #final_shutdown ⇒ Object
- #fqdn ⇒ Object
-
#initialize ⇒ Process
constructor
A new instance of Process.
- #log_state_change(transition) ⇒ Object
- #quiesce ⇒ Object
- #request_stop ⇒ Object
- #stop_when_zero_calls ⇒ Object
Constructor Details
#initialize ⇒ Process
Returns a new instance of Process.
61 62 63 64 |
# File 'lib/adhearsion/process.rb', line 61 def initialize @important_threads = ThreadSafeArray.new super end |
Instance Attribute Details
#important_threads ⇒ Object
Returns the value of attribute important_threads.
59 60 61 |
# File 'lib/adhearsion/process.rb', line 59 def important_threads @important_threads end |
Class Method Details
.method_missing(method_name, *args, &block) ⇒ Object
113 114 115 |
# File 'lib/adhearsion/process.rb', line 113 def self.method_missing(method_name, *args, &block) instance.send method_name, *args, &block end |
Instance Method Details
#die_now! ⇒ Object
105 106 107 |
# File 'lib/adhearsion/process.rb', line 105 def die_now! ::Process.exit 1 end |
#final_shutdown ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/adhearsion/process.rb', line 80 def final_shutdown Adhearsion.active_calls.each do |_, call| call.hangup end # This should shut down any remaining threads. Once those threads have # stopped, important_threads will be empty and the process will exit # normally. Events.trigger_immediately :shutdown Console.stop logger.info "Adhearsion shut down" end |
#fqdn ⇒ Object
109 110 111 |
# File 'lib/adhearsion/process.rb', line 109 def fqdn Socket.gethostbyname(Socket.gethostname).first end |
#log_state_change(transition) ⇒ Object
66 67 68 69 |
# File 'lib/adhearsion/process.rb', line 66 def log_state_change(transition) event, from, to = transition.event, transition.from_name, transition.to_name logger.info "Transitioning from #{from} to #{to} with #{Adhearsion.active_calls.size} active calls due to #{event} event." end |
#quiesce ⇒ Object
76 77 78 |
# File 'lib/adhearsion/process.rb', line 76 def quiesce Events.trigger_immediately :quiesced end |
#request_stop ⇒ Object
71 72 73 74 |
# File 'lib/adhearsion/process.rb', line 71 def request_stop Events.trigger_immediately :stop_requested important_threads << Thread.new { stop_when_zero_calls } end |
#stop_when_zero_calls ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/adhearsion/process.rb', line 95 def stop_when_zero_calls i = 0 until Adhearsion.active_calls.count == 0 logger.info "Stop requested but we still have #{Adhearsion.active_calls.count} active calls." if (i % 50) == 0 sleep 0.2 i += 1 end final_shutdown end |