modern_times 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -3
- data/VERSION +1 -1
- data/lib/modern_times/jms/worker.rb +23 -21
- data/lib/modern_times/jms_requestor/request_handle.rb +12 -7
- data/lib/modern_times/jms_requestor/requestor.rb +10 -5
- data/lib/modern_times/jms_requestor/worker.rb +18 -1
- data/lib/modern_times/railsable.rb +3 -1
- data/test/jms_test.rb +1 -0
- metadata +11 -19
data/README.rdoc
CHANGED
@@ -10,13 +10,11 @@ Very much alpha stage at this point.
|
|
10
10
|
|
11
11
|
== Features/Problems:
|
12
12
|
|
13
|
-
*
|
14
|
-
* jms_test doesn't exit
|
13
|
+
* jms_test issues (doesn't exit, doesn't work when doing more than 1 type of marshaling)
|
15
14
|
* jms_requestor needs testing for dummy requesting
|
16
15
|
* Allow options (durable queues, etc)
|
17
16
|
* Railsable needs testing
|
18
17
|
* Fail options (fail queues, etc.)
|
19
|
-
* Return exception for jms_requestor
|
20
18
|
* Currently tested only for ActiveMQ
|
21
19
|
|
22
20
|
== Install:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
@@ -96,29 +96,10 @@ module ModernTimes
|
|
96
96
|
return options
|
97
97
|
end
|
98
98
|
|
99
|
-
def on_message(message)
|
100
|
-
@message = message
|
101
|
-
object = self.class.marshaler.unmarshal(message.data)
|
102
|
-
ModernTimes.logger.debug "#{self}: Received Object: #{object}" if ModernTimes.logger.debug?
|
103
|
-
perform(object)
|
104
|
-
ModernTimes.logger.debug "#{self}: Finished processing message" if ModernTimes.logger.debug?
|
105
|
-
ModernTimes.logger.flush if ModernTimes.logger.respond_to?(:flush)
|
106
|
-
rescue Exception => e
|
107
|
-
ModernTimes.logger.error "#{self}: Messaging Exception: #{e.inspect}\n#{e.backtrace.inspect}"
|
108
|
-
rescue java.lang.Exception => e
|
109
|
-
ModernTimes.logger.error "#{self}: Java Messaging Exception: #{e.inspect}\n#{e.backtrace.inspect}"
|
110
|
-
end
|
111
|
-
|
112
|
-
def perform(object)
|
113
|
-
raise "#{self}: Need to override perform method in #{self.class.name} in order to act on #{object}"
|
114
|
-
end
|
115
|
-
|
116
|
-
def to_s
|
117
|
-
"#{real_destination_options.to_a.join('=>')}:#{index}"
|
118
|
-
end
|
119
|
-
|
120
99
|
# Start the event loop for handling messages off the queue
|
121
100
|
def start
|
101
|
+
# Grab this to prevent lookup with every message
|
102
|
+
@message_marshaler = self.class.marshaler
|
122
103
|
@session = Connection.create_consumer_session
|
123
104
|
@consumer = @session.consumer(real_destination_options)
|
124
105
|
@session.start
|
@@ -154,6 +135,27 @@ module ModernTimes
|
|
154
135
|
@session.close if @session
|
155
136
|
end
|
156
137
|
|
138
|
+
def on_message(message)
|
139
|
+
@message = message
|
140
|
+
object = @message_marshaler.unmarshal(message.data)
|
141
|
+
ModernTimes.logger.debug "#{self}: Received Object: #{object}" if ModernTimes.logger.debug?
|
142
|
+
perform(object)
|
143
|
+
ModernTimes.logger.debug "#{self}: Finished processing message" if ModernTimes.logger.debug?
|
144
|
+
ModernTimes.logger.flush if ModernTimes.logger.respond_to?(:flush)
|
145
|
+
rescue Exception => e
|
146
|
+
ModernTimes.logger.error "#{self}: Messaging Exception: #{e.inspect}\n#{e.backtrace.inspect}"
|
147
|
+
rescue java.lang.Exception => e
|
148
|
+
ModernTimes.logger.error "#{self}: Java Messaging Exception: #{e.inspect}\n#{e.backtrace.inspect}"
|
149
|
+
end
|
150
|
+
|
151
|
+
def perform(object)
|
152
|
+
raise "#{self}: Need to override perform method in #{self.class.name} in order to act on #{object}"
|
153
|
+
end
|
154
|
+
|
155
|
+
def to_s
|
156
|
+
"#{real_destination_options.to_a.join('=>')}:#{index}"
|
157
|
+
end
|
158
|
+
|
157
159
|
#########
|
158
160
|
protected
|
159
161
|
#########
|
@@ -4,12 +4,13 @@ require 'yaml'
|
|
4
4
|
module ModernTimes
|
5
5
|
module JMSRequestor
|
6
6
|
class RequestHandle
|
7
|
-
def initialize(requestor, message, start, timeout)
|
8
|
-
@requestor
|
9
|
-
@reply_queue
|
10
|
-
@message
|
11
|
-
@start
|
12
|
-
@timeout
|
7
|
+
def initialize(requestor, message, start, timeout, &reconstruct_block)
|
8
|
+
@requestor = requestor
|
9
|
+
@reply_queue = requestor.reply_queue
|
10
|
+
@message = message
|
11
|
+
@start = start
|
12
|
+
@timeout = timeout
|
13
|
+
@reconstruct_block = reconstruct_block
|
13
14
|
end
|
14
15
|
|
15
16
|
def read_response
|
@@ -30,7 +31,11 @@ module ModernTimes
|
|
30
31
|
if error_yaml = response['Exception']
|
31
32
|
raise ModernTimes::RemoteException.from_hash(YAML.load(error_yaml))
|
32
33
|
end
|
33
|
-
|
34
|
+
response = @requestor.marshaler.unmarshal(response.data)
|
35
|
+
if @reconstruct_block
|
36
|
+
response = @reconstruct_block.call(response)
|
37
|
+
end
|
38
|
+
return response
|
34
39
|
end
|
35
40
|
end
|
36
41
|
end
|
@@ -14,26 +14,31 @@ module ModernTimes
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def request(object, timeout)
|
17
|
+
def request(object, timeout, &reconstruct_block)
|
18
18
|
start = Time.now
|
19
19
|
message = publish(object, :jms_reply_to => @reply_queue)
|
20
|
-
return RequestHandle.new(self, message, start, timeout)
|
20
|
+
return RequestHandle.new(self, message, start, timeout, &reconstruct_block)
|
21
21
|
end
|
22
22
|
|
23
23
|
# For non-configured Rails projects, The above request method will be overridden to
|
24
24
|
# call this request method instead which calls all the JMS workers that
|
25
25
|
# operate on the given address.
|
26
|
-
def dummy_request(object, timeout)
|
26
|
+
def dummy_request(object, timeout, &reconstruct_block)
|
27
27
|
@@worker_instances.each do |worker|
|
28
|
-
if worker.kind_of?(Worker) && ModernTimes::JMS.same_destination?(producer_options, worker.destination_options)
|
28
|
+
if worker.kind_of?(Worker) && ModernTimes::JMS.same_destination?(producer_options, worker.class.destination_options)
|
29
29
|
ModernTimes.logger.debug "Dummy requesting #{object} to #{worker}"
|
30
|
-
|
30
|
+
response = worker.request(object)
|
31
|
+
if reconstruct_block
|
32
|
+
response = reconstruct_block.call(response)
|
33
|
+
end
|
34
|
+
return OpenStruct.new(:read_response => response)
|
31
35
|
end
|
32
36
|
end
|
33
37
|
raise "No worker to handle #{address} request of #{object}"
|
34
38
|
end
|
35
39
|
|
36
40
|
def self.setup_dummy_requesting(workers)
|
41
|
+
require 'ostruct'
|
37
42
|
@@dummy_requesting = true
|
38
43
|
@@worker_instances = workers.map {|worker| worker.new}
|
39
44
|
alias_method :real_request, :request
|
@@ -10,6 +10,18 @@ module ModernTimes
|
|
10
10
|
def create_supervisor(manager, worker_options)
|
11
11
|
Supervisor.new(manager, self, {}, worker_options)
|
12
12
|
end
|
13
|
+
|
14
|
+
def request_marshal(option)
|
15
|
+
marshal(option)
|
16
|
+
end
|
17
|
+
|
18
|
+
def response_marshal(option)
|
19
|
+
@response_marshaler = ModernTimes::MarshalStrategy.find(option)
|
20
|
+
end
|
21
|
+
|
22
|
+
def response_marshaler
|
23
|
+
@response_marshaler || marshaler
|
24
|
+
end
|
13
25
|
end
|
14
26
|
|
15
27
|
def self.included(base)
|
@@ -29,12 +41,17 @@ module ModernTimes
|
|
29
41
|
@total_time = 0.0
|
30
42
|
end
|
31
43
|
|
44
|
+
def start
|
45
|
+
@reply_marshaler = self.class.response_marshaler
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
32
49
|
def perform(object)
|
33
50
|
start_time = Time.now
|
34
51
|
response = request(object)
|
35
52
|
response_time = Time.now - start_time
|
36
53
|
session.producer(:destination => message.reply_to) do |producer|
|
37
|
-
reply_message = ModernTimes::JMS.create_message(session,
|
54
|
+
reply_message = ModernTimes::JMS.create_message(session, @reply_marshaler, response)
|
38
55
|
reply_message.jms_correlation_id = message.jms_message_id
|
39
56
|
producer.send(reply_message)
|
40
57
|
end
|
@@ -4,7 +4,9 @@ require 'erb'
|
|
4
4
|
module ModernTimes
|
5
5
|
module Railsable
|
6
6
|
def init_rails
|
7
|
-
|
7
|
+
# Allow user to use JMS w/o modifying jms.yml which could be checked in and hose other users
|
8
|
+
env = ENV['MODERN_TIMES_JMS_ENV'] || Rails.env
|
9
|
+
if @cfg = YAML.load(ERB.new(File.read(File.join(Rails.root, "config", "jms.yml"))).result(binding))[env]
|
8
10
|
ModernTimes.logger.info "Messaging Enabled"
|
9
11
|
ModernTimes::JMS::Connection.init(@cfg)
|
10
12
|
@is_jms_enabled = true
|
data/test/jms_test.rb
CHANGED
@@ -203,6 +203,7 @@ class JMSTest < Test::Unit::TestCase
|
|
203
203
|
end
|
204
204
|
|
205
205
|
[BSONTest, JSONTest, RubyTest, StringTest].each do |marshal_module|
|
206
|
+
#[RubyTest].each do |marshal_module|
|
206
207
|
#[BSONTest, JSONTest, StringTest].each do |marshal_module|
|
207
208
|
marshal_module.name =~ /(.*)Test/
|
208
209
|
marshal_type = $1
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modern_times
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 4
|
9
|
-
version: 0.2.4
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.5
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Brad Pardee
|
@@ -15,20 +11,17 @@ autorequire:
|
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
13
|
|
18
|
-
date: 2011-
|
14
|
+
date: 2011-05-02 00:00:00 -04:00
|
19
15
|
default_executable:
|
20
16
|
dependencies:
|
21
17
|
- !ruby/object:Gem::Dependency
|
22
18
|
name: jruby-jms
|
23
19
|
prerelease: false
|
24
20
|
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
none: false
|
25
22
|
requirements:
|
26
23
|
- - ">="
|
27
24
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
- 11
|
31
|
-
- 0
|
32
25
|
version: 0.11.0
|
33
26
|
type: :runtime
|
34
27
|
version_requirements: *id001
|
@@ -36,12 +29,10 @@ dependencies:
|
|
36
29
|
name: jmx
|
37
30
|
prerelease: false
|
38
31
|
requirement: &id002 !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
39
33
|
requirements:
|
40
34
|
- - ">="
|
41
35
|
- !ruby/object:Gem::Version
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
- 6
|
45
36
|
version: "0.6"
|
46
37
|
type: :runtime
|
47
38
|
version_requirements: *id002
|
@@ -107,6 +98,9 @@ files:
|
|
107
98
|
- test/jms_requestor_test.rb
|
108
99
|
- test/jms_test.rb
|
109
100
|
- test/marshal_strategy_test.rb
|
101
|
+
- examples/exception_test/bar_worker.rb
|
102
|
+
- examples/exception_test/base_worker.rb
|
103
|
+
- examples/exception_test/manager.rb
|
110
104
|
has_rdoc: true
|
111
105
|
homepage: http://github.com/ClarityServices/modern_times
|
112
106
|
licenses: []
|
@@ -117,23 +111,21 @@ rdoc_options: []
|
|
117
111
|
require_paths:
|
118
112
|
- lib
|
119
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
120
115
|
requirements:
|
121
116
|
- - ">="
|
122
117
|
- !ruby/object:Gem::Version
|
123
|
-
segments:
|
124
|
-
- 0
|
125
118
|
version: "0"
|
126
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
127
121
|
requirements:
|
128
122
|
- - ">="
|
129
123
|
- !ruby/object:Gem::Version
|
130
|
-
segments:
|
131
|
-
- 0
|
132
124
|
version: "0"
|
133
125
|
requirements: []
|
134
126
|
|
135
127
|
rubyforge_project:
|
136
|
-
rubygems_version: 1.
|
128
|
+
rubygems_version: 1.5.1
|
137
129
|
signing_key:
|
138
130
|
specification_version: 3
|
139
131
|
summary: Asynchronous task library
|