torquebox-messaging 1.1.1-java → 2.0.0.beta1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/lib/gem_hook.rb +26 -3
  2. data/lib/torquebox-messaging.jar +0 -0
  3. data/lib/torquebox-messaging.rb +2 -32
  4. data/lib/torquebox/messaging.rb +16 -0
  5. data/lib/torquebox/messaging/backgroundable.rb +32 -15
  6. data/lib/torquebox/messaging/backgroundable_processor.rb +32 -0
  7. data/lib/torquebox/messaging/connection.rb +127 -0
  8. data/lib/torquebox/messaging/connection_factory.rb +70 -0
  9. data/lib/torquebox/messaging/const_missing.rb +28 -0
  10. data/lib/torquebox/messaging/core.rb +27 -0
  11. data/lib/torquebox/messaging/destination.rb +68 -111
  12. data/lib/torquebox/messaging/ext/javax_jms_queue_browser.rb +1 -3
  13. data/lib/torquebox/messaging/future_responder.rb +10 -7
  14. data/lib/torquebox/messaging/json_message.rb +50 -0
  15. data/lib/torquebox/messaging/marshal_base64_message.rb +44 -0
  16. data/lib/torquebox/messaging/marshal_message.rb +43 -0
  17. data/lib/torquebox/messaging/message.rb +123 -0
  18. data/lib/torquebox/messaging/message_processor.rb +47 -0
  19. data/lib/torquebox/messaging/processor_wrapper.rb +38 -0
  20. data/lib/torquebox/messaging/queue.rb +61 -0
  21. data/lib/torquebox/messaging/session.rb +168 -0
  22. data/lib/torquebox/messaging/task.rb +7 -6
  23. data/lib/torquebox/messaging/text_message.rb +36 -0
  24. data/lib/torquebox/messaging/topic.rb +54 -0
  25. data/lib/torquebox/messaging/xa_connection.rb +58 -0
  26. data/lib/torquebox/messaging/xa_connection_factory.rb +59 -0
  27. data/lib/torquebox/messaging/xa_session.rb +30 -0
  28. data/licenses/lgpl-2.1.txt +7 -9
  29. data/spec/backgroundable_spec.rb +17 -24
  30. data/spec/destination_spec.rb +31 -318
  31. data/spec/future_responder_spec.rb +1 -1
  32. data/spec/json_message_spec.rb +50 -0
  33. data/spec/message_processor_spec.rb +54 -0
  34. data/spec/message_spec.rb +114 -0
  35. data/spec/task_spec.rb +11 -5
  36. metadata +38 -77
  37. data/lib/acl-spi-3.0.0.CR2.jar +0 -0
  38. data/lib/activation-1.1.jar +0 -0
  39. data/lib/authorization-spi-3.0.0.CR2.jar +0 -0
  40. data/lib/dtdparser-1.21.jar +0 -0
  41. data/lib/hornetq-core-2.1.2.Final.jar +0 -0
  42. data/lib/hornetq-jms-client-2.1.2.Final.jar +0 -0
  43. data/lib/hornetq-logging-2.1.2.Final.jar +0 -0
  44. data/lib/identity-spi-3.0.0.CR2.jar +0 -0
  45. data/lib/jaxb-api-2.1.9.jar +0 -0
  46. data/lib/jboss-common-core-2.2.17.GA.jar +0 -0
  47. data/lib/jboss-jms-api_1.1_spec-1.0.0.Final.jar +0 -0
  48. data/lib/jboss-logging-3.0.0.Beta4.jar +0 -0
  49. data/lib/jboss-reflect-2.2.0.GA.jar +0 -0
  50. data/lib/jbosssx-bare-3.0.0.CR2.jar +0 -0
  51. data/lib/jbossxacml-2.0.5.CR1.jar +0 -0
  52. data/lib/jbossxb-2.0.3.GA.jar +0 -0
  53. data/lib/jnp-client-5.0.5.Final.jar +0 -0
  54. data/lib/jruby-complete-1.6.3.jar +0 -0
  55. data/lib/netty-3.2.1.Final.jar +0 -0
  56. data/lib/picketbox-acl-impl-3.0.0.CR2.jar +0 -0
  57. data/lib/picketbox-bare-3.0.0.CR2.jar +0 -0
  58. data/lib/picketbox-identity-impl-3.0.0.CR2.jar +0 -0
  59. data/lib/picketbox-spi-bare-3.0.0.CR2.jar +0 -0
  60. data/lib/torquebox-base-core.jar +0 -0
  61. data/lib/torquebox-base-metadata.jar +0 -0
  62. data/lib/torquebox-base-spi.jar +0 -0
  63. data/lib/torquebox-mc-support.jar +0 -0
  64. data/lib/torquebox-messaging-core.jar +0 -0
  65. data/lib/torquebox/messaging/client.rb +0 -75
  66. data/lib/torquebox/messaging/ext/javax_jms_session.rb +0 -153
  67. data/lib/xercesImpl-2.9.1.jar +0 -0
  68. data/lib/xml-apis-1.3.04.jar +0 -0
  69. data/spec/client_spec.rb +0 -116
  70. data/spec/dispatcher-queues.yml +0 -4
  71. data/spec/dispatcher_not_running.rb +0 -54
  72. data/spec/ext/java_jmx_session_spec.rb +0 -71
  73. data/spec/queues.yml +0 -6
@@ -0,0 +1,27 @@
1
+ # Copyright 2008-2011 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/core/connection_factory'
19
+ require 'torquebox/messaging/core/connection'
20
+ require 'torquebox/messaging/core/session'
21
+ require 'torquebox/messaging/core/message'
22
+ require 'torquebox/messaging/core/destination'
23
+ require 'torquebox/messaging/core/queue'
24
+ require 'torquebox/messaging/core/topic'
25
+ require 'torquebox/messaging/core/live_destination'
26
+ require 'torquebox/messaging/core/live_queue'
27
+ require 'torquebox/messaging/core/live_topic'
@@ -1,90 +1,80 @@
1
1
  # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
- #
2
+ #
3
3
  # This is free software; you can redistribute it and/or modify it
4
4
  # under the terms of the GNU Lesser General Public License as
5
5
  # published by the Free Software Foundation; either version 2.1 of
6
6
  # the License, or (at your option) any later version.
7
- #
7
+ #
8
8
  # This software is distributed in the hope that it will be useful,
9
9
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
11
  # Lesser General Public License for more details.
12
- #
12
+ #
13
13
  # You should have received a copy of the GNU Lesser General Public
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
- require 'torquebox/kernel'
19
- require 'torquebox/messaging/client'
20
-
18
+ require 'torquebox/injectors'
19
+ require 'torquebox/messaging/session'
20
+ require 'torquebox/messaging/connection_factory'
21
21
  require 'torquebox/messaging/ext/javax_jms_queue_browser'
22
22
 
23
23
  module TorqueBox
24
24
  module Messaging
25
-
26
- module Destination
25
+ class Destination
26
+ include TorqueBox::Injectors
27
27
  include Enumerable
28
-
29
- attr_reader :name
30
- attr_reader :connect_options
31
- attr_reader :enumerable_options
32
28
 
29
+ attr_reader :connection_factory
30
+ attr_reader :name
31
+ attr_accessor :enumerable_options
32
+ attr_accessor :connect_options
33
+
33
34
  PRIORITY_MAP = {
34
- :low => 1,
35
- :normal => 4,
36
- :high => 7,
37
- :critical => 9
35
+ :low => 1,
36
+ :normal => 4,
37
+ :high => 7,
38
+ :critical => 9
38
39
  }
39
40
 
40
- def initialize(name, connect_options=nil, enumerable_options=nil)
41
- @name = name
42
- @connect_options = connect_options || {}
43
- @enumerable_options = enumerable_options || {}
41
+ def _dump(depth)
42
+ return self.name.queue_name if self.name.respond_to?( :queue_name )
43
+ self.name.to_s
44
44
  end
45
45
 
46
- def publish(message, options = {})
47
- wait_for_destination(options[:startup_timeout]) {
48
- Client.connect(@connect_options) do |session|
49
- session.publish name, message, normalize_options(options)
50
- session.commit if session.transacted?
51
- end
52
- }
46
+ def self._load(str)
47
+ self.new( str )
53
48
  end
54
49
 
55
- def receive(options={})
56
- result = nil
57
- wait_for_destination(options[:startup_timeout]) {
58
- Client.connect(@connect_options) do |session|
59
- result = session.receive( name, options )
60
- session.commit if session.transacted?
61
- end
62
- }
63
- result
50
+ def initialize(destination, connection_factory = __inject__( 'connection-factory' ))
51
+ @name = destination
52
+ @connection_factory = ConnectionFactory.new( connection_factory )
53
+ @connect_options = {}
54
+ @enumerable_options = {}
64
55
  end
65
56
 
66
- def start
67
- TorqueBox::Kernel.lookup("JMSServerManager") do |server|
68
- destination.name = name
69
- destination.server = server
70
- destination.create
57
+ def publish(message, options = {})
58
+ wait_for_destination(options[:startup_timeout]) do
59
+ with_session(options) do |session|
60
+ session.publish self, message, normalize_options(options)
61
+ end
71
62
  end
72
63
  end
73
- alias_method :create, :start
74
64
 
75
- def destroy
76
- TorqueBox::Kernel.lookup("JMSServerManager") do |server|
77
- destination.name = name
78
- destination.server = server
79
- destination.destroy
65
+ def receive(options = {})
66
+ wait_for_destination(options[:startup_timeout]) do
67
+ with_session(options) do |session|
68
+ session.receive self, options
69
+ end
80
70
  end
81
71
  end
82
72
 
83
73
  def each(&block)
84
74
  wait_for_destination do
85
- Client.connect(@connect_options) do |session|
86
- destination = session.lookup_destination( name )
87
- browser = session.create_browser( destination, @enumerable_options[:selector] )
75
+ with_session do |session|
76
+ destination = session.java_destination( self )
77
+ browser = session.create_browser( destination, enumerable_options[:selector] )
88
78
  begin
89
79
  browser.each(&block)
90
80
  ensure
@@ -94,92 +84,59 @@ module TorqueBox
94
84
  end
95
85
  end
96
86
 
97
- def to_s
98
- name
99
- end
100
-
101
- protected
102
-
103
- def normalize_options(options)
104
- if options.has_key?(:persistent)
105
- options[:delivery_mode] =
106
- options.delete(:persistent) ? javax.jms::DeliveryMode.PERSISTENT : javax.jms::DeliveryMode.NON_PERSISTENT
107
- end
108
-
109
- if options.has_key?(:priority)
110
- if PRIORITY_MAP[options[:priority]]
111
- options[:priority] = PRIORITY_MAP[options[:priority]]
112
- elsif (0..9) === options[:priority].to_i
113
- options[:priority] = options[:priority].to_i
114
- else
115
- raise ArgumentError.new(":priority must in the range 0..9, or one of #{PRIORITY_MAP.keys.collect {|k| ":#{k}"}.join(',')}")
87
+ def with_session(opts = {})
88
+ transactional = opts.fetch(:tx, true)
89
+ connection_factory.with_new_connection( connect_options[:client_id] ) do |connection|
90
+ connection.with_session(transactional) do |session|
91
+ yield session
116
92
  end
117
93
  end
118
-
119
- options
120
94
  end
121
95
 
122
96
  def wait_for_destination(timeout=nil, &block)
123
- timeout ||= 30000 # 30s default
97
+ timeout ||= 30_000 # 30s default
124
98
  start = Time.now
125
99
  begin
126
100
  block.call
127
- rescue javax.naming.NameNotFoundException => ex
101
+ rescue javax.naming.NameNotFoundException, javax.jms.JMSException
128
102
  elapsed = (Time.now - start) * 1000
129
103
  if elapsed > timeout
130
- raise ex
104
+ raise
131
105
  else
132
106
  sleep(0.1)
133
107
  retry
134
108
  end
135
109
  end
136
110
  end
137
- end
138
111
 
139
- class Queue
140
- include Destination
141
- def destination
142
- @destination ||= Java::org.torquebox.messaging.core::ManagedQueue.new
143
- end
112
+ def normalize_options(options)
113
+ if options.has_key?(:persistent)
114
+ options[:delivery_mode] =
115
+ options.delete(:persistent) ? javax.jms::DeliveryMode.PERSISTENT : javax.jms::DeliveryMode.NON_PERSISTENT
116
+ end
144
117
 
145
- def publish_and_receive(message, options={})
146
- result = nil
147
- wait_for_destination(options[:startup_timeout]) {
148
- Client.connect(@connect_options) do |session|
149
- result = session.publish_and_receive(name, message,
150
- normalize_options(options))
151
- session.commit if session.transacted?
118
+ if options.has_key?(:priority)
119
+ if PRIORITY_MAP[options[:priority]]
120
+ options[:priority] = PRIORITY_MAP[options[:priority]]
121
+ elsif (0..9) === options[:priority].to_i
122
+ options[:priority] = options[:priority].to_i
123
+ else
124
+ raise ArgumentError.new(":priority must in the range 0..9, or one of #{PRIORITY_MAP.keys.collect {|k| ":#{k}"}.join(',')}")
152
125
  end
153
- }
154
- result
155
- end
126
+ end
156
127
 
157
- def receive_and_publish(options={}, &block)
158
- wait_for_destination(options[:startup_timeout]) {
159
- Client.connect(@connect_options) do |session|
160
- session.receive_and_publish(name, normalize_options(options), &block)
161
- session.commit if session.transacted?
162
- end
163
- }
128
+ options
164
129
  end
165
- end
166
130
 
167
- class Topic
168
- include Destination
169
- DEFAULT_SUBSCRIBER_NAME = 'subscriber-1'
131
+ def enumerable_options
132
+ @enumerable_options ||= { }
133
+ @enumerable_options
134
+ end
170
135
 
171
- def destination
172
- @destination ||= Java::org.torquebox.messaging.core::ManagedTopic.new
136
+ def to_s
137
+ name
173
138
  end
174
139
 
175
- def unsubscribe(name = DEFAULT_SUBSCRIBER_NAME, options = {})
176
- wait_for_destination(options[:startup_timeout]) {
177
- Client.connect(@connect_options) do |session|
178
- session.unsubscribe(name)
179
- end
180
- }
181
- end
182
140
  end
183
-
184
141
  end
185
142
  end
@@ -15,13 +15,11 @@
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
-
19
-
20
18
  module javax.jms::QueueBrowser
21
19
  include Enumerable
22
20
 
23
21
  def each(&block)
24
- enumeration.each(&block)
22
+ enumeration.map{ |m| TorqueBox::Messaging::Message.new(m) }.each(&block)
25
23
  end
26
24
  end
27
25
 
@@ -71,8 +71,8 @@ module TorqueBox
71
71
  self.result = yield
72
72
  rescue Exception => e
73
73
  self.error = e
74
- puts "FutureResponder#respond: An error occured: ", e
75
- puts e.backtrace.join( "\n" )
74
+ $stderr.puts "FutureResponder#respond: An error occured: ", e
75
+ $stderr.puts e.backtrace.join( "\n" )
76
76
  end
77
77
 
78
78
  # Convenience method that returns the thread local
@@ -95,11 +95,14 @@ module TorqueBox
95
95
  message[:error] = @error if @error
96
96
  message[:result] = @result if @result_set
97
97
  @queue.publish( message,
98
- {
99
- :correlation_id => @correlation_id,
100
- :ttl => @message_ttl,
101
- :priority => priority
102
- } )
98
+ :correlation_id => @correlation_id,
99
+ :ttl => @message_ttl,
100
+ :priority => priority,
101
+ :encoding => :marshal,
102
+ :tx => false # can't be a part of the task's tx!
103
+ )
104
+ rescue TypeError => ex
105
+ $stderr.puts "FutureResponder#send_response: Warning: unable to marshal #{@result.inspect}"
103
106
  end
104
107
  end
105
108
  end
@@ -0,0 +1,50 @@
1
+ # Copyright 2008-2011 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
+ class JSONMessage < Message
21
+ ENCODING = :json
22
+ JMS_TYPE = :text
23
+
24
+ def require_json
25
+ # We can't ship our own json, as it may collide with the gem
26
+ # requirement for the app.
27
+ if !defined?( JSON )
28
+ begin
29
+ require 'json'
30
+ rescue LoadError => ex
31
+ raise RuntimeError.new( "Unable to load the json gem. Verify that is installed and in your Gemfile (if using Bundler)" )
32
+ end
33
+ end
34
+ end
35
+
36
+ def encode(message)
37
+ require_json
38
+ @jms_message.text = JSON.fast_generate( message ) unless message.nil?
39
+ end
40
+
41
+ def decode
42
+ require_json
43
+ JSON.parse( @jms_message.text, :symbolize_names => true ) unless @jms_message.text.nil?
44
+ end
45
+
46
+ end
47
+
48
+ Message.register_encoding( JSONMessage )
49
+ end
50
+ end
@@ -0,0 +1,44 @@
1
+ # Copyright 2008-2011 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 'base64'
19
+
20
+ module TorqueBox
21
+ module Messaging
22
+ class MarshalBase64Message < Message
23
+ ENCODING = :marshal_base64
24
+ JMS_TYPE = :text
25
+
26
+ def encode(message)
27
+ unless message.nil?
28
+ marshalled = Marshal.dump( message )
29
+ @jms_message.text = Base64.encode64( marshalled )
30
+ end
31
+ end
32
+
33
+ def decode
34
+ unless @jms_message.text.nil?
35
+ serialized = Base64.decode64( @jms_message.text )
36
+ Marshal.restore( serialized )
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ Message.register_encoding( MarshalBase64Message )
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ # Copyright 2008-2011 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
+ class MarshalMessage < Message
21
+ ENCODING = :marshal
22
+ JMS_TYPE = :bytes
23
+
24
+ def encode(message)
25
+ unless message.nil?
26
+ marshalled = Marshal.dump( message )
27
+ @jms_message.write_bytes( marshalled.to_java_bytes )
28
+ end
29
+ end
30
+
31
+ def decode
32
+ if (length = @jms_message.get_body_length) > 0
33
+ bytes = Java::byte[length].new
34
+ @jms_message.read_bytes( bytes )
35
+ Marshal.restore( String.from_java_bytes( bytes ) )
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ Message.register_encoding( MarshalMessage )
42
+ end
43
+ end