Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/2.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed May 15, 2013
2 parents c1d4102 + 78b4b3a commit 8bfd4e7
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 48 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# [develop](https://github.com/adhearsion/adhearsion)

# [2.3.4](https://github.com/adhearsion/adhearsion/compare/v2.3.3...v2.3.4) - [2013-05-14](https://rubygems.org/gems/adhearsion/versions/2.3.4)
* Bugfix: Process signals safely in the main thread - fixes shutdown on Ruby 2.0
* Bugfix: Expose the cert store directory in Punchblock config

# [2.3.3](https://github.com/adhearsion/adhearsion/compare/v2.3.2...v2.3.3) - [2013-05-08](https://rubygems.org/gems/adhearsion/versions/2.3.3)
* Bugfix: Support Celluloid 0.14's new block semantics

Expand Down
1 change: 0 additions & 1 deletion adhearsion.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'countdownlatch'
s.add_runtime_dependency 'deep_merge'
s.add_runtime_dependency 'ffi', ["~> 1.0"]
s.add_runtime_dependency 'future-resource', ["~> 1.0"]
s.add_runtime_dependency 'girl_friday'
s.add_runtime_dependency 'has-guarded-handlers', ["~> 1.5"]
s.add_runtime_dependency 'jruby-openssl' if RUBY_PLATFORM == 'java'
Expand Down
2 changes: 1 addition & 1 deletion lib/adhearsion/call_controller/dial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Dial
# i.e. timeout after :for if no one answers the call
#
# @option options [CallController] :confirm the controller to execute on answered outbound calls to give an opportunity to screen the call. The calls will be joined if the outbound call is still active after this controller completes.
# @option options [Hash] :confirm_metadata Metadata to set on the confirmation controller before executing it.
# @option options [Hash] :confirm_metadata Metadata to set on the confirmation controller before executing it. This is shared between all calls if dialing multiple endpoints; if you care about it being mutated, you should provide an immutable value (using eg https://github.com/harukizaemon/hamster).
#
# @example Make a call to the PSTN using my SIP provider for VoIP termination
# dial "SIP/[email protected]"
Expand Down
9 changes: 4 additions & 5 deletions lib/adhearsion/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def method_missing(method_name, *args, &block)
instance.send method_name, *args, &block
end

def respond_to?(method_name)
instance.respond_to?(method_name) || super
def respond_to_missing?(method_name, include_private = false)
instance.respond_to? method_name, include_private
end

def instance
Expand Down Expand Up @@ -73,9 +73,8 @@ def method_missing(method_name, *args, &block)
register_handler method_name, *args, &block
end

def respond_to?(method_name)
return true if instance_variable_defined?(:@handlers) && @handlers.has_key?(method_name)
super
def respond_to_missing?(method_name, include_private = false)
instance_variable_defined?(:@handlers) && @handlers.has_key?(method_name)
end

alias :register_callback :register_handler
Expand Down
86 changes: 52 additions & 34 deletions lib/adhearsion/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,35 @@ def initialize(options = {})
end

def start
resolve_pid_file_path
load_lib_folder
load_config_file
initialize_log_paths

if should_daemonize?
daemonize!
else
create_pid_file
end
catch :boot_aborted do
resolve_pid_file_path
load_lib_folder
load_config_file
initialize_log_paths

if should_daemonize?
daemonize!
else
create_pid_file
end

Adhearsion.statistics
start_logging
debugging_log
launch_console if need_console?
catch_termination_signal
set_ahn_proc_name
initialize_exception_logger
update_rails_env_var
init_plugins
Adhearsion.statistics
start_logging
debugging_log
launch_console if need_console?
catch_termination_signal
set_ahn_proc_name
initialize_exception_logger
update_rails_env_var
init_plugins

run_plugins
trigger_after_initialized_hooks
run_plugins
trigger_after_initialized_hooks

Adhearsion::Process.booted if Adhearsion.status == :booting
Adhearsion::Process.booted if Adhearsion.status == :booting

logger.info "Adhearsion v#{Adhearsion::VERSION} initialized in \"#{Adhearsion.config.platform.environment}\"!" if Adhearsion.status == :running
logger.info "Adhearsion v#{Adhearsion::VERSION} initialized in \"#{Adhearsion.config.platform.environment}\"!" if Adhearsion.status == :running
end

# This method will block until all important threads have finished.
# When it does, the process will exit.
Expand Down Expand Up @@ -130,24 +132,40 @@ def resolve_log_file_path
end

def catch_termination_signal
%w'INT TERM'.each do |process_signal|
trap process_signal do
logger.info "Received SIG#{process_signal}. Shutting down."
Adhearsion::Process.shutdown
self_read, self_write = IO.pipe

%w(INT TERM HUP ALRM ABRT).each do |sig|
trap sig do
self_write.puts sig
end
end

trap 'HUP' do
logger.debug "Received SIGHUP. Reopening logfiles."
Adhearsion::Logging.reopen_logs
Thread.new do
begin
while readable_io = IO.select([self_read])
signal = readable_io.first[0].gets.strip
handle_signal signal
end
rescue => e
logger.error "Crashed reading signals"
logger.error e
exit 1
end
end
end

trap 'ALRM' do
def handle_signal(signal)
case signal
when 'INT', 'TERM'
logger.info "Received SIG#{signal}. Shutting down."
Adhearsion::Process.shutdown
when 'HUP'
logger.debug "Received SIGHUP. Reopening logfiles."
Adhearsion::Logging.reopen_logs
when 'ALRM'
logger.debug "Received SIGALRM. Toggling trace logging."
Adhearsion::Logging.toggle_trace!
end

trap 'ABRT' do
when 'ABRT'
logger.info "Received ABRT signal. Forcing stop."
Adhearsion::Process.force_stop
end
Expand Down
1 change: 1 addition & 0 deletions lib/adhearsion/punchblock_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PunchblockPlugin < Plugin
password "1" , :desc => "Authentication credentials"
host nil , :desc => "Host punchblock needs to connect (where rayo/asterisk/freeswitch is located)"
port Proc.new { PunchblockPlugin.default_port_for_platform platform }, :transform => Proc.new { |v| PunchblockPlugin.validate_number v }, :desc => "Port punchblock needs to connect"
certs_directory nil , :desc => "Directory containing certificates for securing the connection."
root_domain nil , :desc => "The root domain at which to address the server"
calls_domain nil , :desc => "The domain at which to address calls"
mixers_domain nil , :desc => "The domain at which to address mixers"
Expand Down
3 changes: 3 additions & 0 deletions lib/adhearsion/punchblock_plugin/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def init
:connection_timeout => self.config.connection_timeout,
:host => self.config.host,
:port => self.config.port,
:certs => self.config.certs_directory,
:root_domain => self.config.root_domain,
:calls_domain => self.config.calls_domain,
:mixers_domain => self.config.mixers_domain,
Expand Down Expand Up @@ -106,6 +107,8 @@ def connect

# Wait for the connection to establish
m.synchronize { blocker.wait m }

throw :boot_aborted if self.attempts >= self.config.reconnect_attempts
end

def connect_to_server
Expand Down
2 changes: 1 addition & 1 deletion lib/adhearsion/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: utf-8

module Adhearsion
VERSION = '2.3.3'
VERSION = '2.3.4'
end
8 changes: 8 additions & 0 deletions spec/adhearsion/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ module Adhearsion
Events.clear_handlers :event, EventClass
end

it "should respond_to? any methods corresponding to classes for which handlers are defined" do
Events.register_handler :event_type_1 do |event|
end

Events.should respond_to(:event_type_1)
Events.should_not respond_to(:event_type_2)
end

describe '#draw' do
it "should allow registering handlers by type" do
result = nil
Expand Down
16 changes: 10 additions & 6 deletions spec/adhearsion/punchblock_plugin/initializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def reset_default_config
config.password = "1"
config.host = nil
config.port = nil
config.certs_directory = nil
config.root_domain = nil
config.calls_domain = nil
config.mixers_domain = nil
Expand All @@ -33,6 +34,7 @@ def initialize_punchblock(options = {})
config.password = options[:password] if options.has_key?(:password)
config.host = options[:host] if options.has_key?(:host)
config.port = options[:port] if options.has_key?(:port)
config.certs_directory = options[:certs_directory] if options.has_key?(:certs_directory)
config.root_domain = options[:root_domain] if options.has_key?(:root_domain)
config.calls_domain = options[:calls_domain] if options.has_key?(:calls_domain)
config.mixers_domain = options[:mixers_domain] if options.has_key?(:mixers_domain)
Expand Down Expand Up @@ -80,6 +82,10 @@ def initialize_punchblock(options = {})
subject.port.should be_nil
end

it "should set properly the certs_directory value" do
subject.certs_directory.should be_nil
end

it "should set properly the root_domain value" do
subject.root_domain.should be_nil
end
Expand Down Expand Up @@ -117,10 +123,8 @@ def initialize_punchblock(options = {})
end

it "starts the client with any overridden settings" do
overrides = {:username => '[email protected]/foo', :password => '123', :host => 'foo.bar.com', :port => 200, :connection_timeout => 20, :root_domain => 'foo.com', :calls_domain => 'call.foo.com', :mixers_domain => 'mixer.foo.com', :media_engine => :swift, :default_voice => :hal}

Punchblock::Connection::XMPP.should_receive(:new).once.with(overrides).and_return mock_client
initialize_punchblock overrides
Punchblock::Connection::XMPP.should_receive(:new).once.with(username: '[email protected]/foo', password: '123', host: 'foo.bar.com', port: 200, certs: '/foo/bar', connection_timeout: 20, root_domain: 'foo.com', calls_domain: 'call.foo.com', mixers_domain: 'mixer.foo.com', media_engine: :swift, default_voice: :hal).and_return mock_client
initialize_punchblock username: '[email protected]/foo', password: '123', host: 'foo.bar.com', port: 200, certs_directory: '/foo/bar', connection_timeout: 20, root_domain: 'foo.com', calls_domain: 'call.foo.com', mixers_domain: 'mixer.foo.com', media_engine: :swift, default_voice: :hal
end

describe "#connect" do
Expand Down Expand Up @@ -180,7 +184,7 @@ def initialize_punchblock(options = {})
end

describe 'using Asterisk' do
let(:overrides) { {:username => 'test', :password => '123', :host => 'foo.bar.com', :port => 200, :connection_timeout => 20, :root_domain => 'foo.com', :calls_domain => 'call.foo.com', :mixers_domain => 'mixer.foo.com', :media_engine => :swift, :default_voice => :hal} }
let(:overrides) { {:username => 'test', :password => '123', :host => 'foo.bar.com', :port => 200, :certs => nil, :connection_timeout => 20, :root_domain => 'foo.com', :calls_domain => 'call.foo.com', :mixers_domain => 'mixer.foo.com', :media_engine => :swift, :default_voice => :hal} }

it 'should start an Asterisk PB connection' do
Punchblock::Connection::Asterisk.should_receive(:new).once.with(overrides).and_return mock_client
Expand All @@ -189,7 +193,7 @@ def initialize_punchblock(options = {})
end

describe 'using FreeSWITCH' do
let(:overrides) { {:username => 'test', :password => '123', :host => 'foo.bar.com', :port => 200, :connection_timeout => 20, :root_domain => 'foo.com', :calls_domain => 'call.foo.com', :mixers_domain => 'mixer.foo.com', :media_engine => :swift, :default_voice => :hal} }
let(:overrides) { {:username => 'test', :password => '123', :host => 'foo.bar.com', :port => 200, :certs => nil, :connection_timeout => 20, :root_domain => 'foo.com', :calls_domain => 'call.foo.com', :mixers_domain => 'mixer.foo.com', :media_engine => :swift, :default_voice => :hal} }

it 'should start a FreeSWITCH PB connection' do
Punchblock::Connection::Freeswitch.should_receive(:new).once.with(overrides).and_return mock_client
Expand Down

0 comments on commit 8bfd4e7

Please sign in to comment.