emissary 1.3.20 → 1.3.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+
data/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2010 The New York Times
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
@@ -0,0 +1,38 @@
1
+ lib/emissary.rb
2
+ lib/emissary/servolux.rb
3
+ lib/emissary/server.rb
4
+ lib/emissary/operator.rb
5
+ lib/emissary/operator/amqp.rb
6
+ lib/emissary/message.rb
7
+ lib/emissary/logger.rb
8
+ lib/emissary/identity.rb
9
+ lib/emissary/identity/unix.rb
10
+ lib/emissary/identity/ec2.rb
11
+ lib/emissary/gem_helper.rb
12
+ lib/emissary/errors.rb
13
+ lib/emissary/daemon.rb
14
+ lib/emissary/core_ext/symbolize.rb
15
+ lib/emissary/core_ext/misc_object.rb
16
+ lib/emissary/core_ext/blank.rb
17
+ lib/emissary/config.rb
18
+ lib/emissary/agent.rb
19
+ lib/emissary/agent/test.rb
20
+ lib/emissary/agent/stats.rb
21
+ lib/emissary/agent/sshkeys.rb
22
+ lib/emissary/agent/rabbitmq.rb
23
+ lib/emissary/agent/proxy.rb
24
+ lib/emissary/agent/ping.rb
25
+ lib/emissary/agent/mysql.rb
26
+ lib/emissary/agent/gem.rb
27
+ lib/emissary/agent/file.rb
28
+ lib/emissary/agent/error.rb
29
+ lib/emissary/inifile.rb
30
+ lib/emissary/agent/emissary.rb
31
+ etc/init.d/emissary
32
+ etc/emissary/config.ini
33
+ bin/emissary-setup
34
+ bin/emissary-send-message
35
+ bin/emissary
36
+ bin/amqp-listen
37
+ VERSION.yml
38
+ LICENSE
@@ -0,0 +1,54 @@
1
+ = Emissary
2
+
3
+ * FIX (url)
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ to install libraries:
24
+
25
+ sudo gem install emissary
26
+
27
+ to install scripts and config files:
28
+
29
+ sudo gem emissary
30
+
31
+ == LICENSE:
32
+
33
+ (The MIT License)
34
+
35
+ Copyright (c) 2009 The New York Times
36
+
37
+ Permission is hereby granted, free of charge, to any person obtaining
38
+ a copy of this software and associated documentation files (the
39
+ 'Software'), to deal in the Software without restriction, including
40
+ without limitation the rights to use, copy, modify, merge, publish,
41
+ distribute, sublicense, and/or sell copies of the Software, and to
42
+ permit persons to whom the Software is furnished to do so, subject to
43
+ the following conditions:
44
+
45
+ The above copyright notice and this permission notice shall be
46
+ included in all copies or substantial portions of the Software.
47
+
48
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
49
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
50
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
51
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
52
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
53
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
54
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,98 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'find'
5
+ require 'yaml'
6
+ require 'monitor'
7
+
8
+ def manifest_files
9
+ manifest_files = [];
10
+ base_path = File.expand_path('.')
11
+ search_paths = [
12
+ File.join(base_path, 'lib'),
13
+ File.join(base_path, 'etc'),
14
+ File.join(base_path, 'bin'),
15
+ File.join(base_path, 'VERSION.yml'),
16
+ File.join(base_path, 'LICENSE'),
17
+ ]
18
+
19
+ Find.find(*search_paths) do |path|
20
+ if File.directory? path
21
+ File.basename(path)[/^\./] ? Find.prune : next
22
+ end
23
+ manifest_files << path.gsub(base_path + ::File::SEPARATOR, '')
24
+ end
25
+
26
+ manifest_files
27
+ end
28
+
29
+ GEM = 'emissary'
30
+ GEM_VERSION = (v = YAML.load(File.read('VERSION.yml'))).keys.collect{|s|s.to_s}.sort.collect{|k| v[k.to_sym]}.join('.')
31
+ AUTHOR = 'Carl P. Corliss'
32
+ EMAIL = 'rabbitt@gmail.com'
33
+
34
+ spec = Gem::Specification.new do |s|
35
+ s.name = GEM
36
+ s.version = GEM_VERSION
37
+ s.author = AUTHOR
38
+ s.email = EMAIL
39
+ s.homepage = "http://nimbul.github.com/nimbul/"
40
+ s.platform = Gem::Platform::RUBY
41
+ s.summary = "EventMachine/AMQP based event handling client"
42
+ s.files = manifest_files()
43
+ s.require_path = "lib"
44
+ s.test_files = FileList["{test}/**/*test.rb"].to_a
45
+ s.has_rdoc = false
46
+ s.extra_rdoc_files = ["README.txt"]
47
+ s.executables = File.read('Manifest.txt').split(/\n+/).select { |f| f =~ /^bin/ }.collect { |f| f[/bin\/(.*)$/,1] }
48
+
49
+ s.default_executable = 'bin/emissary-setup'
50
+
51
+ s.add_dependency("daemons", ">= 1.0.10")
52
+ s.add_dependency('inifile', '>= 0.3.0')
53
+ s.add_dependency('sys-cpu', '>= 0.6.2')
54
+ s.add_dependency('bert', '>= 1.1.2')
55
+ s.add_dependency('amqp', '= 0.6.7')
56
+ s.add_dependency('carrot', '= 0.8.1')
57
+ s.add_dependency('eventmachine', '>= 0.12.10')
58
+ s.add_dependency('servolux', '>= 0.9.4')
59
+ s.add_dependency('uuid', '>= 2.3.0')
60
+ s.add_dependency('work_queue', '= 1.0.0')
61
+ end
62
+
63
+ require 'rubygems/package_task'
64
+ Gem::PackageTask.new(spec) do |pkg|
65
+ pkg.need_tar = true
66
+ end
67
+
68
+ require 'rake/clean'
69
+ CLEAN.include('pkg')
70
+
71
+
72
+ desc "install the gem locally"
73
+ task :install => [:package] do
74
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
75
+ end
76
+
77
+ namespace :spec do
78
+ desc "create a gemspec file"
79
+ task :create do
80
+ File.open("#{GEM}.gemspec", 'w') do |file|
81
+ file.puts spec.to_ruby
82
+ end
83
+ end
84
+ end
85
+
86
+ namespace :manifest do
87
+ desc "Rebuild Manifest file"
88
+ task :rebuild do
89
+ File.open('Manifest.txt', 'w') do |file|
90
+ file.puts manifest_files.join("\n")
91
+ end
92
+ end
93
+ end
94
+
95
+ rake_tasks_glob = File.join(File.dirname(File.expand_path(__FILE__)), 'tasks', '*.rake')
96
+ Dir[rake_tasks_glob].sort.each do |ext|
97
+ load ext
98
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 1
3
+ :minor: 3
4
+ :patch: 21
@@ -0,0 +1,226 @@
1
+ # Copyright 2010 The New York Times
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ #
16
+ require 'rubygems'
17
+ require 'bundler/setup'
18
+
19
+ require 'uuid'
20
+ require 'digest/md5'
21
+ require 'yaml'
22
+ require 'pathname'
23
+
24
+ begin
25
+ require 'thread'
26
+ require 'fastthread'
27
+ rescue LoadError
28
+ end
29
+
30
+ module Emissary
31
+ # :stopdoc:
32
+ LIBPATH = Pathname.new(__FILE__).dirname.realpath
33
+ PATH = LIBPATH.dirname
34
+ VERSION = ::YAML.load(File.read(PATH + 'VERSION.yml')).values.join '.'
35
+
36
+ EXTERNALS_BASE = File.join('emissary')
37
+ EXTERNAL_IDENTITIES = File.join(EXTERNALS_BASE, 'identities').to_s
38
+ EXTERNAL_AGENTS = File.join(EXTERNALS_BASE, 'agents').to_s
39
+ EXTERNAL_OPERATORS = File.join(EXTERNALS_BASE, 'operator').to_s
40
+
41
+ DEFAULT_EXCHANGE = :direct
42
+ DAEMON_RECHECK_INTERVAL = 10
43
+ IP_CHECK_DOMAIN = 'checkip.dyndns.org'
44
+ IP_CHECK_URL = "http://#{IP_CHECK_DOMAIN}"
45
+ # :startdoc:
46
+
47
+ class << self
48
+ @@pid = nil
49
+ def PID
50
+ @@pid
51
+ end
52
+
53
+ # Returns the version string for the library.
54
+ #
55
+ def version
56
+ VERSION
57
+ end
58
+
59
+ # Returns the library path for the module. If any arguments are given,
60
+ # they will be joined to the end of the libray path using
61
+ # <tt>File.join</tt>.
62
+ #
63
+ def libpath( *args )
64
+ args.empty? ? LIBPATH.to_s : File.join(LIBPATH.to_s, args.flatten)
65
+ end
66
+
67
+ # Returns the path for the module. If any arguments are given,
68
+ # they will be joined to the end of the path using
69
+ # <tt>File.join</tt>.
70
+ #
71
+ def path( *args )
72
+ args.empty? ? PATH.to_s : File.join(PATH.to_s, args.flatten)
73
+ end
74
+
75
+ def sublib_path( *args )
76
+ args.empty? ? PATH.to_s : File.join(LIBPATH.to_s, 'emissary', args.flatten)
77
+ end
78
+
79
+ def klass_from_handler(klass = nil, handler = nil, *args)
80
+ klass = if handler and handler.is_a? Class and not handler.nil?
81
+ raise ArgumentError, "must provide module or subclass of #{klass.name}" unless klass >= handler
82
+ handler
83
+ elsif handler.is_a? Module
84
+ resource_name = "RESOURCE_#{handler.to_s.upcase.split('::').pop}"
85
+ begin
86
+ klass.const_get(resource_name)
87
+ rescue NameError
88
+ klass.const_set(resource_name, Class.new(klass) { include handler } )
89
+ end
90
+ elsif klass.nil?
91
+ raise ArgumentError, "klass must be a valid class constant for #{name}#klass_from_handler"
92
+ elsif handler.nil?
93
+ raise ArgumentError, "handler must be a valid class or module"
94
+ else
95
+ klass
96
+ end
97
+
98
+ arity = klass.instance_method(:initialize).arity
99
+ expected = arity >= 0 ? arity : -(arity + 1)
100
+ if (arity >= 0 and args.size != expected) or (arity < 0 and args.size < expected)
101
+ raise ArgumentError, "wrong number of arguments for #{klass}#initialize (#{args.size} for #{expected})"
102
+ end
103
+
104
+ klass
105
+ end
106
+
107
+ def klass_loaded?(class_name)
108
+ begin
109
+ !!klass_const(class_name)
110
+ rescue NameError
111
+ false
112
+ end
113
+ end
114
+
115
+ def klass_const(class_name, autoload = false)
116
+ return class_name if class_name.is_a? Class or class_name.is_a? Module
117
+
118
+ klass = Object
119
+
120
+ class_name.split('::').each do |c|
121
+ begin
122
+ klass = klass.const_get(c.to_sym)
123
+ rescue NameError => e
124
+ if autoload
125
+ require_klass( (klass == Object ? c : "#{klass.to_s}::#{c}") )
126
+ redo
127
+ end
128
+ end
129
+ end
130
+
131
+ klass.to_s == class_name ? klass : nil
132
+ end
133
+
134
+ def load_klass(class_name)
135
+ load libpath(*class_name.downcase.split(/::/)) + '.rb'
136
+ end
137
+
138
+ def require_klass(class_name)
139
+ require libpath(*class_name.downcase.split(/::/))
140
+ end
141
+
142
+ def logger
143
+ Emissary::Logger.instance
144
+ end
145
+
146
+ def generate_uuid
147
+ UUID.generate
148
+ end
149
+
150
+ def identity
151
+ @@identity ||= Emissary::Identity.instance
152
+ end
153
+
154
+ # Sets up a line of communication
155
+ #
156
+ def call handler, config, *args
157
+ unless handler.is_a? Class or handler.is_a? Module
158
+ klass_name = 'Emissary::Operator::' + handler.to_s.upcase
159
+ begin
160
+ require_klass klass_name
161
+ rescue LoadError => e
162
+ begin
163
+ require_klass Emissary::EXTERNAL_OPERATORS + '::' + handler.to_s.upcase
164
+ #rescue LoadError
165
+ # raise the original exception if we still haven't found the file
166
+ # raise e
167
+ end
168
+ end
169
+ handler = klass_const klass_name
170
+ end
171
+
172
+ klass = klass_from_handler(Operator, handler, config)
173
+
174
+ operator = klass.new(config, *args)
175
+ operator.validate_config!
176
+ block_given? and yield operator
177
+ operator
178
+ end
179
+
180
+ # Dispatches a message to the agent specified by the message
181
+ #
182
+ def dispatch message, config, *args
183
+ unless message.is_a? Emissary::Message
184
+ raise ArgumentError, "message is not an Emissary::Message"
185
+ end
186
+
187
+ begin
188
+ agent_type = 'Emissary::Agent::' + message.agent.to_s.capitalize
189
+ begin
190
+ require_klass agent_type
191
+ rescue LoadError => e
192
+ begin
193
+ require_klass Emissary::EXTERNAL_AGENTS + '::' + message.agent.to_s.capitalize
194
+ rescue LoadError
195
+ # raise the original exception if we still haven't found the file
196
+ raise e
197
+ end
198
+ end
199
+ rescue Exception => e
200
+ Emissary.logger.error "Dispatcher Error: #{e.class.name}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
201
+ message = message.error(e)
202
+ agent_type = 'Emissary::Agent::Error'
203
+ end
204
+
205
+ handler = klass_const agent_type, true
206
+
207
+ klass = klass_from_handler(Agent, handler, message, config, *args)
208
+
209
+ Emissary.logger.debug " [--] Dispatching message to: #{agent_type}"
210
+ agent = klass.new(message, config, *args)
211
+ block_given? and yield agent
212
+ agent
213
+ end
214
+ end
215
+
216
+ # autoload core object extensions
217
+ Dir[sublib_path('core_ext', '*.rb')].each do |core_extension|
218
+ require core_extension
219
+ end
220
+ end # module Emissary
221
+
222
+ $:.unshift Emissary::LIBPATH.to_s
223
+
224
+ [ :errors, :logger, :operator, :agent, :identity, :message, :config, :gem_helper ].each do |sublib|
225
+ require Emissary.sublib_path sublib.to_s
226
+ end