Class: Adhearsion::Process
- Inherits:
-
Object
- Object
- Adhearsion::Process
- Includes:
- Singleton
- Defined in:
- lib/adhearsion/process.rb
Instance Attribute Summary (collapse)
-
- (Object) important_threads
Returns the value of attribute important_threads.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) die_now!
- - (Object) final_shutdown
- - (Object) fqdn
-
- (Process) initialize
constructor
A new instance of Process.
- - (Object) log_state_change(transition)
- - (Object) request_stop
- - (Object) stop_when_zero_calls
Constructor Details
- (Process) initialize
A new instance of Process
60 61 62 63 |
# File 'lib/adhearsion/process.rb', line 60 def initialize @important_threads = ThreadSafeArray.new super end |
Instance Attribute Details
- (Object) important_threads
Returns the value of attribute important_threads
58 59 60 |
# File 'lib/adhearsion/process.rb', line 58 def important_threads @important_threads end |
Class Method Details
+ (Object) method_missing(method_name, *args, &block)
108 109 110 |
# File 'lib/adhearsion/process.rb', line 108 def self.method_missing(method_name, *args, &block) instance.send method_name, *args, &block end |
Instance Method Details
- (Object) die_now!
100 101 102 |
# File 'lib/adhearsion/process.rb', line 100 def die_now! ::Process.exit 1 end |
- (Object) final_shutdown
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/adhearsion/process.rb', line 75 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 |
- (Object) fqdn
104 105 106 |
# File 'lib/adhearsion/process.rb', line 104 def fqdn Socket.gethostbyname(Socket.gethostname).first end |
- (Object) log_state_change(transition)
65 66 67 68 |
# File 'lib/adhearsion/process.rb', line 65 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 |
- (Object) request_stop
70 71 72 73 |
# File 'lib/adhearsion/process.rb', line 70 def request_stop Events.trigger_immediately :stop_requested important_threads << Thread.new { stop_when_zero_calls } end |
- (Object) stop_when_zero_calls
90 91 92 93 94 95 96 97 98 |
# File 'lib/adhearsion/process.rb', line 90 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 |