sevenscale-adhearsion 0.7.1003 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +8 -2
- data/EVENTS +11 -0
- data/Rakefile +92 -26
- data/adhearsion.gemspec +131 -23
- data/app_generators/ahn/ahn_generator.rb +21 -7
- data/app_generators/ahn/templates/.ahnrc +10 -4
- data/app_generators/ahn/templates/Rakefile +7 -2
- data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +15 -0
- data/app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE +7 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/config.yml +12 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
- data/app_generators/ahn/templates/components/simon_game/{lib/simon_game.rb → simon_game.rb} +14 -19
- data/app_generators/ahn/templates/config/startup.rb +3 -6
- data/app_generators/ahn/templates/dialplan.rb +2 -3
- data/app_generators/ahn/templates/events.rb +32 -6
- data/bin/jahn +10 -0
- data/examples/asterisk_manager_interface/standalone.rb +51 -0
- data/lib/adhearsion/cli.rb +140 -23
- data/lib/adhearsion/component_manager/component_tester.rb +55 -0
- data/lib/adhearsion/component_manager/spec_framework.rb +24 -0
- data/lib/adhearsion/component_manager.rb +169 -238
- data/lib/adhearsion/events_support.rb +59 -237
- data/lib/adhearsion/{core_extensions → foundation}/all.rb +0 -0
- data/lib/adhearsion/{blank_slate.rb → foundation/blank_slate.rb} +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/custom_daemonizer.rb +0 -0
- data/lib/adhearsion/foundation/event_socket.rb +203 -0
- data/lib/adhearsion/foundation/future_resource.rb +36 -0
- data/lib/adhearsion/{core_extensions → foundation}/global.rb +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/metaprogramming.rb +0 -0
- data/lib/adhearsion/foundation/numeric.rb +13 -0
- data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
- data/lib/adhearsion/{core_extensions → foundation}/relationship_properties.rb +2 -0
- data/lib/adhearsion/foundation/string.rb +26 -0
- data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
- data/lib/adhearsion/{core_extensions → foundation}/thread_safety.rb +0 -0
- data/lib/adhearsion/host_definitions.rb +5 -1
- data/lib/adhearsion/initializer/asterisk.rb +33 -11
- data/lib/adhearsion/initializer/configuration.rb +58 -6
- data/lib/adhearsion/initializer/database.rb +3 -46
- data/lib/adhearsion/initializer/drb.rb +9 -3
- data/lib/adhearsion/initializer/freeswitch.rb +3 -3
- data/lib/adhearsion/initializer/rails.rb +1 -1
- data/lib/adhearsion/initializer.rb +213 -87
- data/lib/adhearsion/tasks/deprecations.rb +59 -0
- data/lib/adhearsion/tasks.rb +2 -1
- data/lib/adhearsion/version.rb +3 -3
- data/lib/adhearsion/voip/asterisk/agi_server.rb +6 -6
- data/lib/adhearsion/voip/asterisk/commands.rb +100 -2
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1754 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +286 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +562 -0
- data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
- data/lib/adhearsion/voip/asterisk.rb +1 -8
- data/lib/adhearsion/voip/call.rb +5 -1
- data/lib/adhearsion/voip/dial_plan.rb +74 -61
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +1 -1
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +2 -6
- data/lib/adhearsion/voip/dsl/numerical_string.rb +2 -2
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +2 -2
- data/lib/adhearsion.rb +16 -11
- data/lib/theatre/README.markdown +64 -0
- data/lib/theatre/callback_definition_loader.rb +84 -0
- data/lib/theatre/guid.rb +23 -0
- data/lib/theatre/invocation.rb +121 -0
- data/lib/theatre/namespace_manager.rb +153 -0
- data/lib/theatre/version.rb +2 -0
- data/lib/theatre.rb +151 -0
- metadata +60 -147
- data/Manifest.txt +0 -151
- data/README.txt +0 -5
- data/ahn_generators/component/USAGE +0 -5
- data/ahn_generators/component/component_generator.rb +0 -57
- data/ahn_generators/component/templates/configuration.rb +0 -0
- data/ahn_generators/component/templates/lib/lib.rb.erb +0 -3
- data/ahn_generators/component/templates/test/test.rb.erb +0 -12
- data/ahn_generators/component/templates/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
- data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +0 -31
- data/lib/adhearsion/core_extensions/array.rb +0 -0
- data/lib/adhearsion/core_extensions/guid.rb +0 -5
- data/lib/adhearsion/core_extensions/hash.rb +0 -0
- data/lib/adhearsion/core_extensions/numeric.rb +0 -4
- data/lib/adhearsion/core_extensions/proc.rb +0 -0
- data/lib/adhearsion/core_extensions/pseudo_uuid.rb +0 -11
- data/lib/adhearsion/core_extensions/publishable.rb +0 -73
- data/lib/adhearsion/core_extensions/string.rb +0 -26
- data/lib/adhearsion/core_extensions/thread.rb +0 -13
- data/lib/adhearsion/core_extensions/time.rb +0 -0
- data/lib/adhearsion/distributed/gateways/dbus_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/osa_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/rest_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/soap_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +0 -9
- data/lib/adhearsion/distributed/peer_finder.rb +0 -0
- data/lib/adhearsion/distributed/remote_cli.rb +0 -0
- data/lib/adhearsion/hooks.rb +0 -57
- data/lib/adhearsion/initializer/paths.rb +0 -55
- data/lib/adhearsion/voip/asterisk/ami/actions.rb +0 -238
- data/lib/adhearsion/voip/asterisk/ami/machine.rb +0 -871
- data/lib/adhearsion/voip/asterisk/ami/machine.rl +0 -109
- data/lib/adhearsion/voip/asterisk/ami/parser.rb +0 -262
- data/lib/adhearsion/voip/asterisk/ami.rb +0 -147
- data/spec/fixtures/dialplan.rb +0 -3
- data/spec/initializer/test_configuration.rb +0 -267
- data/spec/initializer/test_loading.rb +0 -162
- data/spec/initializer/test_paths.rb +0 -43
- data/spec/sample.rb +0 -9
- data/spec/silence.rb +0 -10
- data/spec/test_ahn_command.rb +0 -149
- data/spec/test_code_quality.rb +0 -87
- data/spec/test_component_manager.rb +0 -97
- data/spec/test_constants.rb +0 -8
- data/spec/test_drb.rb +0 -104
- data/spec/test_events.rb +0 -136
- data/spec/test_helper.rb +0 -106
- data/spec/test_hooks.rb +0 -15
- data/spec/test_host_definitions.rb +0 -79
- data/spec/test_initialization.rb +0 -124
- data/spec/test_logging.rb +0 -80
- data/spec/test_relationship_properties.rb +0 -54
- data/spec/voip/asterisk/ami_response_definitions.rb +0 -23
- data/spec/voip/asterisk/config_file_generators/test_agents.rb +0 -253
- data/spec/voip/asterisk/config_file_generators/test_queues.rb +0 -325
- data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +0 -306
- data/spec/voip/asterisk/menu_command/test_calculated_match.rb +0 -111
- data/spec/voip/asterisk/menu_command/test_matchers.rb +0 -98
- data/spec/voip/asterisk/mock_ami_server.rb +0 -176
- data/spec/voip/asterisk/test_agi_server.rb +0 -453
- data/spec/voip/asterisk/test_ami.rb +0 -227
- data/spec/voip/asterisk/test_commands.rb +0 -2006
- data/spec/voip/asterisk/test_config_manager.rb +0 -129
- data/spec/voip/dsl/dispatcher_spec_helper.rb +0 -45
- data/spec/voip/dsl/test_dialing_dsl.rb +0 -268
- data/spec/voip/dsl/test_dispatcher.rb +0 -82
- data/spec/voip/dsl/test_parser.rb +0 -87
- data/spec/voip/freeswitch/test_basic_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_inbound_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_oes_server.rb +0 -9
- data/spec/voip/test_call_routing.rb +0 -127
- data/spec/voip/test_dialplan_manager.rb +0 -442
- data/spec/voip/test_numerical_string.rb +0 -48
- data/spec/voip/test_phone_number.rb +0 -36
- data/test/test_ahn_generator.rb +0 -59
- data/test/test_component_generator.rb +0 -52
- data/test/test_generator_helper.rb +0 -20
@@ -0,0 +1,96 @@
|
|
1
|
+
##
|
2
|
+
# Implementation of a Thread-safe Hash. Works by delegating methods to a Hash behind-the-scenes after obtaining an exclusive # lock. Use exactly as you would a normal Hash.
|
3
|
+
#
|
4
|
+
class SynchronizedHash
|
5
|
+
|
6
|
+
def self.atomically_delegate(method_name)
|
7
|
+
class_eval(<<-RUBY, __FILE__, __LINE__)
|
8
|
+
def #{method_name}(*args, &block)
|
9
|
+
@lock.synchronize do
|
10
|
+
@delegate.send(#{method_name.inspect}, *args, &block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
RUBY
|
14
|
+
end
|
15
|
+
|
16
|
+
# Hash-related methods
|
17
|
+
|
18
|
+
atomically_delegate :[]
|
19
|
+
atomically_delegate :[]=
|
20
|
+
atomically_delegate :all?
|
21
|
+
atomically_delegate :any?
|
22
|
+
atomically_delegate :clear
|
23
|
+
atomically_delegate :collect
|
24
|
+
atomically_delegate :default
|
25
|
+
atomically_delegate :default=
|
26
|
+
atomically_delegate :delete
|
27
|
+
atomically_delegate :delete_if
|
28
|
+
atomically_delegate :detect
|
29
|
+
atomically_delegate :each
|
30
|
+
atomically_delegate :each_key
|
31
|
+
atomically_delegate :each_pair
|
32
|
+
atomically_delegate :each_value
|
33
|
+
atomically_delegate :each_with_index
|
34
|
+
atomically_delegate :empty?
|
35
|
+
atomically_delegate :entries
|
36
|
+
atomically_delegate :fetch
|
37
|
+
atomically_delegate :find
|
38
|
+
atomically_delegate :find_all
|
39
|
+
atomically_delegate :grep
|
40
|
+
atomically_delegate :has_key?
|
41
|
+
atomically_delegate :has_value?
|
42
|
+
atomically_delegate :include?
|
43
|
+
atomically_delegate :index
|
44
|
+
atomically_delegate :indexes
|
45
|
+
atomically_delegate :indices
|
46
|
+
atomically_delegate :inject
|
47
|
+
atomically_delegate :invert
|
48
|
+
atomically_delegate :key?
|
49
|
+
atomically_delegate :keys
|
50
|
+
atomically_delegate :length
|
51
|
+
atomically_delegate :map
|
52
|
+
atomically_delegate :max
|
53
|
+
atomically_delegate :member?
|
54
|
+
atomically_delegate :merge
|
55
|
+
atomically_delegate :merge!
|
56
|
+
atomically_delegate :min
|
57
|
+
atomically_delegate :partition
|
58
|
+
atomically_delegate :rehash
|
59
|
+
atomically_delegate :reject
|
60
|
+
atomically_delegate :reject!
|
61
|
+
atomically_delegate :replace
|
62
|
+
atomically_delegate :select
|
63
|
+
atomically_delegate :shift
|
64
|
+
atomically_delegate :size
|
65
|
+
atomically_delegate :sort
|
66
|
+
atomically_delegate :sort_by
|
67
|
+
atomically_delegate :store
|
68
|
+
atomically_delegate :to_hash
|
69
|
+
atomically_delegate :update
|
70
|
+
atomically_delegate :value?
|
71
|
+
atomically_delegate :values
|
72
|
+
atomically_delegate :values_at
|
73
|
+
atomically_delegate :zip
|
74
|
+
|
75
|
+
# Object-related methods
|
76
|
+
|
77
|
+
atomically_delegate :inspect
|
78
|
+
atomically_delegate :to_s
|
79
|
+
atomically_delegate :marshal_dump
|
80
|
+
|
81
|
+
def initialize(*args, &block)
|
82
|
+
@delegate = Hash.new(*args, &block)
|
83
|
+
@lock = Mutex.new
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# If you need to do many operations atomically (a la transaction), you can call this method and access the yielded Hash
|
88
|
+
# which can be safely modified for the duration of your block.
|
89
|
+
#
|
90
|
+
# @yield [Hash] the Hash on which you can safely operate during your block.
|
91
|
+
#
|
92
|
+
def with_lock(&block)
|
93
|
+
@lock.synchronize { yield @delegate }
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
File without changes
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
module Adhearsion
|
4
|
+
|
5
|
+
##
|
6
|
+
# This class isn't yet tied into Adhearsion.
|
7
|
+
#
|
4
8
|
class HostDefinition
|
5
9
|
|
6
10
|
SUPPORTED_KEYS = [:host, :username, :password, :key, :name]
|
@@ -41,7 +45,7 @@ module Adhearsion
|
|
41
45
|
attr_reader :name, :host, :username, :password, :key
|
42
46
|
def initialize(hash)
|
43
47
|
@host, @username, @password, @key, @name = hash.values_at(*SUPPORTED_KEYS)
|
44
|
-
@name ||=
|
48
|
+
@name ||= new_guid
|
45
49
|
|
46
50
|
unrecognized_keys = hash.keys - SUPPORTED_KEYS
|
47
51
|
raise HostDefinitionException, "Unrecognized key(s): #{unrecognized_keys.map(&:inspect).to_sentence}" if unrecognized_keys.any?
|
@@ -8,9 +8,9 @@ module Adhearsion
|
|
8
8
|
class << self
|
9
9
|
|
10
10
|
def start
|
11
|
-
self.config =
|
11
|
+
self.config = AHN_CONFIG.asterisk
|
12
12
|
self.agi_server = initialize_agi
|
13
|
-
self.ami_client = initialize_ami if config.ami_enabled?
|
13
|
+
self.ami_client = VoIP::Asterisk.manager_interface = initialize_ami if config.ami_enabled?
|
14
14
|
join_server_thread_after_initialized
|
15
15
|
end
|
16
16
|
|
@@ -22,16 +22,25 @@ module Adhearsion
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def initialize_agi
|
25
|
-
|
26
|
-
|
25
|
+
VoIP::Asterisk::AGI::Server.new :host => config.listening_host,
|
26
|
+
:port => config.listening_port
|
27
27
|
end
|
28
28
|
|
29
29
|
def initialize_ami
|
30
30
|
options = ami_options
|
31
31
|
start_ami_after_initialized
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
returning VoIP::Asterisk::Manager::ManagerInterface.new(options) do
|
33
|
+
class << VoIP::Asterisk
|
34
|
+
if respond_to?(:manager_interface)
|
35
|
+
ahn_log.warn "Asterisk.manager_interface already initialized?"
|
36
|
+
else
|
37
|
+
def manager_interface
|
38
|
+
# ahn_log.ami.warn "Warning! This Asterisk.manager_interface() notation is for Adhearsion version 0.8.0 only. Subsequent versions of Adhearsion will use a feature called SuperManager. Migrating to use SuperManager will be very simple. See http://docs.adhearsion.com/AMI for more information."
|
39
|
+
Adhearsion::Initializer::AsteriskInitializer.ami_client
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
35
44
|
end
|
36
45
|
|
37
46
|
def ami_options
|
@@ -42,13 +51,26 @@ module Adhearsion
|
|
42
51
|
end
|
43
52
|
|
44
53
|
def join_server_thread_after_initialized
|
45
|
-
|
46
|
-
|
54
|
+
Events.register_callback(:after_initialized) do
|
55
|
+
begin
|
56
|
+
agi_server.start
|
57
|
+
rescue => e
|
58
|
+
ahn_log.fatal "Failed to start AGI server! #{e.inspect}"
|
59
|
+
abort
|
60
|
+
end
|
61
|
+
end
|
62
|
+
IMPORTANT_THREADS << agi_server
|
47
63
|
end
|
48
64
|
|
49
65
|
def start_ami_after_initialized
|
50
|
-
|
51
|
-
|
66
|
+
Events.register_callback(:after_initialized) do
|
67
|
+
begin
|
68
|
+
self.ami_client.connect!
|
69
|
+
rescue Errno::ECONNREFUSED
|
70
|
+
ahn_log.ami.error "Connection refused when connecting to AMI! Please check your configuration."
|
71
|
+
rescue => e
|
72
|
+
ahn_log.ami.error "Error connecting to AMI! #{e.inspect}"
|
73
|
+
end
|
52
74
|
end
|
53
75
|
end
|
54
76
|
|
@@ -24,8 +24,11 @@ module Adhearsion
|
|
24
24
|
|
25
25
|
class << self
|
26
26
|
def configure(&block)
|
27
|
-
|
28
|
-
|
27
|
+
if Adhearsion.const_defined?(:AHN_CONFIG)
|
28
|
+
yield AHN_CONFIG if block_given?
|
29
|
+
else
|
30
|
+
Adhearsion.const_set(:AHN_CONFIG, new(&block))
|
31
|
+
end
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
@@ -33,10 +36,6 @@ module Adhearsion
|
|
33
36
|
attr_accessor :end_call_on_hangup
|
34
37
|
attr_accessor :end_call_on_error
|
35
38
|
|
36
|
-
def logging(options)
|
37
|
-
Adhearsion::Logging.logging_level = options[:level]
|
38
|
-
end
|
39
|
-
|
40
39
|
def initialize
|
41
40
|
@automatically_answer_incoming_calls = true
|
42
41
|
@end_call_on_hangup = true
|
@@ -44,6 +43,59 @@ module Adhearsion
|
|
44
43
|
yield self if block_given?
|
45
44
|
end
|
46
45
|
|
46
|
+
def ahnrc
|
47
|
+
@ahnrc
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Load the contents of an .ahnrc file into this Configuration.
|
52
|
+
#
|
53
|
+
# @param [String, Hash] ahnrc String of YAML .ahnrc data or a Hash of the pre-loaded YAML data structure
|
54
|
+
#
|
55
|
+
def ahnrc=(new_ahnrc)
|
56
|
+
case new_ahnrc
|
57
|
+
when Hash
|
58
|
+
@raw_ahnrc = new_ahnrc.to_yaml.freeze
|
59
|
+
@ahnrc = new_ahnrc.clone.freeze
|
60
|
+
when String
|
61
|
+
@raw_ahnrc = new_ahnrc.clone.freeze
|
62
|
+
@ahnrc = YAML.load(new_ahnrc).freeze
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def logging(options)
|
67
|
+
Adhearsion::Logging.logging_level = options[:level]
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Adhearsion's .ahnrc file is used to define paths to certain parts of the framework. For example, the name dialplan.rb
|
72
|
+
# is actually specified in .ahnrc. This file can actually be just a filename, a filename with a glob (.e.g "*.rb"), an
|
73
|
+
# Array of filenames or even an Array of globs.
|
74
|
+
#
|
75
|
+
# @param [String,Array] String segments which convey the nesting of Hash keys through .ahnrc
|
76
|
+
# @raise [RuntimeError] If ahnrc has not been set yet with #ahnrc=()
|
77
|
+
# @raise [NameError] If the path through the ahnrc is invalid
|
78
|
+
#
|
79
|
+
def files_from_setting(*path_through_config)
|
80
|
+
raise RuntimeError, "No ahnrc has been set yet!" unless @ahnrc
|
81
|
+
queried_nested_setting = path_through_config.flatten.inject(@ahnrc) do |hash,key_name|
|
82
|
+
if hash.kind_of?(Hash) && hash.has_key?(key_name)
|
83
|
+
hash[key_name]
|
84
|
+
else
|
85
|
+
raise NameError, "Paths #{path_through_config.inspect} not found in .ahnrc!"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
raise NameError, "Paths #{path_through_config.inspect} not found in .ahnrc!" unless queried_nested_setting
|
89
|
+
queried_nested_setting = Array queried_nested_setting
|
90
|
+
queried_nested_setting.map { |filename| files_from_glob(filename) }.flatten.uniq
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def files_from_glob(glob)
|
96
|
+
Dir.glob "#{AHN_ROOT}/#{glob}"
|
97
|
+
end
|
98
|
+
|
47
99
|
class AbstractConfiguration
|
48
100
|
extend ConfigurationEntryPoint
|
49
101
|
|
@@ -23,7 +23,7 @@ module Adhearsion
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def create_call_hook_for_connection_cleanup
|
26
|
-
|
26
|
+
Events.register_callback([:asterisk, :before_call]) do
|
27
27
|
ActiveRecord::Base.verify_active_connections!
|
28
28
|
end
|
29
29
|
end
|
@@ -33,7 +33,7 @@ module Adhearsion
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def require_models
|
36
|
-
|
36
|
+
AHN_CONFIG.files_from_setting("paths", "models").each do |model|
|
37
37
|
load model
|
38
38
|
end
|
39
39
|
end
|
@@ -46,47 +46,4 @@ module Adhearsion
|
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|
49
|
-
end
|
50
|
-
|
51
|
-
=begin
|
52
|
-
db_config = Adhearsion::Configuration.core.database
|
53
|
-
if db_config
|
54
|
-
unless Adhearsion::Paths.manager_for? "models"
|
55
|
-
raise "No paths specified for the database 'models' in .ahnrc! Aborting."
|
56
|
-
end
|
57
|
-
require 'active_record'
|
58
|
-
|
59
|
-
ActiveRecord::Base.verification_timeout = 14400
|
60
|
-
ActiveRecord::Base.logger = Logger.new("log/database.log")
|
61
|
-
ActiveRecord::Base.establish_connection db_config
|
62
|
-
|
63
|
-
all_models.each { |model| require model }
|
64
|
-
|
65
|
-
# Below is a monkey patch for keeping ActiveRecord connections alive.
|
66
|
-
# http://www.sparecycles.org/2007/7/2/saying-goodbye-to-lost-connections-in-rails
|
67
|
-
|
68
|
-
module ActiveRecord
|
69
|
-
module ConnectionAdapters
|
70
|
-
class MysqlAdapter
|
71
|
-
def execute(sql, name = nil) #:nodoc:
|
72
|
-
reconnect_lost_connections = true
|
73
|
-
begin
|
74
|
-
log(sql, name) { @connection.query(sql) }
|
75
|
-
rescue ActiveRecord::StatementInvalid => exception
|
76
|
-
if reconnect_lost_connections and exception.message =~ /(Lost connection to MySQL server during query|MySQL server has gone away)/
|
77
|
-
reconnect_lost_connections = false
|
78
|
-
reconnect!
|
79
|
-
retry
|
80
|
-
elsif exception.message.split(":").first =~ /Packets out of order/
|
81
|
-
raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings."
|
82
|
-
else
|
83
|
-
raise
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
=end
|
49
|
+
end
|
@@ -8,17 +8,23 @@ module Adhearsion
|
|
8
8
|
class DrbInitializer
|
9
9
|
|
10
10
|
class << self
|
11
|
-
|
11
|
+
|
12
12
|
def start
|
13
13
|
config = Adhearsion::AHN_CONFIG.drb
|
14
14
|
DRb.install_acl ACL.new(config.acl) if config.acl
|
15
|
-
|
15
|
+
|
16
|
+
drb_door = Object.new
|
17
|
+
Components.component_manager.extend_object_with(drb_door, :rpc)
|
18
|
+
|
19
|
+
DRb.start_service "druby://#{config.host}:#{config.port}", drb_door
|
20
|
+
|
16
21
|
ahn_log "Starting DRb on #{config.host}:#{config.port}"
|
17
22
|
end
|
18
|
-
|
23
|
+
|
19
24
|
def stop
|
20
25
|
DRb.stop_service
|
21
26
|
end
|
27
|
+
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|
@@ -15,8 +15,8 @@ if oes_enabled
|
|
15
15
|
|
16
16
|
server = Adhearsion::VoIP::FreeSwitch::OesServer.new port, host
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
Events.register_callback(:after_initialized) { server.start }
|
19
|
+
Events.register_callback(:shutdown) { server.stop }
|
20
|
+
IMPORTANT_THREADS << server
|
21
21
|
|
22
22
|
end
|
@@ -18,7 +18,7 @@ module Adhearsion
|
|
18
18
|
load_rails
|
19
19
|
if defined? ActiveRecord
|
20
20
|
ActiveRecord::Base.allow_concurrency = true
|
21
|
-
|
21
|
+
Events.register_callback([:asterisk, :before_call]) do
|
22
22
|
ActiveRecord::Base.verify_active_connections!
|
23
23
|
end
|
24
24
|
end
|