torquebox-messaging 2.1.0-java → 2.1.1-java

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gem_hook.rb CHANGED
@@ -41,9 +41,11 @@ require 'torquebox/messaging/xa_connection_factory'
41
41
  require 'torquebox/messaging/xa_connection'
42
42
  require 'torquebox/messaging/xa_session'
43
43
 
44
+ require 'torquebox/messaging/processor_middleware/chain'
45
+ require 'torquebox/messaging/processor_middleware/with_transaction'
44
46
  require 'torquebox/messaging/message_processor'
45
47
  require 'torquebox/messaging/task'
46
48
  require 'torquebox/messaging/backgroundable'
47
- require 'torquebox/messaging/processor_wrapper'
48
49
 
49
- require 'torquebox/messaging/datamapper_marshaling.rb'
50
+
51
+ require 'torquebox/messaging/datamapper_marshaling'
Binary file
@@ -1,6 +1,6 @@
1
1
  module TorqueboxMessaging
2
- VERSION = '2.1.0'
3
- MAVEN_VERSION = '2.1.0'
2
+ VERSION = '2.1.1'
3
+ MAVEN_VERSION = '2.1.1'
4
4
  end
5
5
  begin
6
6
  require 'java'
@@ -14,7 +14,7 @@
14
14
  # License along with this software; if not, write to the Free
15
15
  # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
16
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
-
17
+
18
18
  require 'torquebox/messaging/queue'
19
19
  require 'torquebox/messaging/future'
20
20
  require 'torquebox/messaging/task'
@@ -27,6 +27,7 @@ module TorqueBox
27
27
  # Backgroundable provides mechanism for executing an object's
28
28
  # methods asynchronously.
29
29
  module Backgroundable
30
+ MUTEX = Mutex.new
30
31
 
31
32
  def self.included(base)
32
33
  base.extend(ClassMethods)
@@ -82,13 +83,20 @@ module TorqueBox
82
83
  end
83
84
 
84
85
  def __enable_backgroundable_newrelic_tracing(method)
86
+ method = method.to_s
85
87
  if Backgroundable.newrelic_available?
86
- include(NewRelic::Agent::Instrumentation::ControllerInstrumentation) unless
87
- include?(NewRelic::Agent::Instrumentation::ControllerInstrumentation)
88
- begin
89
- add_transaction_tracer(method, :name => method.sub("__sync_", ""), :category => :task)
90
- rescue Exception => e
91
- TorqueBox::Logger.new( Backgroundable ).error "Error loading New Relic for backgrounded method #{method.sub("__sync_", "")}: #{e}"
88
+ TorqueBox::Messaging::Backgroundable::MUTEX.synchronize do
89
+ @__enabled_bg_tracing_methods ||= {}
90
+ if !@__enabled_bg_tracing_methods[method]
91
+ include(NewRelic::Agent::Instrumentation::ControllerInstrumentation) unless
92
+ include?(NewRelic::Agent::Instrumentation::ControllerInstrumentation)
93
+ begin
94
+ add_transaction_tracer(method, :name => method.sub("__sync_", ""), :category => :task)
95
+ rescue Exception => e
96
+ TorqueBox::Logger.new( Backgroundable ).error "Error loading New Relic for backgrounded method #{method.sub("__sync_", "")}: #{e}"
97
+ end
98
+ @__enabled_bg_tracing_methods[method] = true
99
+ end
92
100
  end
93
101
  end
94
102
  end
@@ -42,6 +42,11 @@ module TorqueBox
42
42
  end
43
43
  end
44
44
 
45
+ # Do not begin a transaction before invoking a Backgroundable method
46
+ def middleware
47
+ super.remove(TorqueBox::Messaging::ProcessorMiddleware::WithTransaction)
48
+ end
49
+
45
50
  private
46
51
  def self.log
47
52
  @logger ||= TorqueBox::Logger.new( self )
@@ -75,10 +75,17 @@ module TorqueBox
75
75
  end
76
76
  end
77
77
 
78
- def receive(options = {})
78
+ def receive(options = {}, &block)
79
79
  wait_for_destination(options[:startup_timeout]) do
80
- with_session(options) do |session|
81
- session.receive self, options
80
+ func = lambda do
81
+ with_session(options) do |session|
82
+ session.receive self, options, &block
83
+ end
84
+ end
85
+ if block
86
+ TorqueBox.transaction &func
87
+ else
88
+ func.call
82
89
  end
83
90
  end
84
91
  end
@@ -0,0 +1,17 @@
1
+ # A message processor that echos any messages sent to it back to
2
+ # another queue specified by the response_queue configuration option
3
+ module Torquebox
4
+ module Messaging
5
+ class EchoProcessor < TorqueBox::Messaging::MessageProcessor
6
+
7
+ def initialize(options={})
8
+ @response_queue = TorqueBox::Messaging::Queue.new(options['response_queue'])
9
+ end
10
+
11
+ def on_message(body)
12
+ @response_queue.publish(body)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -15,10 +15,13 @@
15
15
  # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
16
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
17
 
18
+ require 'torquebox/messaging/processor_middleware/default_middleware'
19
+
18
20
  module TorqueBox
19
21
  module Messaging
20
22
  class MessageProcessor
21
-
23
+ include ProcessorMiddleware::DefaultMiddleware
24
+
22
25
  attr_accessor :message
23
26
 
24
27
  def initialize
@@ -0,0 +1,88 @@
1
+ # Copyright 2008-2012 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ module TorqueBox
19
+ module Messaging
20
+ module ProcessorMiddleware
21
+ class Chain
22
+
23
+ def prepend(klass, *args)
24
+ chain.unshift(MWare.new(klass, args)) unless locate(klass)
25
+ self
26
+ end
27
+
28
+ def append(klass, *args)
29
+ chain << MWare.new(klass, args) unless locate(klass)
30
+ self
31
+ end
32
+
33
+ alias_method :add, :append
34
+
35
+ def remove(klass)
36
+ loc = locate(klass)
37
+ chain.delete_at(loc) if loc
38
+ self
39
+ end
40
+
41
+ def inspect
42
+ chain.map(&:klass).inspect
43
+ end
44
+
45
+ def invoke(session, message, processor)
46
+ realized_chain = realize
47
+ walker = lambda do
48
+ mware = realized_chain.shift
49
+ if mware
50
+ mware.call(session, message, &walker)
51
+ else
52
+ processor.process!(message)
53
+ end
54
+ end
55
+ walker.call
56
+ end
57
+
58
+ protected
59
+
60
+ def chain
61
+ @chain ||= []
62
+ end
63
+
64
+ def locate(klass)
65
+ chain.index { |m| m.klass == klass }
66
+ end
67
+
68
+ def realize
69
+ chain.map(&:instance)
70
+ end
71
+ end
72
+
73
+ class MWare
74
+ attr_reader :klass
75
+
76
+ def initialize(klass, args)
77
+ @klass = klass
78
+ @args = args
79
+ end
80
+
81
+ def instance
82
+ @klass.new(*@args)
83
+ end
84
+ end
85
+
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,38 @@
1
+ # Copyright 2008-2012 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ require 'torquebox/messaging/processor_middleware/chain'
19
+ require 'torquebox/messaging/processor_middleware/with_transaction'
20
+
21
+ module TorqueBox
22
+ module Messaging
23
+ module ProcessorMiddleware
24
+ module DefaultMiddleware
25
+
26
+ def self.default
27
+ ProcessorMiddleware::Chain.new.append(WithTransaction)
28
+ end
29
+
30
+ def middleware
31
+ @middleware ||= DefaultMiddleware.default
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
38
+
@@ -19,18 +19,21 @@ require 'torquebox/transactions'
19
19
 
20
20
  module TorqueBox
21
21
  module Messaging
22
- class ProcessorWrapper
22
+ module ProcessorMiddleware
23
+ class WithTransaction
23
24
 
24
- def initialize(target, session, message)
25
- @target = target
26
- @session = session
27
- @message = message
28
- end
29
-
30
- def process!
31
- TorqueBox.transaction( @session ) do
32
- @target.process!( @message )
25
+ def call(session, message)
26
+ if session
27
+ begin
28
+ TorqueBox.transaction( session ) { yield }
29
+ rescue Exception => ex
30
+ $stderr.puts("Unable to process inbound message", ex)
31
+ end
32
+ else
33
+ yield
34
+ end
33
35
  end
36
+
34
37
  end
35
38
 
36
39
  end
@@ -72,7 +72,8 @@ module TorqueBox
72
72
  begin
73
73
  jms_message = consumer.receive( timeout )
74
74
  if jms_message
75
- decode ? Message.new( jms_message ).decode : jms_message
75
+ message = decode ? Message.new( jms_message ).decode : jms_message
76
+ block_given? ? yield(message) : message
76
77
  end
77
78
  ensure
78
79
  consumer.close unless consumer.nil?
@@ -19,12 +19,14 @@ require 'torquebox/messaging/queue'
19
19
  require 'torquebox/messaging/future_responder'
20
20
  require 'torquebox/messaging/future'
21
21
  require 'torquebox/messaging/future_status'
22
+ require 'torquebox/messaging/processor_middleware/default_middleware'
22
23
 
23
24
  module TorqueBox
24
25
  module Messaging
25
26
 
26
- class Task
27
+ class Task
27
28
  include FutureStatus
29
+ include ProcessorMiddleware::DefaultMiddleware
28
30
 
29
31
  def self.queue_name( name = self.name[0...-4] )
30
32
  suffix = org.torquebox.core.util.StringUtils.underscore(name)
@@ -0,0 +1,160 @@
1
+ require 'torquebox/messaging/processor_middleware/chain'
2
+
3
+ class MockMWare
4
+ def initialize(*args)
5
+ @log = args.first unless args.empty?
6
+ end
7
+
8
+ def call(session, message)
9
+ @log << self.class if @log
10
+ yield
11
+ end
12
+ end
13
+
14
+ class MockMWare2 < MockMWare; end
15
+
16
+
17
+ class TorqueBox::Messaging::ProcessorMiddleware::MWare
18
+ attr_reader :args
19
+ end
20
+
21
+ class TorqueBox::Messaging::ProcessorMiddleware::Chain
22
+ def get_chain
23
+ chain
24
+ end
25
+ end
26
+
27
+ describe TorqueBox::Messaging::ProcessorMiddleware::Chain do
28
+ before(:each) do
29
+ @chain = TorqueBox::Messaging::ProcessorMiddleware::Chain.new
30
+ end
31
+
32
+ describe "#prepend" do
33
+ it "should work when the chain is empty" do
34
+ @chain.prepend(MockMWare)
35
+ @chain.get_chain.first.klass.should == MockMWare
36
+ end
37
+
38
+ it "should work when the chain is not empty" do
39
+ @chain.prepend(MockMWare)
40
+ @chain.prepend(MockMWare2)
41
+ @chain.get_chain.first.klass.should == MockMWare2
42
+ end
43
+
44
+ it "should not add the same class twice" do
45
+ @chain.prepend(MockMWare)
46
+ @chain.prepend(MockMWare)
47
+ @chain.get_chain.first.klass.should == MockMWare
48
+ @chain.get_chain.length.should == 1
49
+ end
50
+
51
+ it "should work with args" do
52
+ @chain.prepend(MockMWare, :arg1, :arg2)
53
+ mware = @chain.get_chain.first
54
+ mware.args.should == [:arg1, :arg2]
55
+ end
56
+
57
+ it "should return the chain" do
58
+ @chain.prepend(MockMWare).should == @chain
59
+ end
60
+
61
+
62
+ end
63
+
64
+ describe "#append" do
65
+ it "should work when the chain is empty" do
66
+ @chain.append(MockMWare)
67
+ @chain.get_chain.first.klass.should == MockMWare
68
+ end
69
+
70
+ it "should work when the chain is not empty" do
71
+ @chain.append(MockMWare)
72
+ @chain.append(MockMWare2)
73
+ @chain.get_chain.last.klass.should == MockMWare2
74
+ end
75
+
76
+ it "should not add the same class twice" do
77
+ @chain.append(MockMWare)
78
+ @chain.append(MockMWare)
79
+ @chain.get_chain.first.klass.should == MockMWare
80
+ @chain.get_chain.length.should == 1
81
+ end
82
+
83
+ it "should return the chain" do
84
+ @chain.append(MockMWare).should == @chain
85
+ end
86
+
87
+ end
88
+
89
+ describe "#remove" do
90
+ it "should work" do
91
+ @chain.append(MockMWare)
92
+ @chain.remove(MockMWare)
93
+ @chain.get_chain.should be_empty
94
+ end
95
+
96
+ it "should not barf if the class isn't present" do
97
+ lambda do
98
+ @chain.remove(MockMWare)
99
+ end.should_not raise_error
100
+ end
101
+
102
+ it "should only remove the given class" do
103
+ @chain.append(MockMWare)
104
+ @chain.append(MockMWare2)
105
+ @chain.remove(MockMWare)
106
+ @chain.get_chain.first.klass.should == MockMWare2
107
+ @chain.get_chain.length.should == 1
108
+ end
109
+
110
+ it "should return the chain" do
111
+ @chain.remove(MockMWare).should == @chain
112
+ end
113
+
114
+ end
115
+
116
+ describe '#invoke' do
117
+ before(:each) do
118
+ @processor = mock('processor')
119
+ @log = []
120
+ @processor.stub(:process!) do
121
+ @log << :processor
122
+ end.with("message")
123
+ end
124
+
125
+ describe "when the chain is empty" do
126
+ it "should call the processor" do
127
+ @chain.invoke("session", "message", @processor)
128
+ end
129
+ end
130
+
131
+ describe "when the chain is not empty" do
132
+ it "should call the processor" do
133
+ @chain.append(MockMWare)
134
+ @chain.invoke("session", "message", @processor)
135
+ end
136
+
137
+ it "should call the chain first" do
138
+ @chain.append(MockMWare, @log)
139
+ @chain.invoke("session", "message", @processor)
140
+ @log.should == [MockMWare, :processor]
141
+ end
142
+
143
+ it "should call the chain in order" do
144
+ @chain.append(MockMWare, @log)
145
+ @chain.append(MockMWare2, @log)
146
+ @chain.invoke("session", "message", @processor)
147
+ @log.should == [MockMWare, MockMWare2, :processor]
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "#inspect" do
153
+ it "should work" do
154
+ @chain.append(MockMWare)
155
+ @chain.inspect.should == "[MockMWare]"
156
+ end
157
+ end
158
+
159
+ end
160
+
@@ -0,0 +1,21 @@
1
+ require 'torquebox/messaging/processor_middleware/default_middleware'
2
+
3
+ class Thing
4
+ include TorqueBox::Messaging::ProcessorMiddleware::DefaultMiddleware
5
+ end
6
+
7
+
8
+ describe TorqueBox::Messaging::ProcessorMiddleware::DefaultMiddleware do
9
+
10
+ before(:each) do
11
+ @thing = Thing.new
12
+ end
13
+
14
+ describe "#middleware" do
15
+ it "should return the default middleware" do
16
+ @thing.middleware.inspect.should == "[TorqueBox::Messaging::ProcessorMiddleware::WithTransaction]"
17
+ end
18
+ end
19
+
20
+
21
+ end
@@ -51,4 +51,11 @@ describe TorqueBox::Messaging::MessageProcessor do
51
51
  @processor.body.should eql(payload)
52
52
  end
53
53
 
54
+ describe "#middleware" do
55
+ it "should return the default middleware" do
56
+ @processor.middleware.inspect.should == "[TorqueBox::Messaging::ProcessorMiddleware::WithTransaction]"
57
+ end
58
+ end
59
+
60
+
54
61
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: torquebox-messaging
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.1.0
5
+ version: 2.1.1
6
6
  platform: java
7
7
  authors:
8
8
  - The TorqueBox Team
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-07-26 00:00:00 Z
13
+ date: 2012-08-27 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: torquebox-core
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 2.1.0
23
+ version: 2.1.1
24
24
  type: :runtime
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - "="
33
33
  - !ruby/object:Gem::Version
34
- version: 2.1.0
34
+ version: 2.1.1
35
35
  type: :runtime
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
@@ -85,45 +85,50 @@ files:
85
85
  - lib/hornetq-core-2.2.18.Final.jar
86
86
  - lib/hornetq-jms-2.2.18.Final.jar
87
87
  - lib/netty-3.2.6.Final.jar
88
- - lib/gem_hook.rb
89
88
  - lib/org.torquebox.messaging-client.rb
89
+ - lib/gem_hook.rb
90
90
  - lib/torquebox/messaging.rb
91
- - lib/torquebox/messaging/clojure_message.rb
92
- - lib/torquebox/messaging/connection.rb
93
- - lib/torquebox/messaging/processor_wrapper.rb
94
- - lib/torquebox/messaging/destination.rb
95
- - lib/torquebox/messaging/session.rb
96
- - lib/torquebox/messaging/connection_factory.rb
91
+ - lib/torquebox/messaging/marshal_message.rb
97
92
  - lib/torquebox/messaging/core.rb
98
93
  - lib/torquebox/messaging/xa_session.rb
99
- - lib/torquebox/messaging/message_processor.rb
100
- - lib/torquebox/messaging/marshal_message.rb
101
- - lib/torquebox/messaging/future.rb
102
- - lib/torquebox/messaging/topic.rb
94
+ - lib/torquebox/messaging/connection.rb
95
+ - lib/torquebox/messaging/future_responder.rb
103
96
  - lib/torquebox/messaging/backgroundable_processor.rb
104
- - lib/torquebox/messaging/queue.rb
97
+ - lib/torquebox/messaging/message_processor.rb
98
+ - lib/torquebox/messaging/future_status.rb
99
+ - lib/torquebox/messaging/connection_factory.rb
105
100
  - lib/torquebox/messaging/xa_connection_factory.rb
106
- - lib/torquebox/messaging/future_responder.rb
107
- - lib/torquebox/messaging/text_message.rb
108
101
  - lib/torquebox/messaging/message.rb
109
- - lib/torquebox/messaging/task.rb
110
- - lib/torquebox/messaging/json_message.rb
102
+ - lib/torquebox/messaging/datamapper_marshaling.rb
103
+ - lib/torquebox/messaging/topic.rb
104
+ - lib/torquebox/messaging/marshal_base64_message.rb
105
+ - lib/torquebox/messaging/text_message.rb
111
106
  - lib/torquebox/messaging/backgroundable.rb
107
+ - lib/torquebox/messaging/json_message.rb
108
+ - lib/torquebox/messaging/destination.rb
109
+ - lib/torquebox/messaging/echo_processor.rb
110
+ - lib/torquebox/messaging/future.rb
111
+ - lib/torquebox/messaging/clojure_message.rb
112
+ - lib/torquebox/messaging/task.rb
113
+ - lib/torquebox/messaging/session.rb
114
+ - lib/torquebox/messaging/queue.rb
112
115
  - lib/torquebox/messaging/const_missing.rb
113
- - lib/torquebox/messaging/datamapper_marshaling.rb
114
- - lib/torquebox/messaging/future_status.rb
115
116
  - lib/torquebox/messaging/xa_connection.rb
116
- - lib/torquebox/messaging/marshal_base64_message.rb
117
+ - lib/torquebox/messaging/processor_middleware/chain.rb
118
+ - lib/torquebox/messaging/processor_middleware/default_middleware.rb
119
+ - lib/torquebox/messaging/processor_middleware/with_transaction.rb
117
120
  - lib/torquebox/messaging/ext/javax_jms_queue_browser.rb
118
- - spec/task_spec.rb
119
- - spec/datamapper_marshaling_spec.rb
120
- - spec/future_spec.rb
121
- - spec/json_message_spec.rb
122
- - spec/message_processor_spec.rb
123
- - spec/future_responder_spec.rb
124
121
  - spec/backgroundable_spec.rb
122
+ - spec/future_responder_spec.rb
123
+ - spec/default_middleware_spec.rb
124
+ - spec/message_processor_spec.rb
125
+ - spec/chain_spec.rb
126
+ - spec/future_spec.rb
125
127
  - spec/message_spec.rb
126
128
  - spec/destination_spec.rb
129
+ - spec/datamapper_marshaling_spec.rb
130
+ - spec/task_spec.rb
131
+ - spec/json_message_spec.rb
127
132
  homepage: http://torquebox.org/
128
133
  licenses:
129
134
  - lgpl
@@ -152,12 +157,14 @@ signing_key:
152
157
  specification_version: 3
153
158
  summary: TorqueBox Messaging Client
154
159
  test_files:
155
- - spec/task_spec.rb
156
- - spec/datamapper_marshaling_spec.rb
157
- - spec/future_spec.rb
158
- - spec/json_message_spec.rb
159
- - spec/message_processor_spec.rb
160
- - spec/future_responder_spec.rb
161
160
  - spec/backgroundable_spec.rb
161
+ - spec/future_responder_spec.rb
162
+ - spec/default_middleware_spec.rb
163
+ - spec/message_processor_spec.rb
164
+ - spec/chain_spec.rb
165
+ - spec/future_spec.rb
162
166
  - spec/message_spec.rb
163
167
  - spec/destination_spec.rb
168
+ - spec/datamapper_marshaling_spec.rb
169
+ - spec/task_spec.rb
170
+ - spec/json_message_spec.rb