adhearsion 1.2.6 → 2.0.0.alpha1

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.
Files changed (236) hide show
  1. data/.gitignore +17 -10
  2. data/CHANGELOG.md +273 -0
  3. data/Gemfile +1 -1
  4. data/Guardfile +17 -0
  5. data/README.markdown +61 -9
  6. data/Rakefile +16 -48
  7. data/adhearsion.gemspec +21 -7
  8. data/bin/ahn +3 -1
  9. data/cucumber.yml +4 -0
  10. data/features/app_generator.feature +42 -0
  11. data/features/cli.feature +108 -0
  12. data/features/step_definitions/app_generator_steps.rb +6 -0
  13. data/features/step_definitions/cli_steps.rb +74 -0
  14. data/features/support/aruba_helper.rb +22 -0
  15. data/features/support/env.rb +37 -0
  16. data/features/support/utils.rb +8 -0
  17. data/lib/adhearsion.rb +85 -41
  18. data/lib/adhearsion/call.rb +176 -0
  19. data/lib/adhearsion/call_controller.rb +134 -0
  20. data/lib/adhearsion/call_controller/dial.rb +70 -0
  21. data/lib/adhearsion/call_controller/input.rb +173 -0
  22. data/lib/adhearsion/call_controller/menu.rb +124 -0
  23. data/lib/adhearsion/call_controller/output.rb +267 -0
  24. data/lib/adhearsion/call_controller/record.rb +42 -0
  25. data/lib/adhearsion/call_controller/utility.rb +60 -0
  26. data/lib/adhearsion/calls.rb +81 -0
  27. data/lib/adhearsion/cli.rb +1 -3
  28. data/lib/adhearsion/cli_commands.rb +142 -0
  29. data/lib/adhearsion/configuration.rb +149 -0
  30. data/lib/adhearsion/console.rb +19 -8
  31. data/lib/adhearsion/dialplan_controller.rb +9 -0
  32. data/lib/adhearsion/events.rb +84 -0
  33. data/lib/adhearsion/foundation/all.rb +0 -7
  34. data/lib/adhearsion/foundation/custom_daemonizer.rb +4 -6
  35. data/lib/adhearsion/foundation/exception_handler.rb +9 -0
  36. data/lib/adhearsion/foundation/object.rb +26 -8
  37. data/lib/adhearsion/foundation/synchronized_hash.rb +3 -6
  38. data/lib/adhearsion/foundation/thread_safety.rb +17 -1
  39. data/lib/adhearsion/generators/app/app_generator.rb +4 -13
  40. data/lib/adhearsion/generators/app/templates/Gemfile +10 -5
  41. data/lib/adhearsion/generators/app/templates/Procfile +1 -0
  42. data/lib/adhearsion/generators/app/templates/README.md +28 -0
  43. data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +41 -0
  44. data/lib/adhearsion/generators/app/templates/{components/simon_game → lib}/simon_game.rb +6 -18
  45. data/lib/adhearsion/generators/app/templates/script/ahn +2 -2
  46. data/lib/adhearsion/initializer.rb +151 -293
  47. data/lib/adhearsion/initializer/logging.rb +33 -0
  48. data/lib/adhearsion/logging.rb +65 -69
  49. data/lib/adhearsion/menu_dsl.rb +15 -0
  50. data/lib/adhearsion/menu_dsl/calculated_match.rb +39 -0
  51. data/lib/adhearsion/menu_dsl/calculated_match_collection.rb +41 -0
  52. data/lib/adhearsion/menu_dsl/fixnum_match_calculator.rb +18 -0
  53. data/lib/adhearsion/menu_dsl/match_calculator.rb +36 -0
  54. data/lib/adhearsion/{voip/menu_state_machine/menu_class.rb → menu_dsl/menu.rb} +38 -40
  55. data/lib/adhearsion/menu_dsl/menu_builder.rb +69 -0
  56. data/lib/adhearsion/menu_dsl/range_match_calculator.rb +55 -0
  57. data/lib/adhearsion/menu_dsl/string_match_calculator.rb +21 -0
  58. data/lib/adhearsion/outbound_call.rb +64 -0
  59. data/lib/adhearsion/plugin.rb +319 -0
  60. data/lib/adhearsion/plugin/collection.rb +19 -0
  61. data/lib/adhearsion/plugin/initializer.rb +37 -0
  62. data/lib/adhearsion/plugin/methods_container.rb +6 -0
  63. data/lib/adhearsion/process.rb +94 -0
  64. data/lib/adhearsion/punchblock_plugin.rb +29 -0
  65. data/lib/adhearsion/punchblock_plugin/initializer.rb +137 -0
  66. data/lib/adhearsion/router.rb +30 -0
  67. data/lib/adhearsion/router/route.rb +42 -0
  68. data/lib/adhearsion/script_ahn_loader.rb +2 -2
  69. data/lib/adhearsion/tasks.rb +14 -9
  70. data/lib/adhearsion/tasks/configuration.rb +26 -0
  71. data/lib/adhearsion/tasks/plugins.rb +17 -0
  72. data/lib/adhearsion/version.rb +8 -14
  73. data/spec/adhearsion/call_controller/dial_spec.rb +138 -0
  74. data/spec/adhearsion/call_controller/input_spec.rb +278 -0
  75. data/spec/adhearsion/call_controller/menu_spec.rb +120 -0
  76. data/spec/adhearsion/call_controller/output_spec.rb +466 -0
  77. data/spec/adhearsion/call_controller/record_spec.rb +125 -0
  78. data/spec/adhearsion/call_controller_spec.rb +395 -0
  79. data/spec/adhearsion/call_spec.rb +438 -0
  80. data/spec/adhearsion/calls_spec.rb +47 -0
  81. data/spec/adhearsion/configuration_spec.rb +308 -0
  82. data/spec/adhearsion/dialplan_controller_spec.rb +26 -0
  83. data/spec/adhearsion/events_spec.rb +112 -0
  84. data/spec/adhearsion/initializer/logging_spec.rb +58 -0
  85. data/spec/adhearsion/initializer_spec.rb +209 -122
  86. data/spec/adhearsion/logging_spec.rb +58 -47
  87. data/spec/adhearsion/menu_dsl/calculated_match_collection_spec.rb +56 -0
  88. data/spec/adhearsion/menu_dsl/calculated_match_spec.rb +57 -0
  89. data/spec/adhearsion/menu_dsl/fixnum_match_calculator_spec.rb +33 -0
  90. data/spec/adhearsion/menu_dsl/match_calculator_spec.rb +13 -0
  91. data/spec/adhearsion/menu_dsl/menu_builder_spec.rb +118 -0
  92. data/spec/adhearsion/menu_dsl/menu_spec.rb +210 -0
  93. data/spec/adhearsion/menu_dsl/range_match_calculator_spec.rb +28 -0
  94. data/spec/adhearsion/menu_dsl/string_match_calculator_spec.rb +36 -0
  95. data/spec/adhearsion/menu_dsl_spec.rb +12 -0
  96. data/spec/adhearsion/outbound_call_spec.rb +174 -0
  97. data/spec/adhearsion/plugin_spec.rb +489 -0
  98. data/spec/adhearsion/process_spec.rb +34 -0
  99. data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +294 -0
  100. data/spec/adhearsion/router/route_spec.rb +99 -0
  101. data/spec/adhearsion/router_spec.rb +106 -0
  102. data/spec/adhearsion_spec.rb +46 -0
  103. data/spec/spec_helper.rb +14 -14
  104. data/spec/support/call_controller_test_helpers.rb +48 -0
  105. data/spec/support/initializer_stubs.rb +8 -13
  106. data/spec/support/punchblock_mocks.rb +6 -0
  107. metadata +255 -253
  108. data/CHANGELOG +0 -174
  109. data/bin/ahnctl +0 -68
  110. data/bin/jahn +0 -43
  111. data/examples/asterisk_manager_interface/standalone.rb +0 -51
  112. data/lib/adhearsion/commands.rb +0 -302
  113. data/lib/adhearsion/component_manager.rb +0 -278
  114. data/lib/adhearsion/component_manager/component_tester.rb +0 -54
  115. data/lib/adhearsion/component_manager/spec_framework.rb +0 -18
  116. data/lib/adhearsion/events_support.rb +0 -65
  117. data/lib/adhearsion/foundation/blank_slate.rb +0 -3
  118. data/lib/adhearsion/foundation/event_socket.rb +0 -205
  119. data/lib/adhearsion/foundation/future_resource.rb +0 -36
  120. data/lib/adhearsion/foundation/metaprogramming.rb +0 -17
  121. data/lib/adhearsion/foundation/numeric.rb +0 -13
  122. data/lib/adhearsion/foundation/pseudo_guid.rb +0 -10
  123. data/lib/adhearsion/foundation/relationship_properties.rb +0 -42
  124. data/lib/adhearsion/foundation/string.rb +0 -26
  125. data/lib/adhearsion/generators/app/templates/.ahnrc +0 -34
  126. data/lib/adhearsion/generators/app/templates/README +0 -8
  127. data/lib/adhearsion/generators/app/templates/components/ami_remote/ami_remote.rb +0 -15
  128. data/lib/adhearsion/generators/app/templates/components/disabled/HOW_TO_ENABLE +0 -7
  129. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/README.markdown +0 -47
  130. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.rb +0 -34
  131. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.yml +0 -12
  132. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/README.markdown +0 -3
  133. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +0 -11
  134. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
  135. data/lib/adhearsion/generators/app/templates/config/startup.rb +0 -81
  136. data/lib/adhearsion/generators/app/templates/dialplan.rb +0 -3
  137. data/lib/adhearsion/generators/app/templates/events.rb +0 -33
  138. data/lib/adhearsion/host_definitions.rb +0 -67
  139. data/lib/adhearsion/initializer/asterisk.rb +0 -86
  140. data/lib/adhearsion/initializer/configuration.rb +0 -324
  141. data/lib/adhearsion/initializer/database.rb +0 -60
  142. data/lib/adhearsion/initializer/drb.rb +0 -31
  143. data/lib/adhearsion/initializer/freeswitch.rb +0 -22
  144. data/lib/adhearsion/initializer/ldap.rb +0 -57
  145. data/lib/adhearsion/initializer/rails.rb +0 -41
  146. data/lib/adhearsion/initializer/xmpp.rb +0 -42
  147. data/lib/adhearsion/tasks/components.rb +0 -32
  148. data/lib/adhearsion/tasks/database.rb +0 -5
  149. data/lib/adhearsion/tasks/deprecations.rb +0 -59
  150. data/lib/adhearsion/tasks/generating.rb +0 -20
  151. data/lib/adhearsion/tasks/lint.rb +0 -4
  152. data/lib/adhearsion/voip/asterisk.rb +0 -4
  153. data/lib/adhearsion/voip/asterisk/agi_server.rb +0 -121
  154. data/lib/adhearsion/voip/asterisk/commands.rb +0 -1966
  155. data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +0 -140
  156. data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +0 -102
  157. data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +0 -250
  158. data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +0 -240
  159. data/lib/adhearsion/voip/asterisk/config_manager.rb +0 -64
  160. data/lib/adhearsion/voip/asterisk/manager_interface.rb +0 -697
  161. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +0 -1681
  162. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +0 -341
  163. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +0 -78
  164. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +0 -87
  165. data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +0 -80
  166. data/lib/adhearsion/voip/call.rb +0 -521
  167. data/lib/adhearsion/voip/call_routing.rb +0 -64
  168. data/lib/adhearsion/voip/commands.rb +0 -17
  169. data/lib/adhearsion/voip/constants.rb +0 -39
  170. data/lib/adhearsion/voip/conveniences.rb +0 -18
  171. data/lib/adhearsion/voip/dial_plan.rb +0 -252
  172. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +0 -151
  173. data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +0 -37
  174. data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +0 -27
  175. data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +0 -124
  176. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +0 -69
  177. data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +0 -16
  178. data/lib/adhearsion/voip/dsl/numerical_string.rb +0 -128
  179. data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +0 -48
  180. data/lib/adhearsion/voip/freeswitch/event_handler.rb +0 -58
  181. data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +0 -129
  182. data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +0 -38
  183. data/lib/adhearsion/voip/freeswitch/oes_server.rb +0 -195
  184. data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +0 -80
  185. data/lib/adhearsion/voip/menu_state_machine/matchers.rb +0 -123
  186. data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +0 -57
  187. data/lib/adhearsion/xmpp/connection.rb +0 -61
  188. data/lib/theatre.rb +0 -147
  189. data/lib/theatre/README.markdown +0 -64
  190. data/lib/theatre/callback_definition_loader.rb +0 -86
  191. data/lib/theatre/guid.rb +0 -23
  192. data/lib/theatre/invocation.rb +0 -131
  193. data/lib/theatre/namespace_manager.rb +0 -153
  194. data/lib/theatre/version.rb +0 -2
  195. data/spec/adhearsion/cli_spec.rb +0 -306
  196. data/spec/adhearsion/component_manager_spec.rb +0 -292
  197. data/spec/adhearsion/constants_spec.rb +0 -8
  198. data/spec/adhearsion/drb_spec.rb +0 -65
  199. data/spec/adhearsion/fixtures/dialplan.rb +0 -3
  200. data/spec/adhearsion/foundation/event_socket_spec.rb +0 -168
  201. data/spec/adhearsion/host_definitions_spec.rb +0 -79
  202. data/spec/adhearsion/initializer/configuration_spec.rb +0 -291
  203. data/spec/adhearsion/initializer/loading_spec.rb +0 -154
  204. data/spec/adhearsion/initializer/paths_spec.rb +0 -74
  205. data/spec/adhearsion/relationship_properties_spec.rb +0 -54
  206. data/spec/adhearsion/voip/asterisk/agi_server_spec.rb +0 -473
  207. data/spec/adhearsion/voip/asterisk/ami/ami_spec.rb +0 -550
  208. data/spec/adhearsion/voip/asterisk/ami/lexer/ami_fixtures.yml +0 -30
  209. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story +0 -291
  210. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story.rb +0 -241
  211. data/spec/adhearsion/voip/asterisk/ami/lexer/story_helper.rb +0 -124
  212. data/spec/adhearsion/voip/asterisk/commands_spec.rb +0 -3241
  213. data/spec/adhearsion/voip/asterisk/config_file_generators/agents_spec.rb +0 -251
  214. data/spec/adhearsion/voip/asterisk/config_file_generators/queues_spec.rb +0 -323
  215. data/spec/adhearsion/voip/asterisk/config_file_generators/voicemail_spec.rb +0 -306
  216. data/spec/adhearsion/voip/asterisk/config_manager_spec.rb +0 -127
  217. data/spec/adhearsion/voip/asterisk/menu_command/calculated_match_spec.rb +0 -109
  218. data/spec/adhearsion/voip/asterisk/menu_command/matchers_spec.rb +0 -97
  219. data/spec/adhearsion/voip/call_routing_spec.rb +0 -125
  220. data/spec/adhearsion/voip/dialplan_manager_spec.rb +0 -468
  221. data/spec/adhearsion/voip/dsl/dialing_dsl_spec.rb +0 -270
  222. data/spec/adhearsion/voip/dsl/dispatcher_spec.rb +0 -82
  223. data/spec/adhearsion/voip/dsl/dispatcher_spec_helper.rb +0 -45
  224. data/spec/adhearsion/voip/dsl/parser_spec.rb +0 -69
  225. data/spec/adhearsion/voip/freeswitch/basic_connection_manager_spec.rb +0 -39
  226. data/spec/adhearsion/voip/freeswitch/inbound_connection_manager_spec.rb +0 -39
  227. data/spec/adhearsion/voip/freeswitch/oes_server_spec.rb +0 -9
  228. data/spec/adhearsion/voip/numerical_string_spec.rb +0 -61
  229. data/spec/adhearsion/voip/phone_number_spec.rb +0 -45
  230. data/spec/support/the_following_code.rb +0 -3
  231. data/spec/theatre/dsl_examples/simple_before_call.rb +0 -7
  232. data/spec/theatre/dsl_spec.rb +0 -69
  233. data/spec/theatre/invocation_spec.rb +0 -182
  234. data/spec/theatre/namespace_spec.rb +0 -125
  235. data/spec/theatre/spec_helper_spec.rb +0 -28
  236. data/spec/theatre/theatre_class_spec.rb +0 -148
@@ -1,13 +1,6 @@
1
1
  require 'English'
2
2
  require 'tmpdir'
3
3
  require 'tempfile'
4
- begin
5
- # Try ActiveSupport >= 2.3.0
6
- require 'active_support/all'
7
- rescue LoadError
8
- # Assume ActiveSupport < 2.3.0
9
- require 'active_support'
10
- end
11
4
 
12
5
  # Require all other files here.
13
6
  Dir.glob File.join(File.dirname(__FILE__), "*rb") do |file|
@@ -17,15 +17,13 @@ module Adhearsion
17
17
  end
18
18
 
19
19
  # This method causes the current running process to become a daemon
20
- def daemonize(log_file='/dev/null')
20
+ def daemonize(log_file = '/dev/null')
21
21
  oldmode = 0
22
22
  srand # Split rand streams between spawning and daemonized process
23
23
  safefork and exit # Fork and exit from the parent
24
24
 
25
25
  # Detach from the controlling terminal
26
- unless sess_id = Process.setsid
27
- raise 'Cannot detach from controlled terminal'
28
- end
26
+ raise 'Cannot detach from controlled terminal' unless sess_id = ::Process.setsid
29
27
 
30
28
  # Prevent the possibility of acquiring a controlling terminal
31
29
  if oldmode.zero?
@@ -39,7 +37,7 @@ module Adhearsion
39
37
  STDIN.reopen "/dev/null"
40
38
  STDOUT.reopen '/dev/null', "a"
41
39
  STDERR.reopen log_file, "a"
42
- return oldmode ? sess_id : 0
40
+ oldmode ? sess_id : 0
43
41
  end
44
42
  end
45
- end
43
+ end
@@ -0,0 +1,9 @@
1
+ class Object
2
+ def catching_standard_errors(&block)
3
+ begin
4
+ yield
5
+ rescue StandardError => e
6
+ Adhearsion::Events.trigger :exception, e
7
+ end
8
+ end
9
+ end
@@ -1,10 +1,28 @@
1
- # Monkey patch Object to support the #tap method.
2
- # This method is present in Ruby 1.8.7 and later.
3
- unless Object.respond_to?(:tap)
4
- class Object
5
- def tap
6
- yield self
7
- self
1
+ require 'adhearsion/logging'
2
+
3
+ class Object
4
+ def pb_logger
5
+ logger
6
+ end
7
+
8
+ def logger_id
9
+ self
10
+ end
11
+
12
+ def method_missing(method_id, *arguments, &block)
13
+ if method_id == Adhearsion::Logging::METHOD
14
+ self.class.send :define_method, method_id do
15
+ Logging.logger[logger_id]
16
+ end
17
+ Logging.logger[logger_id]
18
+ else
19
+ super
8
20
  end
9
21
  end
10
- end
22
+
23
+ def respond_to?(method_id, include_private = false)
24
+ return true if method_id == Adhearsion::Logging::METHOD
25
+
26
+ super
27
+ end
28
+ end
@@ -7,14 +7,13 @@ class SynchronizedHash
7
7
  class_eval(<<-RUBY, __FILE__, __LINE__)
8
8
  def #{method_name}(*args, &block)
9
9
  @lock.synchronize do
10
- @delegate.send(#{method_name.inspect}, *args, &block)
10
+ @delegate.send #{method_name.inspect}, *args, &block
11
11
  end
12
12
  end
13
13
  RUBY
14
14
  end
15
15
 
16
16
  # Hash-related methods
17
-
18
17
  atomically_delegate :[]
19
18
  atomically_delegate :[]=
20
19
  atomically_delegate :all?
@@ -73,13 +72,12 @@ class SynchronizedHash
73
72
  atomically_delegate :zip
74
73
 
75
74
  # Object-related methods
76
-
77
75
  atomically_delegate :inspect
78
76
  atomically_delegate :to_s
79
77
  atomically_delegate :marshal_dump
80
78
 
81
79
  def initialize(*args, &block)
82
- @delegate = Hash.new(*args, &block)
80
+ @delegate = Hash.new *args, &block
83
81
  @lock = Mutex.new
84
82
  end
85
83
 
@@ -92,5 +90,4 @@ class SynchronizedHash
92
90
  def with_lock(&block)
93
91
  @lock.synchronize { yield @delegate }
94
92
  end
95
-
96
- end
93
+ end
@@ -1,7 +1,23 @@
1
1
  require 'thread'
2
+
2
3
  class Object
3
4
  def synchronize(&block)
4
5
  @mutex ||= Mutex.new
5
6
  @mutex.synchronize &block
6
7
  end
7
- end
8
+ end
9
+
10
+ class ThreadSafeArray
11
+ include Enumerable
12
+
13
+ def initialize
14
+ @mutex = Mutex.new
15
+ @array = []
16
+ end
17
+
18
+ def method_missing(method, *args, &block)
19
+ @mutex.synchronize do
20
+ @array.send method, *args, &block
21
+ end
22
+ end
23
+ end
@@ -12,11 +12,7 @@ module Adhearsion
12
12
  class AppGenerator < Thor::Group
13
13
  include Thor::Actions
14
14
 
15
- BASEDIRS = %w{
16
- components
17
- config
18
- script
19
- }
15
+ BASEDIRS = %w( config lib script )
20
16
 
21
17
  argument :app_action, :type => :string
22
18
  argument :app_path, :type => :string
@@ -33,14 +29,9 @@ module Adhearsion
33
29
  def setup_project
34
30
  self.destination_root = @app_path
35
31
  BASEDIRS.each { |dir| directory dir }
36
- %w{
37
- .ahnrc
38
- dialplan.rb
39
- events.rb
40
- README
41
- Rakefile
42
- Gemfile
43
- }.each { |file| copy_file file }
32
+ copy_file "Gemfile"
33
+ copy_file "Rakefile"
34
+ copy_file "README.md"
44
35
  end
45
36
  end
46
37
  end
@@ -1,10 +1,15 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
- gem "adhearsion", ">= 1.2.4"
3
+ gem "adhearsion", :git => 'git://github.com/adhearsion/adhearsion.git', :branch => :develop
4
4
 
5
5
  #
6
- # Here are some example components you might like to use. Simply
7
- # uncomment them, run `bundle install` and enable in startup.rb.
6
+ # Here are some example plugins you might like to use. Simply
7
+ # uncomment them and run `bundle install`.
8
8
  #
9
9
 
10
- # gem 'ahn-restful-rpc'
10
+ # gem 'adhearsion-asterisk'
11
+ # gem 'adhearsion-rails'
12
+ # gem 'adhearsion-activerecord'
13
+ # gem 'adhearsion-ldap'
14
+ # gem 'adhearsion-xmpp'
15
+ # gem 'adhearsion-drb'
@@ -0,0 +1 @@
1
+ ahn: bundle exec ahn start .
@@ -0,0 +1,28 @@
1
+ # Welcome to Adhearsion
2
+
3
+ You've got a fresh app and you're almost ready to get started. Firstly, you'll need to configure your VoIP platform:
4
+
5
+ ## Asterisk
6
+
7
+ Edit `extensions.conf` to include the following:
8
+
9
+ ```
10
+ [your_context_name]
11
+ exten => _.,1,AGI(agi:async)
12
+ ```
13
+
14
+ and setup a user in `manager.conf` with read/write access to `all`.
15
+
16
+ ## Voxeo PRISM
17
+
18
+ Install the [rayo-server](https://github.com/rayo/rayo-server) app into PRISM 11 and follow the [configuration guide](https://github.com/rayo/rayo-server/wiki/Single-node-and-cluster-configuration-reference).
19
+
20
+ ## Configure your app
21
+
22
+ In `config/adhearsion.rb` you'll need to set the VoIP platform you're using, along with the correct credentials. You'll find example config there, so follow the comments.
23
+
24
+ ## Ready, set, go!
25
+
26
+ Start your new app with "ahn start /path/to/your/app". You'll get a lovely console and should be presented with the SimonGame
27
+
28
+ Check out [the Adhearsion website](http://adhearsion.com) for more details of where to go from here.
@@ -0,0 +1,41 @@
1
+ # Centralized way to overwrite any Adhearsion platform or plugin configuration
2
+ # - Execute rake adhearsion:config:desc to get the configuration options
3
+ # - Execute rake adhearsion:config:show to get the configuration values
4
+ #
5
+ # To update a plugin configuration you can write either:
6
+ #
7
+ # * Option 1
8
+ # Adhearsion.config.<plugin-name> do |config|
9
+ # config.<key> = <value>
10
+ # end
11
+ #
12
+ # * Option 2
13
+ # Adhearsion.config do |config|
14
+ # config.<plugin-name>.<key> = <value>
15
+ # end
16
+
17
+ Adhearsion.config do |config|
18
+
19
+ config.development do |dev|
20
+ dev.platform.logging.level = :debug
21
+ end
22
+
23
+ ##
24
+ # Use with Voxeo PRISM or other Rayo installation
25
+ #
26
+ # config.punchblock.username = "" # Your XMPP JID for use with Rayo
27
+ # config.punchblock.password = "" # Your XMPP password
28
+
29
+ ##
30
+ # Use with Asterisk
31
+ #
32
+ # config.punchblock.platform = :asterisk # Your AMI username
33
+ # config.punchblock.username = "" # Your AMI username
34
+ # config.punchblock.password = "" # Your AMI password
35
+ # config.punchblock.host = "127.0.0.1" # Your AMI host
36
+ # config.punchblock.port = 5038 # Your AMI port
37
+ end
38
+
39
+ Adhearsion.router do
40
+ route 'default', SimonGame
41
+ end
@@ -1,17 +1,6 @@
1
- methods_for :dialplan do
2
- def simon_game
3
- SimonGame.new(self).start
4
- end
5
- end
6
-
7
- class SimonGame
8
-
9
- def initialize(call)
10
- @call = call
1
+ class SimonGame < Adhearsion::CallController
2
+ def run
11
3
  reset
12
- end
13
-
14
- def start
15
4
  loop do
16
5
  say_number
17
6
  collect_attempt
@@ -29,18 +18,18 @@ class SimonGame
29
18
 
30
19
  def say_number
31
20
  update_number
32
- @call.say_digits @number
21
+ speak @number
33
22
  end
34
23
 
35
24
  def collect_attempt
36
- @attempt = @call.input @number.length
25
+ @attempt = input @number.length
37
26
  end
38
27
 
39
28
  def verify_attempt
40
29
  if attempt_correct?
41
- @call.play 'good'
30
+ speak 'good'
42
31
  else
43
- @call.play %W[#{@number.length-1} times wrong-try-again-smarty]
32
+ speak "#{@number.length - 1} times wrong, try again smarty"
44
33
  reset
45
34
  end
46
35
  end
@@ -52,5 +41,4 @@ class SimonGame
52
41
  def reset
53
42
  @attempt, @number = '', ''
54
43
  end
55
-
56
44
  end
@@ -3,6 +3,6 @@
3
3
  require File.expand_path('../../config/environment', __FILE__)
4
4
 
5
5
  require 'adhearsion'
6
- require 'adhearsion/commands'
6
+ require 'adhearsion/cli_commands'
7
7
 
8
- Adhearsion::CLI::AhnCommand.execute!
8
+ Adhearsion::CLI::AhnCommand.start
@@ -1,115 +1,19 @@
1
- module Adhearsion
2
-
3
- mattr_accessor :status
4
-
5
- class << self
6
-
7
- ##
8
- # Shuts down the framework.
9
- #
10
- def shutdown!
11
- if self.status == :stopping
12
- # This is the second shutdown request we've received while attempting
13
- # to shut down gracefully. At this point, let's pull the plug...
14
- ahn_log.warning "Shutting down immediately at #{Time.now}"
15
- exit
16
- end
17
- ahn_log "Shutting down gracefully at #{Time.now}."
18
- self.status = :stopping
19
- Events.trigger_immediately :shutdown
20
- Events.stop!
21
- exit
22
- end
23
-
24
- end
25
- class PathString < String
26
-
27
- class << self
28
-
29
- ##
30
- # Will return a PathString for the application root folder to which the specified arbitrarily nested subfolder belongs.
31
- # It works by traversing parent directories looking for the .ahnrc file. If no .ahnrc is found, nil is returned.
32
- #
33
- # @param [String] folder The path to the directory which should be a
34
- # @return [nil] if the subdirectory does not belong to a parent Adhearsion app directory
35
- # @return [PathString] if a directory is found
36
- #
37
- def from_application_subdirectory(folder)
38
- folder = File.expand_path folder
39
- ahn_rc = nil
40
-
41
- until ahn_rc || folder == "/"
42
- possible_ahn_rc = File.join(folder, ".ahnrc")
43
- if File.exists?(possible_ahn_rc)
44
- ahn_rc = possible_ahn_rc
45
- else
46
- folder = File.expand_path(folder + "/..")
47
- end
48
- end
49
- ahn_rc ? new(folder) : nil
50
- end
51
- end
52
-
53
- attr_accessor :component_path, :dialplan_path, :log_path
54
-
55
- def initialize(path)
56
- super
57
- defaults
58
- end
59
-
60
- def defaults
61
- @component_path = build_path_for "components"
62
- @dialplan_path = dup
63
- @log_path = build_path_for "logs"
64
- end
65
-
66
- def base_path=(value)
67
- replace(value)
68
- defaults
69
- end
70
-
71
- def using_base_path(temporary_base_path, &block)
72
- original_path = dup
73
- self.base_path = temporary_base_path
74
- block.call
75
- ensure
76
- self.base_path = original_path
77
- end
78
-
79
- private
80
- def build_path_for(path)
81
- File.join(to_s, path)
82
- end
83
- end
1
+ require 'adhearsion/punchblock_plugin'
84
2
 
3
+ module Adhearsion
85
4
  class Initializer
86
5
 
87
- class << self
88
- def get_rules_from(location)
89
- location = File.join location, ".ahnrc" if File.directory? location
90
- File.exists?(location) ? YAML.load_file(location) : nil
91
- end
6
+ extend ActiveSupport::Autoload
92
7
 
93
- def ahn_root=(path)
94
- if Object.constants.map(&:to_sym).include?(:AHN_ROOT)
95
- Object.const_get(:AHN_ROOT).base_path = File.expand_path(path)
96
- else
97
- Object.const_set(:AHN_ROOT, PathString.new(File.expand_path(path)))
98
- end
99
- end
8
+ autoload :Logging
100
9
 
10
+ class << self
101
11
  def start(*args, &block)
102
12
  new(*args, &block).start
103
13
  end
104
-
105
- def start_from_init_file(file, ahn_app_path)
106
- return if defined?(@@started) && @@started
107
- start ahn_app_path, :loaded_init_files => file
108
- end
109
-
110
14
  end
111
15
 
112
- attr_reader :path, :daemon, :pid_file, :log_file, :ahn_app_log_directory
16
+ attr_reader :path, :daemon, :pid_file
113
17
 
114
18
  # Creation of pid_files
115
19
  #
@@ -122,198 +26,163 @@ module Adhearsion
122
26
  # one is not created UNLESS it is running in daemon mode, in which
123
27
  # case one is created. You can force Adhearsion to not create one
124
28
  # even in daemon mode by supplying "false".
125
- def initialize(path=nil, options={})
29
+ def initialize(options = {})
126
30
  @@started = true
127
31
  @path = path
128
32
  @mode = options[:mode]
129
33
  @pid_file = options[:pid_file].nil? ? ENV['PID_FILE'] : options[:pid_file]
130
34
  @loaded_init_files = options[:loaded_init_files]
131
- self.class.ahn_root = path
35
+ Adhearsion.ahn_root = '.'
132
36
  end
133
37
 
134
38
  def start
135
- Adhearsion.status = :starting
136
-
137
39
  resolve_pid_file_path
138
- resolve_log_file_path
40
+ load_lib_folder
41
+ load_plugins_methods
42
+ load_config
43
+ initialize_log_paths
139
44
  daemonize! if should_daemonize?
140
45
  launch_console if need_console?
141
- switch_to_root_directory
142
46
  catch_termination_signal
143
- create_pid_file if pid_file
144
- bootstrap_rc
145
- initialize_log_file
47
+ create_pid_file
48
+ start_logging
49
+ logger.info "Loaded config in <#{Adhearsion.config.platform.environment}> environment"
146
50
  initialize_exception_logger
147
- load_all_init_files
148
- init_datasources
149
- init_components_subsystem
150
- init_modules
151
- init_events_subsystem
152
- load_components
153
- init_events_file
51
+ update_rails_env_var
52
+ init_plugins
154
53
 
155
- ahn_log "Adhearsion v#{Adhearsion::VERSION::STRING} initialized!"
156
- Adhearsion.status = :running
54
+ logger.info "Adhearsion v#{Adhearsion::VERSION} initialized!"
55
+ Adhearsion::Process.booted
157
56
 
158
57
  trigger_after_initialized_hooks
159
58
  join_important_threads
160
-
161
59
  self
162
60
  end
163
61
 
62
+ def update_rails_env_var
63
+ env = ENV['AHN_ENV']
64
+ if env && Adhearsion.config.valid_environment?(env.to_sym)
65
+ if ENV['RAILS_ENV'] != env
66
+ logger.warn "Updating AHN_RAILS variable to <#{env}>"
67
+ ENV['RAILS_ENV'] = env
68
+ else
69
+ logger.info "Using the configured value for RAILS_ENV : <#{env}>"
70
+ end
71
+ else
72
+ env = ENV['RAILS_ENV']
73
+ unless env
74
+ env = Adhearsion.config.platform.environment.to_s
75
+ logger.info "Defining AHN_RAILS variable to <#{env}>"
76
+ ENV['RAILS_ENV'] = env
77
+ else
78
+ logger.info "Using the configured value for RAILS_ENV : <#{env}>"
79
+ end
80
+ end
81
+ env
82
+ end
83
+
164
84
  def default_pid_path
165
- File.join AHN_ROOT, 'adhearsion.pid'
85
+ File.join Adhearsion.config.root, 'adhearsion.pid'
166
86
  end
167
87
 
168
88
  def resolve_pid_file_path
169
- @pid_file = if pid_file.equal?(true) then default_pid_path
170
- elsif pid_file then pid_file
171
- elsif pid_file.equal?(false) then nil
172
- # FIXME @pid_file = @daemon? Assignment or equality? I'm assuming equality.
173
- else @pid_file = (@mode == :daemon) ? default_pid_path : nil
89
+ @pid_file = if pid_file.equal?(true)
90
+ default_pid_path
91
+ elsif pid_file.equal?(false)
92
+ nil
93
+ elsif pid_file
94
+ File.expand_path pid_file
95
+ else
96
+ should_daemonize? ? default_pid_path : nil
174
97
  end
175
98
  end
176
99
 
177
100
  def resolve_log_file_path
178
- @ahn_app_log_directory = AHN_ROOT + '/log'
179
- @log_file = File.expand_path(ahn_app_log_directory + "/adhearsion.log")
180
- end
181
-
182
- def switch_to_root_directory
183
- Dir.chdir AHN_ROOT
101
+ _log_file = Adhearsion.config.platform.logging.outputters
102
+ _log_file = _log_file[0] if _log_file.is_a?(Array)
103
+ _log_file = File.expand_path(Adhearsion.config.root.dup.concat("/").concat(_log_file)) unless _log_file.start_with?("/")
104
+ _log_file
184
105
  end
185
106
 
186
107
  def catch_termination_signal
187
108
  %w'INT TERM'.each do |process_signal|
188
109
  trap process_signal do
189
- Adhearsion.shutdown!
110
+ Adhearsion::Process.shutdown
190
111
  end
191
112
  end
192
- end
193
-
194
- ##
195
- # This step in the initialization process loads the .ahnrc in the given app folder. With the information in .ahnrc, we
196
- # can continue the initialization knowing where certain files are specifically.
197
- #
198
- def bootstrap_rc
199
- rules = self.class.get_rules_from AHN_ROOT
200
-
201
- AHN_CONFIG.ahnrc = rules
202
-
203
- # DEPRECATION: Check if the old paths format is being used. If so, abort and notify.
204
- if rules.has_key?("paths") && rules["paths"].kind_of?(Hash)
205
- paths = rules["paths"].each_pair do |key,value|
206
- if value.kind_of?(Hash)
207
- if value.has_key?("directory") || value.has_key?("pattern")
208
- puts
209
- puts *caller
210
- puts
211
-
212
- abort <<-WARNING
213
- Deprecation Warning
214
- -------------------
215
- The (hidden) .ahnrc file in this app is of an older format and needs to be fixed.
216
-
217
- There is a rake task to automatically fix it or you can do it manually. Note: it's
218
- best if you do it manually so you can retain the YAML comments in your .ahnrc file.
219
-
220
- The rake task is called "deprecations:fix_ahnrc_path_format".
221
-
222
- To do it manually, find all entries in the "paths" section of your ".ahnrc" file
223
- which look like the following:
224
-
225
- paths:
226
- key_name_could_be_anything:
227
- directory: some_folder
228
- pattern: *.rb
229
-
230
- Note: the "models" section had this syntax before:
231
113
 
232
- models:
233
- directory: models
234
- pattern: "*.rb"
235
-
236
- The NEW syntax is as follows (using models as an example):
237
-
238
- models: models/*.rb
239
-
240
- This new format is much cleaner.
114
+ trap 'QUIT' do
115
+ Adhearsion::Process.hard_shutdown
116
+ end
241
117
 
242
- Adhearsion will abort until you fix this. Sorry for the incovenience.
243
- WARNING
244
- end
245
- end
246
- end
118
+ trap 'ABRT' do
119
+ Adhearsion::Process.force_stop
247
120
  end
121
+ end
248
122
 
249
- gems = rules['gems']
250
- if gems.kind_of?(Hash) && gems.any? && respond_to?(:gem)
251
- gems.each_pair do |gem_name,properties_hash|
252
- if properties_hash && properties_hash["version"]
253
- gem gem_name, properties_hash["version"]
254
- else
255
- gem gem_name
256
- end
257
- if properties_hash
258
- case properties_hash["require"]
259
- when Array
260
- properties_hash["require"].each { |lib| require lib }
261
- when String
262
- require properties_hash["require"]
263
- end
264
- end
123
+ ##
124
+ # Loads files in application lib folder
125
+ # @return [Boolean] if files have been loaded (lib folder is configured to not nil and actually exists)
126
+ def load_lib_folder
127
+ return false if Adhearsion.config.platform.lib.nil?
128
+
129
+ lib_folder = [Adhearsion.config.platform.root, Adhearsion.config.platform.lib].join '/'
130
+ return false unless File.directory? lib_folder
131
+
132
+ Dir.chdir lib_folder do
133
+ rbfiles = File.join "**", "*.rb"
134
+ Dir.glob(rbfiles).each do |file|
135
+ require "#{lib_folder}/#{file}"
265
136
  end
266
137
  end
138
+ true
267
139
  end
268
140
 
269
- def load_all_init_files
270
- init_files_from_rc = AHN_CONFIG.files_from_setting("paths", "init").map { |file| File.expand_path(file) }
271
- already_loaded_init_files = Array(@loaded_init_files).map { |file| File.expand_path(file) }
272
- (init_files_from_rc - already_loaded_init_files).each { |init| load init }
141
+ def load_config
142
+ require "#{Adhearsion.config.root}/config/adhearsion.rb"
273
143
  end
274
144
 
275
- def init_datasources
276
- require 'adhearsion/initializer/database.rb'
277
- require 'adhearsion/initializer/ldap.rb'
278
-
279
- DatabaseInitializer.start if AHN_CONFIG.database_enabled?
280
- LdapInitializer.start if AHN_CONFIG.ldap_enabled?
145
+ def init_get_logging_appenders
146
+ @file_loggers ||= memoize_logging_appenders
281
147
  end
282
148
 
283
- def init_modules
284
-
285
- require 'adhearsion/initializer/asterisk.rb'
286
- require 'adhearsion/initializer/drb.rb'
287
- require 'adhearsion/initializer/rails.rb'
288
- require 'adhearsion/initializer/xmpp.rb'
289
- # require 'adhearsion/initializer/freeswitch.rb'
290
-
291
- AsteriskInitializer.start if AHN_CONFIG.asterisk_enabled?
292
- DrbInitializer.start if AHN_CONFIG.drb_enabled?
293
- RailsInitializer.start if AHN_CONFIG.rails_enabled?
294
- XMPPInitializer.start if AHN_CONFIG.xmpp_enabled?
295
- # FreeswitchInitializer.start if AHN_CONFIG.freeswitch_enabled?
296
-
297
- end
298
-
299
- def init_events_subsystem
300
- application_events_files = AHN_CONFIG.files_from_setting("paths", "events")
301
- if application_events_files.any?
302
- Events.register_callback(:shutdown) do
303
- ahn_log.events "Performing a graceful stop of events subsystem"
304
- Events.framework_theatre.graceful_stop!
149
+ def memoize_logging_appenders
150
+ appenders = Array(Adhearsion.config.platform.logging.outputters.dup)
151
+ # Any filename in the outputters array is mapped to a ::Logging::Appenders::File instance
152
+ appenders.map! do |a|
153
+ case a
154
+ when String
155
+ f = File.expand_path(Adhearsion.config.root.dup.concat("/").concat(a)) unless a.start_with?("/")
156
+ ::Logging.appenders.file(f,
157
+ :layout => ::Logging.layouts.pattern(
158
+ :pattern => Adhearsion::Logging.adhearsion_pattern
159
+ )
160
+ )
161
+ else
162
+ a
305
163
  end
306
- Events.framework_theatre.start!
164
+ end
165
+
166
+ if should_daemonize?
167
+ appenders
307
168
  else
308
- ahn_log.events.warn 'No entries in the "events" section of .ahnrc. Skipping its initialization.'
169
+ stdout = ::Logging.appenders.stdout(
170
+ 'stdout',
171
+ :layout => ::Logging.layouts.pattern(
172
+ :pattern => Adhearsion::Logging.adhearsion_pattern,
173
+ :color_scheme => 'bright'
174
+ )
175
+ )
176
+ appenders << stdout
309
177
  end
310
178
  end
311
179
 
312
- def init_events_file
313
- application_events_files = AHN_CONFIG.files_from_setting("paths", "events")
314
- application_events_files.each do |file|
315
- Events.framework_theatre.load_events_file file
316
- end
180
+ def load_plugins_methods
181
+ Plugin.load_methods
182
+ end
183
+
184
+ def init_plugins
185
+ Plugin.init_plugins
317
186
  end
318
187
 
319
188
  def should_daemonize?
@@ -325,71 +194,60 @@ Adhearsion will abort until you fix this. Sorry for the incovenience.
325
194
  end
326
195
 
327
196
  def daemonize!
328
- ahn_log "Daemonizing now! Creating #{pid_file}."
197
+ logger.info "Daemonizing now!"
198
+ logger.info "Creating PID file #{pid_file}"
329
199
  extend Adhearsion::CustomDaemonizer
330
- daemonize log_file
200
+ daemonize resolve_log_file_path
331
201
  end
332
202
 
333
203
  def launch_console
334
- require 'adhearsion/console'
335
- Thread.new do
336
- begin
337
- puts "Starting console"
204
+ Adhearsion::Process.important_threads << Thread.new do
205
+ catching_standard_errors do
338
206
  Adhearsion::Console.run
339
- Adhearsion.shutdown!
340
- rescue Exception => e
341
- puts e.message
342
- puts e.backtrace.join("\n")
207
+ Adhearsion::Process.shutdown
343
208
  end
344
209
  end
345
210
  end
346
211
 
347
- def initialize_log_file
348
- Dir.mkdir(ahn_app_log_directory) unless File.directory? ahn_app_log_directory
349
- file_logger = Log4r::FileOutputter.new("Main Adhearsion log file", :filename => log_file, :trunc => false)
350
-
351
- if should_daemonize?
352
- Logging::AdhearsionLogger.outputters = [file_logger]
353
- else
354
- Logging::AdhearsionLogger.outputters << file_logger
212
+ # Creates the relative paths associated to log files
213
+ # i.e.
214
+ # - log_file = "log/adhearsion.log" => creates 'log' folder
215
+ # - log_file = "log/test/adhearsion.log" => creates 'log' and 'log/test' folders
216
+ def initialize_log_paths
217
+ outputters = Array(Adhearsion.config.platform.logging.outputters)
218
+ outputters.select{|o| o.is_a?(String)}.each do |o|
219
+ o = o.split("/")
220
+ unless o[0].empty? # only if relative path
221
+ o.pop # not consider filename
222
+ o.inject("") do |path, folder|
223
+ path = path.concat(folder).concat("/")
224
+ Dir.mkdir(path) unless File.directory? path
225
+ path
226
+ end
227
+ end
355
228
  end
356
- Logging::DefaultAdhearsionLogger.redefine_outputters
229
+ end
230
+
231
+ def start_logging
232
+ outputters = init_get_logging_appenders
233
+ Logging.start outputters, Adhearsion.config.platform.logging.level, Adhearsion.config.platform.logging.formatter
357
234
  end
358
235
 
359
236
  def initialize_exception_logger
360
- Events.register_callback :exception do |e|
361
- ahn_log.error "#{e.class}: #{e.message}"
362
- ahn_log.debug e.backtrace.join("\n\t")
237
+ Events.register_handler :exception do |e|
238
+ logger.error e
363
239
  end
364
240
  end
365
241
 
366
242
  def create_pid_file
367
- if pid_file
368
- File.open pid_file, 'w' do |file|
369
- file.puts Process.pid
370
- end
243
+ return unless pid_file
371
244
 
372
- Events.register_callback :shutdown do
373
- File.delete(pid_file) if File.exists?(pid_file)
374
- end
375
- end
376
- end
377
-
378
- def init_components_subsystem
379
- @components_directory = File.expand_path "components"
380
- if File.directory? @components_directory
381
- Components.component_manager = Components::ComponentManager.new @components_directory
382
- Kernel.send(:const_set, :COMPONENTS, Components.component_manager.lazy_config_loader)
383
- Components.component_manager.globalize_global_scope!
384
- Components.component_manager.extend_object_with(Theatre::CallbackDefinitionLoader, :events)
385
- else
386
- ahn_log.warn "No components directory found. Not initializing any components."
245
+ File.open pid_file, 'w' do |file|
246
+ file.puts ::Process.pid
387
247
  end
388
- end
389
248
 
390
- def load_components
391
- if Components.component_manager
392
- Components.component_manager.load_components
249
+ Events.register_callback :shutdown do
250
+ File.delete(pid_file) if File.exists?(pid_file)
393
251
  end
394
252
  end
395
253
 
@@ -398,24 +256,24 @@ Adhearsion will abort until you fix this. Sorry for the incovenience.
398
256
  end
399
257
 
400
258
  ##
401
- # This method will block Thread.main() until calling join() has returned for all Threads in IMPORTANT_THREADS.
402
- # Note: IMPORTANT_THREADS won't always contain Thread instances. It simply requires the objects respond to join().
259
+ # This method will block Thread.main() until calling join() has returned for all Threads in Adhearsion::Process.important_threads.
260
+ # Note: important_threads won't always contain Thread instances. It simply requires the objects respond to join().
403
261
  #
404
262
  def join_important_threads
405
263
  # Note: we're using this ugly accumulator to ensure that all threads have ended since IMPORTANT_THREADS will almost
406
264
  # certainly change sizes after this method is called.
407
265
  index = 0
408
- until index == IMPORTANT_THREADS.size
266
+ until index == Adhearsion::Process.important_threads.size
409
267
  begin
410
- IMPORTANT_THREADS[index].join
268
+ Adhearsion::Process.important_threads[index].join
411
269
  rescue => e
412
- ahn_log.error "Error after join()ing Thread #{Thread.inspect}. #{e.message}"
270
+ logger.error "Error after joining Thread #{Thread.inspect}. #{e.message}"
413
271
  ensure
414
272
  index = index + 1
415
273
  end
416
274
  end
417
275
  end
418
276
 
419
- class InitializationFailedError < StandardError; end
277
+ InitializationFailedError = Class.new StandardError
420
278
  end
421
279
  end