adhearsion 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +11 -2
- data/EVENTS +1 -1
- data/Rakefile +4 -4
- data/adhearsion.gemspec +8 -4
- data/app_generators/ahn/USAGE +3 -3
- data/app_generators/ahn/ahn_generator.rb +11 -11
- data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +3 -3
- data/app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb +6 -6
- data/app_generators/ahn/templates/components/disabled/restful_rpc/restful_rpc.rb +16 -16
- data/app_generators/ahn/templates/components/disabled/restful_rpc/spec/restful_rpc_spec.rb +42 -42
- data/app_generators/ahn/templates/components/disabled/sandbox/sandbox.rb +11 -11
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +1 -1
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +6 -6
- data/app_generators/ahn/templates/components/simon_game/simon_game.rb +4 -4
- data/app_generators/ahn/templates/config/startup.rb +31 -16
- data/bin/ahn +3 -3
- data/bin/ahnctl +8 -8
- data/bin/jahn +3 -3
- data/examples/asterisk_manager_interface/standalone.rb +2 -2
- data/lib/adhearsion.rb +4 -2
- data/lib/adhearsion/cli.rb +31 -31
- data/lib/adhearsion/component_manager.rb +39 -39
- data/lib/adhearsion/component_manager/component_tester.rb +14 -14
- data/lib/adhearsion/component_manager/spec_framework.rb +1 -1
- data/lib/adhearsion/events_support.rb +12 -12
- data/lib/adhearsion/foundation/blank_slate.rb +1 -1
- data/lib/adhearsion/foundation/custom_daemonizer.rb +2 -2
- data/lib/adhearsion/foundation/event_socket.rb +26 -26
- data/lib/adhearsion/foundation/future_resource.rb +6 -6
- data/lib/adhearsion/foundation/metaprogramming.rb +2 -2
- data/lib/adhearsion/foundation/numeric.rb +3 -3
- data/lib/adhearsion/foundation/relationship_properties.rb +7 -7
- data/lib/adhearsion/foundation/string.rb +8 -8
- data/lib/adhearsion/foundation/synchronized_hash.rb +8 -8
- data/lib/adhearsion/host_definitions.rb +16 -16
- data/lib/adhearsion/initializer.rb +74 -65
- data/lib/adhearsion/initializer/asterisk.rb +15 -9
- data/lib/adhearsion/initializer/configuration.rb +54 -39
- data/lib/adhearsion/initializer/database.rb +4 -4
- data/lib/adhearsion/initializer/drb.rb +6 -6
- data/lib/adhearsion/initializer/freeswitch.rb +1 -1
- data/lib/adhearsion/initializer/ldap.rb +51 -0
- data/lib/adhearsion/initializer/rails.rb +8 -8
- data/lib/adhearsion/logging.rb +16 -16
- data/lib/adhearsion/tasks/deprecations.rb +12 -12
- data/lib/adhearsion/tasks/generating.rb +2 -2
- data/lib/adhearsion/tasks/testing.rb +7 -7
- data/lib/adhearsion/version.rb +1 -1
- data/lib/adhearsion/voip/asterisk/agi_server.rb +44 -14
- data/lib/adhearsion/voip/asterisk/commands.rb +281 -237
- data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +8 -8
- data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +14 -14
- data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +16 -16
- data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +39 -39
- data/lib/adhearsion/voip/asterisk/config_manager.rb +13 -13
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +91 -87
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +739 -739
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +60 -60
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +16 -16
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +1 -1
- data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +13 -13
- data/lib/adhearsion/voip/asterisk/super_manager.rb +3 -3
- data/lib/adhearsion/voip/call.rb +101 -64
- data/lib/adhearsion/voip/call_routing.rb +9 -9
- data/lib/adhearsion/voip/constants.rb +7 -7
- data/lib/adhearsion/voip/conveniences.rb +1 -1
- data/lib/adhearsion/voip/dial_plan.rb +42 -40
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +27 -27
- data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +1 -1
- data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +6 -6
- data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +17 -17
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +7 -7
- data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +2 -2
- data/lib/adhearsion/voip/dsl/numerical_string.rb +3 -3
- data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +7 -7
- data/lib/adhearsion/voip/freeswitch/event_handler.rb +1 -1
- data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +20 -20
- data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +5 -5
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +33 -33
- data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +1 -1
- data/lib/adhearsion/voip/menu_state_machine/matchers.rb +2 -2
- data/lib/adhearsion/voip/menu_state_machine/menu_class.rb +9 -9
- data/lib/theatre.rb +18 -18
- data/lib/theatre/callback_definition_loader.rb +17 -17
- data/lib/theatre/guid.rb +6 -6
- data/lib/theatre/invocation.rb +19 -19
- data/lib/theatre/namespace_manager.rb +28 -28
- metadata +55 -14
@@ -1,23 +1,23 @@
|
|
1
1
|
require "thread"
|
2
2
|
|
3
3
|
class FutureResource
|
4
|
-
|
4
|
+
|
5
5
|
def initialize
|
6
6
|
@resource_lock = Monitor.new
|
7
7
|
@resource_value_blocker = @resource_lock.new_cond
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def set_yet?
|
11
11
|
@resource_lock.synchronize { defined? @resource }
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def resource
|
15
15
|
@resource_lock.synchronize do
|
16
16
|
@resource_value_blocker.wait unless defined? @resource
|
17
17
|
@resource
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def resource=(resource)
|
22
22
|
@resource_lock.synchronize do
|
23
23
|
raise ResourceAlreadySetException if defined? @resource
|
@@ -26,11 +26,11 @@ class FutureResource
|
|
26
26
|
@resource_value_blocker = nil # Don't really need it anymore.
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
class ResourceAlreadySetException < Exception
|
31
31
|
def initialize
|
32
32
|
super "Cannot set this resource twice!"
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
class Numeric
|
2
|
-
|
2
|
+
|
3
3
|
def digit()
|
4
4
|
ahn_log.deprecation 'Please do not use Fixnum#digit() and Fixnum#digits() in the future! These will be deprecated soon'
|
5
5
|
self
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def digits()
|
9
9
|
ahn_log.deprecation 'Please do not use Fixnum#digit() and Fixnum#digits() in the future! These will be deprecated soon'
|
10
10
|
self
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
class Module
|
2
|
-
|
2
|
+
|
3
3
|
##
|
4
|
-
# In OOP, relationships between classes should be treated as *properties* of those classes. Often, in a complex OO
|
4
|
+
# In OOP, relationships between classes should be treated as *properties* of those classes. Often, in a complex OO
|
5
5
|
# architecture, you'll end up with many relationships that intermingle in monolithic ways, blunting the effectiveness of
|
6
6
|
# subclassing.
|
7
7
|
#
|
8
8
|
# For example, say you have an Automobile class which, in its constructor, instantiates a new Battery class and performs
|
9
9
|
# some operations on it such as calling an install() method. Let's also assume the Automobile class exposes a repair()
|
10
|
-
# method which uses a class-level method of Battery to diagnose your own instance of Battery. If the result of the
|
10
|
+
# method which uses a class-level method of Battery to diagnose your own instance of Battery. If the result of the
|
11
11
|
# diagnosis shows that the Battery is bad, the Automobile will instantiate a new Battery object and replace the old battery
|
12
12
|
# with the new one.
|
13
13
|
#
|
14
14
|
# Now, what if you wish to create a new Automobile derived from existing technology: a HybridAutomobile subclass. For this
|
15
15
|
# particular HybridAutomobile class, let's simply say the only difference between it and its parent is which kind of
|
16
|
-
# Battery it uses -- it requires its own special subclass of Battery. With Automobile's current implementation, its
|
17
|
-
# references to which Battery it instantiates and uses are embedded in the immutable method defintions. This
|
16
|
+
# Battery it uses -- it requires its own special subclass of Battery. With Automobile's current implementation, its
|
17
|
+
# references to which Battery it instantiates and uses are embedded in the immutable method defintions. This
|
18
18
|
# HybridAutomobile needs to override which Battery its superclass' methods use and nothing else.
|
19
19
|
#
|
20
20
|
# For this reason, the Battery class which Automobile uses is semantically a property which others may want to override.
|
@@ -35,8 +35,8 @@ class Module
|
|
35
35
|
#
|
36
36
|
def relationships(relationship_mapping)
|
37
37
|
relationship_mapping.each_pair do |class_name, class_object|
|
38
|
-
define_method(class_name) { class_object }
|
38
|
+
define_method(class_name) { class_object }
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
class String
|
2
|
-
|
2
|
+
|
3
3
|
def unindent
|
4
4
|
gsub(/^\s*/,'')
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def unindent!
|
8
8
|
gsub!(/^\s*/,'')
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def self.random_char
|
12
12
|
case random_digit = rand(62)
|
13
|
-
when 0...10
|
14
|
-
when 10...36
|
15
|
-
when 36...62
|
13
|
+
when 0...10 then random_digit.to_s
|
14
|
+
when 10...36 then (random_digit + 55).chr
|
15
|
+
when 36...62 then (random_digit + 61).chr
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.random(length_of_string=8)
|
20
20
|
Array.new(length_of_string) { random_char }.join
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def nameify() downcase.gsub(/[^\w]/, '') end
|
24
24
|
def nameify!() replace nameify end
|
25
|
-
|
25
|
+
|
26
26
|
end
|
@@ -2,7 +2,7 @@
|
|
2
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
3
|
#
|
4
4
|
class SynchronizedHash
|
5
|
-
|
5
|
+
|
6
6
|
def self.atomically_delegate(method_name)
|
7
7
|
class_eval(<<-RUBY, __FILE__, __LINE__)
|
8
8
|
def #{method_name}(*args, &block)
|
@@ -12,9 +12,9 @@ class SynchronizedHash
|
|
12
12
|
end
|
13
13
|
RUBY
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# Hash-related methods
|
17
|
-
|
17
|
+
|
18
18
|
atomically_delegate :[]
|
19
19
|
atomically_delegate :[]=
|
20
20
|
atomically_delegate :all?
|
@@ -71,18 +71,18 @@ class SynchronizedHash
|
|
71
71
|
atomically_delegate :values
|
72
72
|
atomically_delegate :values_at
|
73
73
|
atomically_delegate :zip
|
74
|
-
|
74
|
+
|
75
75
|
# Object-related methods
|
76
|
-
|
76
|
+
|
77
77
|
atomically_delegate :inspect
|
78
78
|
atomically_delegate :to_s
|
79
79
|
atomically_delegate :marshal_dump
|
80
|
-
|
80
|
+
|
81
81
|
def initialize(*args, &block)
|
82
82
|
@delegate = Hash.new(*args, &block)
|
83
83
|
@lock = Mutex.new
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
##
|
87
87
|
# If you need to do many operations atomically (a la transaction), you can call this method and access the yielded Hash
|
88
88
|
# which can be safely modified for the duration of your block.
|
@@ -92,5 +92,5 @@ class SynchronizedHash
|
|
92
92
|
def with_lock(&block)
|
93
93
|
@lock.synchronize { yield @delegate }
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
module Adhearsion
|
4
|
-
|
4
|
+
|
5
5
|
##
|
6
6
|
# This class isn't yet tied into Adhearsion.
|
7
7
|
#
|
8
8
|
class HostDefinition
|
9
|
-
|
9
|
+
|
10
10
|
SUPPORTED_KEYS = [:host, :username, :password, :key, :name]
|
11
|
-
|
11
|
+
|
12
12
|
cattr_reader :definitions
|
13
13
|
@@definitions ||= []
|
14
|
-
|
14
|
+
|
15
15
|
class << self
|
16
16
|
def import_from_data_structure(local_definitions)
|
17
17
|
case local_definitions
|
@@ -28,40 +28,40 @@ module Adhearsion
|
|
28
28
|
raise HostDefinitionException, "Unrecognized definition #{local_definitions}"
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def import_from_yaml(yaml_string)
|
33
33
|
import_from_data_structure YAML.load(yaml_string)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def import_from_yaml_file(file)
|
37
37
|
import_from_yaml YAML.load_file(file)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def clear_definitions!
|
41
41
|
definitions.clear
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
attr_reader :name, :host, :username, :password, :key
|
46
46
|
def initialize(hash)
|
47
47
|
@host, @username, @password, @key, @name = hash.values_at(*SUPPORTED_KEYS)
|
48
48
|
@name ||= new_guid
|
49
|
-
|
49
|
+
|
50
50
|
unrecognized_keys = hash.keys - SUPPORTED_KEYS
|
51
|
-
raise HostDefinitionException, "Unrecognized key(s): #{unrecognized_keys.map(&:inspect).to_sentence}" if unrecognized_keys.any?
|
51
|
+
raise HostDefinitionException, "Unrecognized key(s): #{unrecognized_keys.map(&:inspect).to_sentence}" if unrecognized_keys.any?
|
52
52
|
raise HostDefinitionException, "You must supply a password or key!" if username && !(password || key)
|
53
53
|
raise HostDefinitionException, "You must supply a username!" unless username
|
54
54
|
raise HostDefinitionException, 'You cannot supply both a password and key!' if password && key
|
55
55
|
raise HostDefinitionException, 'You must supply a host!' unless host
|
56
|
-
|
56
|
+
|
57
57
|
self.class.definitions << self
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
class HostDefinitionException < Exception
|
61
|
-
|
61
|
+
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
end
|
65
|
-
|
66
|
-
|
65
|
+
|
66
|
+
|
67
67
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Adhearsion
|
2
|
-
|
2
|
+
|
3
3
|
class << self
|
4
|
-
|
4
|
+
|
5
5
|
##
|
6
6
|
# Shuts down the framework.
|
7
7
|
#
|
@@ -9,25 +9,25 @@ module Adhearsion
|
|
9
9
|
ahn_log "Shutting down gracefully at #{Time.now}."
|
10
10
|
Events.stop!
|
11
11
|
exit
|
12
|
-
end
|
13
|
-
|
12
|
+
end
|
13
|
+
|
14
14
|
end
|
15
15
|
class PathString < String
|
16
|
-
|
16
|
+
|
17
17
|
class << self
|
18
|
-
|
18
|
+
|
19
19
|
##
|
20
20
|
# Will return a PathString for the application root folder to which the specified arbitrarily nested subfolder belongs.
|
21
21
|
# It works by traversing parent directories looking for the .ahnrc file. If no .ahnrc is found, nil is returned.
|
22
22
|
#
|
23
|
-
# @param [String] folder The path to the directory which should be a
|
23
|
+
# @param [String] folder The path to the directory which should be a
|
24
24
|
# @return [nil] if the subdirectory does not belong to a parent Adhearsion app directory
|
25
|
-
# @return [PathString] if a directory is found
|
25
|
+
# @return [PathString] if a directory is found
|
26
26
|
#
|
27
27
|
def from_application_subdirectory(folder)
|
28
28
|
folder = File.expand_path folder
|
29
29
|
ahn_rc = nil
|
30
|
-
|
30
|
+
|
31
31
|
until ahn_rc || folder == "/"
|
32
32
|
possible_ahn_rc = File.join(folder, ".ahnrc")
|
33
33
|
if File.exists?(possible_ahn_rc)
|
@@ -39,14 +39,14 @@ module Adhearsion
|
|
39
39
|
ahn_rc ? new(folder) : nil
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
attr_accessor :component_path, :dialplan_path, :log_path
|
44
|
-
|
44
|
+
|
45
45
|
def initialize(path)
|
46
46
|
super
|
47
47
|
defaults
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def defaults
|
51
51
|
@component_path = build_path_for "components"
|
52
52
|
@dialplan_path = dup
|
@@ -57,7 +57,7 @@ module Adhearsion
|
|
57
57
|
replace(value)
|
58
58
|
defaults
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def using_base_path(temporary_base_path, &block)
|
62
62
|
original_path = dup
|
63
63
|
self.base_path = temporary_base_path
|
@@ -65,21 +65,21 @@ module Adhearsion
|
|
65
65
|
ensure
|
66
66
|
self.base_path = original_path
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
private
|
70
70
|
def build_path_for(path)
|
71
71
|
File.join(to_s, path)
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
class Initializer
|
76
|
-
|
76
|
+
|
77
77
|
class << self
|
78
78
|
def get_rules_from(location)
|
79
79
|
location = File.join location, ".ahnrc" if File.directory? location
|
80
80
|
File.exists?(location) ? YAML.load_file(location) : nil
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
def ahn_root=(path)
|
84
84
|
if Object.constants.include?("AHN_ROOT")
|
85
85
|
Object.const_get(:AHN_ROOT).base_path = File.expand_path(path)
|
@@ -87,20 +87,20 @@ module Adhearsion
|
|
87
87
|
Object.const_set(:AHN_ROOT, PathString.new(File.expand_path(path)))
|
88
88
|
end
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
def start(*args, &block)
|
92
92
|
new(*args, &block).start
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
def start_from_init_file(file, ahn_app_path)
|
96
96
|
return if defined?(@@started) && @@started
|
97
97
|
start ahn_app_path, :loaded_init_files => file
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
attr_reader :path, :daemon, :pid_file, :log_file, :ahn_app_log_directory
|
103
|
-
|
103
|
+
|
104
104
|
# Creation of pid_files
|
105
105
|
#
|
106
106
|
# - You may want to have Adhearsion create a process identification
|
@@ -119,37 +119,38 @@ module Adhearsion
|
|
119
119
|
@pid_file = options[:pid_file].nil? ? ENV['PID_FILE'] : options[:pid_file]
|
120
120
|
@loaded_init_files = options[:loaded_init_files]
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
def start
|
124
124
|
self.class.ahn_root = path
|
125
|
-
|
125
|
+
|
126
126
|
resolve_pid_file_path
|
127
127
|
resolve_log_file_path
|
128
|
+
daemonize! if should_daemonize?
|
128
129
|
switch_to_root_directory
|
129
130
|
catch_termination_signal
|
131
|
+
create_pid_file if pid_file
|
130
132
|
bootstrap_rc
|
131
133
|
initialize_log_file
|
132
134
|
load_all_init_files
|
135
|
+
init_datasources
|
133
136
|
init_components_subsystem
|
134
137
|
init_modules
|
135
138
|
init_events_subsystem
|
136
139
|
load_components
|
137
140
|
init_events_file
|
138
|
-
|
139
|
-
create_pid_file if pid_file
|
140
|
-
|
141
|
+
|
141
142
|
ahn_log "Adhearsion initialized!"
|
142
|
-
|
143
|
+
|
143
144
|
trigger_after_initialized_hooks
|
144
145
|
join_important_threads
|
145
|
-
|
146
|
+
|
146
147
|
self
|
147
148
|
end
|
148
|
-
|
149
|
+
|
149
150
|
def default_pid_path
|
150
151
|
File.join AHN_ROOT, 'adhearsion.pid'
|
151
152
|
end
|
152
|
-
|
153
|
+
|
153
154
|
def resolve_pid_file_path
|
154
155
|
@pid_file = if pid_file.equal?(true) then default_pid_path
|
155
156
|
elsif pid_file then pid_file
|
@@ -158,35 +159,35 @@ module Adhearsion
|
|
158
159
|
else @pid_file = @daemon ? default_pid_path : nil
|
159
160
|
end
|
160
161
|
end
|
161
|
-
|
162
|
-
def resolve_log_file_path
|
162
|
+
|
163
|
+
def resolve_log_file_path
|
163
164
|
@ahn_app_log_directory = AHN_ROOT + '/log'
|
164
165
|
@log_file = File.expand_path(ahn_app_log_directory + "/adhearsion.log")
|
165
166
|
end
|
166
|
-
|
167
|
+
|
167
168
|
def switch_to_root_directory
|
168
169
|
Dir.chdir AHN_ROOT
|
169
170
|
end
|
170
|
-
|
171
|
+
|
171
172
|
def catch_termination_signal
|
172
173
|
%w'INT TERM'.each do |process_signal|
|
173
174
|
trap process_signal do
|
174
175
|
ahn_log "Shutting down gracefully at #{Time.now}."
|
175
|
-
Events.
|
176
|
+
Events.trigger_immediately :shutdown
|
176
177
|
exit
|
177
178
|
end
|
178
179
|
end
|
179
180
|
end
|
180
|
-
|
181
|
+
|
181
182
|
##
|
182
183
|
# This step in the initialization process loads the .ahnrc in the given app folder. With the information in .ahnrc, we
|
183
184
|
# can continue the initialization knowing where certain files are specifically.
|
184
185
|
#
|
185
186
|
def bootstrap_rc
|
186
187
|
rules = self.class.get_rules_from AHN_ROOT
|
187
|
-
|
188
|
+
|
188
189
|
AHN_CONFIG.ahnrc = rules
|
189
|
-
|
190
|
+
|
190
191
|
# DEPRECATION: Check if the old paths format is being used. If so, abort and notify.
|
191
192
|
if rules.has_key?("paths") && rules["paths"].kind_of?(Hash)
|
192
193
|
paths = rules["paths"].each_pair do |key,value|
|
@@ -195,7 +196,7 @@ module Adhearsion
|
|
195
196
|
puts
|
196
197
|
puts *caller
|
197
198
|
puts
|
198
|
-
|
199
|
+
|
199
200
|
abort <<-WARNING
|
200
201
|
Deprecation Warning
|
201
202
|
-------------------
|
@@ -203,8 +204,8 @@ The (hidden) .ahnrc file in this app is of an older format and needs to be fixed
|
|
203
204
|
|
204
205
|
There is a rake task to automatically fix it or you can do it manually. Note: it's
|
205
206
|
best if you do it manually so you can retain the YAML comments in your .ahnrc file.
|
206
|
-
|
207
|
-
The rake task is called "deprecations:fix_ahnrc_path_format".
|
207
|
+
|
208
|
+
The rake task is called "deprecations:fix_ahnrc_path_format".
|
208
209
|
|
209
210
|
To do it manually, find all entries in the "paths" section of your ".ahnrc" file
|
210
211
|
which look like the following:
|
@@ -232,7 +233,7 @@ Adhearsion will abort until you fix this. Sorry for the incovenience.
|
|
232
233
|
end
|
233
234
|
end
|
234
235
|
end
|
235
|
-
|
236
|
+
|
236
237
|
gems = rules['gems']
|
237
238
|
if gems.kind_of?(Hash) && gems.any? && respond_to?(:gem)
|
238
239
|
gems.each_pair do |gem_name,properties_hash|
|
@@ -247,32 +248,40 @@ Adhearsion will abort until you fix this. Sorry for the incovenience.
|
|
247
248
|
properties_hash["require"].each { |lib| require lib }
|
248
249
|
when String
|
249
250
|
require properties_hash["require"]
|
250
|
-
end
|
251
|
+
end
|
251
252
|
end
|
252
253
|
end
|
253
254
|
end
|
254
255
|
end
|
255
|
-
|
256
|
+
|
256
257
|
def load_all_init_files
|
257
258
|
init_files_from_rc = AHN_CONFIG.files_from_setting("paths", "init").map { |file| File.expand_path(file) }
|
258
259
|
already_loaded_init_files = Array(@loaded_init_files).map { |file| File.expand_path(file) }
|
259
260
|
(init_files_from_rc - already_loaded_init_files).each { |init| load init }
|
260
261
|
end
|
261
|
-
|
262
|
-
def
|
262
|
+
|
263
|
+
def init_datasources
|
263
264
|
require 'adhearsion/initializer/database.rb'
|
265
|
+
require 'adhearsion/initializer/ldap.rb'
|
266
|
+
|
267
|
+
DatabaseInitializer.start if AHN_CONFIG.database_enabled?
|
268
|
+
LdapInitializer.start if AHN_CONFIG.ldap_enabled?
|
269
|
+
end
|
270
|
+
|
271
|
+
def init_modules
|
272
|
+
|
264
273
|
require 'adhearsion/initializer/asterisk.rb'
|
265
274
|
require 'adhearsion/initializer/drb.rb'
|
266
275
|
require 'adhearsion/initializer/rails.rb'
|
267
276
|
# require 'adhearsion/initializer/freeswitch.rb'
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
RailsInitializer.start if AHN_CONFIG.rails_enabled?
|
277
|
+
|
278
|
+
AsteriskInitializer.start if AHN_CONFIG.asterisk_enabled?
|
279
|
+
DrbInitializer.start if AHN_CONFIG.drb_enabled?
|
280
|
+
RailsInitializer.start if AHN_CONFIG.rails_enabled?
|
273
281
|
# FreeswitchInitializer.start if AHN_CONFIG.freeswitch_enabled?
|
282
|
+
|
274
283
|
end
|
275
|
-
|
284
|
+
|
276
285
|
def init_events_subsystem
|
277
286
|
application_events_files = AHN_CONFIG.files_from_setting("paths", "events")
|
278
287
|
if application_events_files.any?
|
@@ -285,28 +294,28 @@ Adhearsion will abort until you fix this. Sorry for the incovenience.
|
|
285
294
|
ahn_log.events.warn 'No entries in the "events" section of .ahnrc. Skipping its initialization.'
|
286
295
|
end
|
287
296
|
end
|
288
|
-
|
297
|
+
|
289
298
|
def init_events_file
|
290
299
|
application_events_files = AHN_CONFIG.files_from_setting("paths", "events")
|
291
300
|
application_events_files.each do |file|
|
292
301
|
Events.framework_theatre.load_events_file file
|
293
302
|
end
|
294
303
|
end
|
295
|
-
|
304
|
+
|
296
305
|
def should_daemonize?
|
297
306
|
@daemon || ENV['DAEMON']
|
298
307
|
end
|
299
|
-
|
308
|
+
|
300
309
|
def daemonize!
|
301
310
|
ahn_log "Daemonizing now! Creating #{pid_file}."
|
302
311
|
extend Adhearsion::CustomDaemonizer
|
303
312
|
daemonize log_file
|
304
313
|
end
|
305
|
-
|
314
|
+
|
306
315
|
def initialize_log_file
|
307
316
|
Dir.mkdir(ahn_app_log_directory) unless File.directory? ahn_app_log_directory
|
308
317
|
file_logger = Log4r::FileOutputter.new("Main Adhearsion log file", :filename => log_file, :trunc => false)
|
309
|
-
|
318
|
+
|
310
319
|
if should_daemonize?
|
311
320
|
Logging::AdhearsionLogger.outputters = file_logger
|
312
321
|
else
|
@@ -314,19 +323,19 @@ Adhearsion will abort until you fix this. Sorry for the incovenience.
|
|
314
323
|
end
|
315
324
|
Logging::DefaultAdhearsionLogger.redefine_outputters
|
316
325
|
end
|
317
|
-
|
326
|
+
|
318
327
|
def create_pid_file(file = pid_file)
|
319
328
|
if file
|
320
329
|
File.open pid_file, 'w' do |file|
|
321
330
|
file.puts Process.pid
|
322
331
|
end
|
323
|
-
|
332
|
+
|
324
333
|
Events.register_callback :shutdown do
|
325
334
|
File.delete(pid_file) if File.exists?(pid_file)
|
326
335
|
end
|
327
336
|
end
|
328
337
|
end
|
329
|
-
|
338
|
+
|
330
339
|
def init_components_subsystem
|
331
340
|
@components_directory = File.expand_path "components"
|
332
341
|
if File.directory? @components_directory
|
@@ -338,17 +347,17 @@ Adhearsion will abort until you fix this. Sorry for the incovenience.
|
|
338
347
|
ahn_log.warn "No components directory found. Not initializing any components."
|
339
348
|
end
|
340
349
|
end
|
341
|
-
|
350
|
+
|
342
351
|
def load_components
|
343
352
|
if Components.component_manager
|
344
353
|
Components.component_manager.load_components
|
345
354
|
end
|
346
355
|
end
|
347
|
-
|
356
|
+
|
348
357
|
def trigger_after_initialized_hooks
|
349
358
|
Events.trigger_immediately :after_initialized
|
350
359
|
end
|
351
|
-
|
360
|
+
|
352
361
|
##
|
353
362
|
# This method will block Thread.main() until calling join() has returned for all Threads in IMPORTANT_THREADS.
|
354
363
|
# Note: IMPORTANT_THREADS won't always contain Thread instances. It simply requires the objects respond to join().
|
@@ -367,7 +376,7 @@ Adhearsion will abort until you fix this. Sorry for the incovenience.
|
|
367
376
|
end
|
368
377
|
end
|
369
378
|
end
|
370
|
-
|
379
|
+
|
371
380
|
class InitializationFailedError < Exception; end
|
372
381
|
end
|
373
382
|
end
|