jruby-jms 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/HISTORY.md +15 -0
  2. data/README.md +27 -28
  3. data/Rakefile +7 -1
  4. data/doc/classes/JMS.html +265 -0
  5. data/doc/classes/JMS/BytesMessage.html +215 -0
  6. data/doc/classes/JMS/Connection.html +1145 -0
  7. data/doc/classes/JMS/MapMessage.html +333 -0
  8. data/doc/classes/JMS/Message.html +1085 -0
  9. data/doc/classes/JMS/MessageConsumer.html +316 -0
  10. data/doc/classes/JMS/MessageListenerImpl.html +262 -0
  11. data/doc/classes/JMS/ObjectMessage.html +170 -0
  12. data/doc/classes/JMS/OracleAQConnectionFactory.html +184 -0
  13. data/doc/classes/JMS/QueueBrowser.html +155 -0
  14. data/doc/classes/JMS/Session.html +947 -0
  15. data/doc/classes/JMS/SessionPool.html +411 -0
  16. data/doc/classes/JMS/TextMessage.html +194 -0
  17. data/doc/created.rid +1 -0
  18. data/doc/files/README_md.html +440 -0
  19. data/doc/files/lib/jms/bytes_message_rb.html +122 -0
  20. data/doc/files/lib/jms/connection_rb.html +140 -0
  21. data/doc/files/lib/jms/imports_rb.html +108 -0
  22. data/doc/files/lib/jms/logging_rb.html +129 -0
  23. data/doc/files/lib/jms/map_message_rb.html +122 -0
  24. data/doc/files/lib/jms/message_consumer_rb.html +122 -0
  25. data/doc/files/lib/jms/message_listener_impl_rb.html +122 -0
  26. data/doc/files/lib/jms/message_rb.html +122 -0
  27. data/doc/files/lib/jms/object_message_rb.html +122 -0
  28. data/doc/files/lib/jms/oracle_a_q_connection_factory_rb.html +122 -0
  29. data/doc/files/lib/jms/queue_browser_rb.html +122 -0
  30. data/doc/files/lib/jms/session_pool_rb.html +108 -0
  31. data/doc/files/lib/jms/session_rb.html +164 -0
  32. data/doc/files/lib/jms/text_message_rb.html +122 -0
  33. data/doc/files/lib/jms_rb.html +131 -0
  34. data/doc/fr_class_index.html +39 -0
  35. data/doc/fr_file_index.html +42 -0
  36. data/doc/fr_method_index.html +120 -0
  37. data/doc/index.html +24 -0
  38. data/doc/rdoc-style.css +208 -0
  39. data/examples/advanced/session_pool.rb +37 -0
  40. data/examples/client-server/replier.rb +29 -0
  41. data/examples/client-server/requestor.rb +40 -0
  42. data/examples/jms.yml +85 -9
  43. data/examples/performance/consumer.rb +6 -8
  44. data/examples/performance/producer.rb +10 -10
  45. data/examples/producer-consumer/browser.rb +24 -0
  46. data/examples/{consumer.rb → producer-consumer/consumer.rb} +5 -4
  47. data/examples/producer-consumer/consumer_async.rb +30 -0
  48. data/examples/{producer.rb → producer-consumer/producer.rb} +5 -3
  49. data/examples/publish-subscribe/publish.rb +24 -0
  50. data/examples/publish-subscribe/subscribe.rb +31 -0
  51. data/lib/jms/bytes_message.rb +52 -0
  52. data/lib/jms/connection.rb +170 -162
  53. data/lib/jms/imports.rb +21 -0
  54. data/lib/jms/logging.rb +17 -1
  55. data/lib/jms/{javax_jms_map_message.rb → map_message.rb} +2 -2
  56. data/lib/jms/message.rb +285 -0
  57. data/lib/jms/{javax_jms_message_consumer.rb → message_consumer.rb} +6 -3
  58. data/lib/jms/{message_listener.rb → message_listener_impl.rb} +3 -3
  59. data/lib/jms/{javax_jms_object_message.rb → object_message.rb} +1 -1
  60. data/lib/jms/oracle_a_q_connection_factory.rb +35 -0
  61. data/lib/jms/{javax_jms_queue_browser.rb → queue_browser.rb} +5 -4
  62. data/lib/jms/{javax_jms_session.rb → session.rb} +23 -25
  63. data/lib/jms/session_pool.rb +148 -0
  64. data/lib/jms/{javax_jms_text_message.rb → text_message.rb} +1 -1
  65. data/test/connection_test.rb +31 -29
  66. data/test/jms.yml +8 -9
  67. data/test/message_test.rb +29 -29
  68. data/test/session_test.rb +39 -39
  69. metadata +62 -22
  70. data/lib/jms/javax_jms_message.rb +0 -264
@@ -0,0 +1,21 @@
1
+ # Import Java classes into JMS Namespace
2
+ module JMS
3
+ java_import 'javax.jms.DeliveryMode'
4
+ java_import 'javax.jms.Message'
5
+ java_import 'javax.jms.BytesMessage'
6
+ java_import 'javax.jms.TextMessage'
7
+ java_import 'javax.jms.MapMessage'
8
+ java_import 'javax.jms.ObjectMessage'
9
+ java_import 'javax.jms.StreamMessage'
10
+ java_import 'javax.jms.Session'
11
+ java_import 'javax.jms.Destination'
12
+ java_import 'javax.jms.Queue'
13
+ java_import 'javax.jms.Topic'
14
+ java_import 'javax.jms.TemporaryQueue'
15
+ java_import 'javax.jms.TemporaryTopic'
16
+ java_import 'javax.jms.MessageConsumer'
17
+ java_import 'javax.jms.MessageProducer'
18
+ java_import 'javax.jms.QueueBrowser'
19
+ java_import 'javax.jms.MessageListener'
20
+ java_import 'javax.jms.ExceptionListener'
21
+ end
data/lib/jms/logging.rb CHANGED
@@ -1,4 +1,20 @@
1
- # Add HornetQ logging capabilities
1
+ ################################################################################
2
+ # Copyright 2008, 2009, 2010, 2011 J. Reid Morrison
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ################################################################################
16
+
17
+ # Add Logging capabilities
2
18
  module JMS
3
19
 
4
20
  # Returns the logger being used by jruby-jms
@@ -15,7 +15,7 @@
15
15
  ################################################################################
16
16
 
17
17
  #Interface javax.jms.MapMessage
18
- module javax.jms::MapMessage
18
+ module JMS::MapMessage
19
19
  # Since each is defined, add support for: inject, map, include?, and find_all?
20
20
  # <=> also allows support for: min, max, and sort
21
21
  include Enumerable
@@ -86,6 +86,6 @@ module javax.jms::MapMessage
86
86
  # Does map include specified key
87
87
  def include?(key)
88
88
  # Ensure a Ruby true is returned
89
- item_exists key == true
89
+ item_exists(key) == true
90
90
  end
91
91
  end
@@ -0,0 +1,285 @@
1
+ ################################################################################
2
+ # Copyright 2008, 2009, 2010, 2011 J. Reid Morrison
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ################################################################################
16
+
17
+ # Extend JMS Message Interface with Ruby methods
18
+ #
19
+ # A Message is the item that can be put on a queue, or obtained from a queue.
20
+ #
21
+ # A Message consists of 3 major parts:
22
+ # - Header
23
+ # Accessible as attributes of the Message class
24
+ # - Properties
25
+ # Accessible via [] and []= methods
26
+ # - Data
27
+ # The actual data portion of the message
28
+ # See the specific message types for details on how to access the data
29
+ # portion of the message
30
+ #
31
+ # For further help on javax.jms.Message
32
+ # http://download.oracle.com/javaee/6/api/index.html?javax/jms/Message.html
33
+ #
34
+ # Interface javax.jms.Message
35
+ module JMS::Message
36
+
37
+ # Methods directly exposed from the Java class:
38
+
39
+ # call-seq:
40
+ # acknowledge
41
+ #
42
+ # Acknowledges all consumed messages of the session of this consumed message
43
+ #
44
+
45
+ # call-seq:
46
+ # clear_body
47
+ #
48
+ # Clears out the message body
49
+ #
50
+
51
+ # call-seq:
52
+ # clear_properties
53
+ #
54
+ # Clears out the properties of this message
55
+ #
56
+
57
+ # For Backward compatibility with JRuby prior to 1.6
58
+ # JRuby 1.6 now does all this for us. Thank you headius :)
59
+ unless self.instance_methods.include? :jms_delivery_mode
60
+
61
+ # Header Fields - Attributes of the message
62
+
63
+ # Returns the JMS Delivery Mode
64
+ # One of the following will be returned
65
+ # JMS::DeliveryMode::PERSISTENT
66
+ # JMS::DeliveryMode::NON_PERSISTENT
67
+ def jms_delivery_mode
68
+ getJMSDeliveryMode
69
+ end
70
+
71
+ # Set the JMS Delivery Mode
72
+ # Values can be
73
+ # JMS::DeliveryMode::PERSISTENT
74
+ # JMS::DeliveryMode::NON_PERSISTENT
75
+ def jms_delivery_mode=(mode)
76
+ raise "Sorry, due to incompatibility with JRuby 1.6, please call jms_delivery_mode_sym when using symbols" if mode.is_a? Symbol
77
+ self.setJMSDeliveryMode(mode)
78
+ end
79
+
80
+ # Is the message persistent?
81
+ def persistent?
82
+ getJMSDeliveryMode == JMS::DeliveryMode::PERSISTENT
83
+ end
84
+
85
+ # Returns the Message correlation ID as a String
86
+ # The resulting string may contain nulls
87
+ def jms_correlation_id
88
+ String.from_java_bytes(getJMSCorrelationIDAsBytes) if getJMSCorrelationIDAsBytes
89
+ end
90
+
91
+ # Set the Message correlation ID
92
+ # correlation_id: String
93
+ # Also supports embedded nulls within the correlation id
94
+ def jms_correlation_id=(correlation_id)
95
+ setJMSCorrelationIDAsBytes(correlation_id.nil? ? nil : correlation_id.to_java_bytes)
96
+ end
97
+
98
+ # Returns the Message Destination
99
+ # Instance of JMS::Destination
100
+ def jms_destination
101
+ getJMSDestination
102
+ end
103
+
104
+ # Set the Message Destination
105
+ # jms_destination: Must be an instance of JMS::Destination
106
+ def jms_destination=(destination)
107
+ setJMSDestination(destination)
108
+ end
109
+
110
+ # Return the message expiration value as an Integer
111
+ def jms_expiration
112
+ getJMSExpiration
113
+ end
114
+
115
+ # Set the Message expiration value
116
+ # expiration: Integer
117
+ def jms_expiration=(expiration)
118
+ setJMSExpiration(expiration)
119
+ end
120
+
121
+ # Returns the Message ID as a String
122
+ # The resulting string may contain embedded nulls
123
+ def jms_message_id
124
+ getJMSMessageID
125
+ end
126
+
127
+ # Set the Message correlation ID
128
+ # message_id: String
129
+ # Also supports nulls within the message id
130
+ def jms_message_id=(message_id)
131
+ setJMSMessageID(message_id)
132
+ end
133
+
134
+ # Returns the Message Priority level as an Integer
135
+ def jms_priority
136
+ getJMSPriority
137
+ end
138
+
139
+ # Set the Message priority level
140
+ # priority: Integer
141
+ def jms_priority=(priority)
142
+ setJMSPriority(priority)
143
+ end
144
+
145
+ # Indicates whether the Message was redelivered?
146
+ def jms_redelivered?
147
+ getJMSRedelivered
148
+ end
149
+
150
+ # Set whether the Message was redelivered
151
+ # bool: Boolean
152
+ def jms_redelivered=(bool)
153
+ setJMSPriority(bool)
154
+ end
155
+
156
+ # Returns the Message reply to Destination
157
+ # Instance of JMS::Destination
158
+ def jms_reply_to
159
+ getJMSReplyTo
160
+ end
161
+
162
+ # Set the Message reply to Destination
163
+ # reply_to: Must be an instance of JMS::Destination
164
+ def jms_reply_to=(reply_to)
165
+ setJMSReplyTo(reply_to)
166
+ end
167
+
168
+ # Returns the Message timestamp as Java Timestamp Integer
169
+ #TODO Return Ruby Time object?
170
+ def jms_timestamp
171
+ getJMSTimestamp
172
+ end
173
+
174
+ # Set the Message timestamp as Java Timestamp Integer
175
+ # timestamp: Must be an Java Timestamp Integer
176
+ #TODO Support Ruby Time
177
+ def jms_timestamp=(timestamp)
178
+ setJMSTimestamp(timestamp)
179
+ end
180
+
181
+ # Returns the Message type supplied by the client when the message was sent
182
+ def jms_type
183
+ getJMSType
184
+ end
185
+
186
+ # Sets the Message type
187
+ # type: String
188
+ def jms_type=(type)
189
+ setJMSType(type)
190
+ end
191
+ end
192
+
193
+ # Return the JMS Delivery Mode as a Ruby symbol
194
+ # :persistent
195
+ # :non_persistent
196
+ # nil if unknown
197
+ def jms_delivery_mode_sym
198
+ case jms_delivery_mode
199
+ when JMS::DeliveryMode::PERSISTENT
200
+ :persistent
201
+ when JMS::DeliveryMode::NON_PERSISTENT
202
+ :non_persistent
203
+ else
204
+ nil
205
+ end
206
+ end
207
+
208
+ # Set the JMS Delivery Mode from a Ruby Symbol
209
+ # Valid values for mode
210
+ # :persistent
211
+ # :non_persistent
212
+ def jms_delivery_mode_sym=(mode)
213
+ val = case mode
214
+ when :persistent
215
+ JMS::DeliveryMode::PERSISTENT
216
+ when :non_persistent
217
+ JMS::DeliveryMode::NON_PERSISTENT
218
+ else
219
+ raise "Unknown delivery mode symbol: #{mode}"
220
+ end
221
+ self.setJMSDeliveryMode(val)
222
+ end
223
+
224
+ # Return the attributes (header fields) of the message as a Hash
225
+ def attributes
226
+ {
227
+ :jms_correlation_id => jms_correlation_id,
228
+ :jms_delivery_mode => jms_delivery_mode_sym,
229
+ :jms_destination => jms_destination,
230
+ :jms_expiration => jms_expiration,
231
+ :jms_message_id => jms_message_id,
232
+ :jms_priority => jms_priority,
233
+ :jms_redelivered => jms_redelivered?,
234
+ :jms_reply_to => jms_reply_to,
235
+ :jms_timestamp => jms_timestamp,
236
+ :jms_type => jms_type,
237
+ }
238
+ end
239
+
240
+ # Methods for manipulating the message properties
241
+
242
+ # Get the value of a property
243
+ def [](key)
244
+ getObjectProperty key.to_s
245
+ end
246
+
247
+ # Set a property
248
+ def []=(key, value)
249
+ setObjectProperty(key.to_s, value)
250
+ end
251
+
252
+ # Does message include specified property?
253
+ def include?(key)
254
+ # Ensure a Ruby true is returned
255
+ property_exists(key) == true
256
+ end
257
+
258
+ # Return Properties as a hash
259
+ def properties
260
+ h = {}
261
+ properties_each_pair {|k,v| h[k]=v}
262
+ h
263
+ end
264
+
265
+ # Set Properties from an existing hash
266
+ def properties=(h)
267
+ clear_properties
268
+ h.each_pair {|k,v| setObjectProperty(k.to_s, v)}
269
+ h
270
+ end
271
+
272
+ # Return each name value pair
273
+ def properties_each_pair(&proc)
274
+ enum = getPropertyNames
275
+ while enum.has_more_elements
276
+ key = enum.next_element
277
+ proc.call key, getObjectProperty(key)
278
+ end
279
+ end
280
+
281
+ def inspect
282
+ "#{self.class.name}: #{data}\nAttributes: #{attributes.inspect}\nProperties: #{properties.inspect}"
283
+ end
284
+
285
+ end
@@ -14,7 +14,8 @@
14
14
  # limitations under the License.
15
15
  ################################################################################
16
16
 
17
- module javax.jms::MessageConsumer
17
+ # Interface javax.jms.MessageConsumer
18
+ module JMS::MessageConsumer
18
19
  # Obtain a message from the Destination or Topic
19
20
  # In JMS terms, the message is received from the Destination
20
21
  # :timeout follows the rules for MQSeries:
@@ -75,7 +76,9 @@ module javax.jms::MessageConsumer
75
76
  duration = Time.now - start_time
76
77
  {:messages => message_count,
77
78
  :duration => duration,
78
- :messages_per_second => (message_count/duration).to_i}
79
+ :messages_per_second => duration > 0 ? (message_count/duration).to_i : 0,
80
+ :ms_per_msg => message_count > 0 ? (duration*1000.0)/message_count : 0
81
+ }
79
82
  end
80
83
  end
81
84
 
@@ -100,7 +103,7 @@ module javax.jms::MessageConsumer
100
103
  def on_message(params={}, &proc)
101
104
  raise "MessageConsumer::on_message requires a code block to be executed for each message received" unless proc
102
105
 
103
- @listener = JMS::MessageListener.new(params,&proc)
106
+ @listener = JMS::MessageListenerImpl.new(params,&proc)
104
107
  self.setMessageListener @listener
105
108
  end
106
109
 
@@ -15,11 +15,11 @@
15
15
  ################################################################################
16
16
 
17
17
  module JMS
18
-
18
+
19
19
  private
20
20
  # For internal use only by JMS::Connection
21
- class MessageListener
22
- include javax.jms::MessageListener
21
+ class MessageListenerImpl
22
+ include JMS::MessageListener
23
23
 
24
24
  # Parameters:
25
25
  # :statistics Capture statistics on how many messages have been read
@@ -15,7 +15,7 @@
15
15
  ################################################################################
16
16
 
17
17
  #Interface javax.jms.ObjectMessage
18
- module javax.jms::ObjectMessage
18
+ module JMS::ObjectMessage
19
19
  def data
20
20
  getObject
21
21
  end
@@ -0,0 +1,35 @@
1
+ ################################################################################
2
+ # Copyright 2008, 2009, 2010, 2011 J. Reid Morrison
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ################################################################################
16
+
17
+ module JMS
18
+
19
+ # Connection Factory to support Oracle AQ
20
+ class OracleAQConnectionFactory
21
+ attr_accessor :username, :url
22
+ attr_writer :password
23
+
24
+ # Creates a connection per standard JMS 1.1 techniques from the Oracle AQ JMS Interface
25
+ def create_connection
26
+ cf = oracle.jms.AQjmsFactory.getConnectionFactory(@url, java.util.Properties.new)
27
+ if username
28
+ cf.createConnection(@username, @password)
29
+ else
30
+ cf.createConnection()
31
+ end
32
+ end
33
+ end
34
+
35
+ end
@@ -14,14 +14,15 @@
14
14
  # limitations under the License.
15
15
  ################################################################################
16
16
 
17
- module javax.jms::QueueBrowser
17
+ #Interface javax.jms.QueueBrowser
18
+ module JMS::QueueBrowser
18
19
  # For each message on the queue call the supplied Proc
19
- def each(params={}, &proc)
20
- raise "javax.jms.QueueBrowser::each requires a code block to be executed for each message received" unless proc
20
+ def each(params={}, &block)
21
+ raise "JMS::QueueBrowser::each requires a code block to be executed for each message received" unless block
21
22
 
22
23
  e = self.getEnumeration
23
24
  while e.hasMoreElements
24
- proc.call(e.nextElement)
25
+ block.call(e.nextElement)
25
26
  end
26
27
  end
27
28
  end