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,1145 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: JMS::Connection</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">JMS::Connection</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/jms/connection_rb.html">
59
+ lib/jms/connection.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <p>
83
+ Every <a href="../JMS.html">JMS</a> <a
84
+ href="Connection.html#M000068">session</a> must have at least one <a
85
+ href="Connection.html">Connection</a> instance A <a
86
+ href="Connection.html">Connection</a> instance represents a connection
87
+ between this client application and the <a href="../JMS.html">JMS</a>
88
+ Provider (server/queue manager/broker). A connection is distinct from a <a
89
+ href="Session.html">Session</a>, in that multiple Sessions can share a
90
+ single connection. Also, unit of work control (commit/rollback) is
91
+ performed at the <a href="Session.html">Session</a> level.
92
+ </p>
93
+ <p>
94
+ Since many JRuby applications will only have one connection and one <a
95
+ href="Connection.html#M000068">session</a> several convenience methods have
96
+ been added to support creating both the <a href="Session.html">Session</a>
97
+ and <a href="Connection.html">Connection</a> objects automatically.
98
+ </p>
99
+ <p>
100
+ For Example, to read all messages from a queue and then terminate:
101
+ </p>
102
+ <pre>
103
+ require 'rubygems'
104
+ require 'jms'
105
+
106
+ JMS::Connection.create_session(
107
+ :factory =&gt; 'org.apache.activemq.ActiveMQConnectionFactory',
108
+ :broker_url =&gt; 'tcp://localhost:61616',
109
+ :require_jars =&gt; [
110
+ '~/Applications/apache-activemq-5.5.0/activemq-all-5.5.0.jar',
111
+ '~/Applications/apache-activemq-5.5.0/lib/optional/slf4j-log4j12-1.5.11.jar',
112
+ '~/Applications/apache-activemq-5.5.0/lib/optional/log4j-1.2.14.jar',
113
+ ]
114
+ ) do |session|
115
+ session.consumer(:queue_name=&gt;'TEST') do |consumer|
116
+ if message = consumer.receive_no_wait
117
+ puts &quot;Data Received: #{message.data}&quot;
118
+ else
119
+ puts 'No message available'
120
+ end
121
+ end
122
+ end
123
+ </pre>
124
+ <p>
125
+ The above code creates a <a href="Connection.html">Connection</a> and then
126
+ a <a href="Session.html">Session</a>. Once the block completes the <a
127
+ href="Connection.html#M000068">session</a> is closed and the <a
128
+ href="Connection.html">Connection</a> disconnected.
129
+ </p>
130
+ <p>
131
+ See: <a
132
+ href="http://download.oracle.com/javaee/6/api/javax/jms/Connection.html">download.oracle.com/javaee/6/api/javax/jms/Connection.html</a>
133
+ </p>
134
+
135
+ </div>
136
+
137
+
138
+ </div>
139
+
140
+ <div id="method-list">
141
+ <h3 class="section-bar">Methods</h3>
142
+
143
+ <div class="name-list">
144
+ <a href="#M000076">client_id</a>&nbsp;&nbsp;
145
+ <a href="#M000077">client_id=</a>&nbsp;&nbsp;
146
+ <a href="#M000075">close</a>&nbsp;&nbsp;
147
+ <a href="#M000074">create_session</a>&nbsp;&nbsp;
148
+ <a href="#M000085">create_session_pool</a>&nbsp;&nbsp;
149
+ <a href="#M000078">exception_listener</a>&nbsp;&nbsp;
150
+ <a href="#M000079">exception_listener=</a>&nbsp;&nbsp;
151
+ <a href="#M000069">fetch_dependencies</a>&nbsp;&nbsp;
152
+ <a href="#M000081">meta_data</a>&nbsp;&nbsp;
153
+ <a href="#M000070">new</a>&nbsp;&nbsp;
154
+ <a href="#M000080">on_exception</a>&nbsp;&nbsp;
155
+ <a href="#M000083">on_message</a>&nbsp;&nbsp;
156
+ <a href="#M000084">on_message_statistics</a>&nbsp;&nbsp;
157
+ <a href="#M000073">session</a>&nbsp;&nbsp;
158
+ <a href="#M000068">session</a>&nbsp;&nbsp;
159
+ <a href="#M000071">start</a>&nbsp;&nbsp;
160
+ <a href="#M000067">start</a>&nbsp;&nbsp;
161
+ <a href="#M000072">stop</a>&nbsp;&nbsp;
162
+ <a href="#M000082">to_s</a>&nbsp;&nbsp;
163
+ </div>
164
+ </div>
165
+
166
+ </div>
167
+
168
+
169
+ <!-- if includes -->
170
+
171
+ <div id="section">
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+ <!-- if method_list -->
181
+ <div id="methods">
182
+ <h3 class="section-bar">Public Class methods</h3>
183
+
184
+ <div id="method-M000070" class="method-detail">
185
+ <a name="M000070"></a>
186
+
187
+ <div class="method-heading">
188
+ <a href="#M000070" class="method-signature">
189
+ <span class="method-name">new</span><span class="method-args">(params = {})</span>
190
+ </a>
191
+ </div>
192
+
193
+ <div class="method-description">
194
+ <p>
195
+ Create a connection to the <a href="../JMS.html">JMS</a> provider
196
+ </p>
197
+ <p>
198
+ Note: Connection::start must be called before any consumers will be
199
+ </p>
200
+ <pre>
201
+ able to receive messages
202
+ </pre>
203
+ <p>
204
+ In <a href="../JMS.html">JMS</a> we need to <a
205
+ href="Connection.html#M000067">start</a> by obtaining the <a
206
+ href="../JMS.html">JMS</a> Factory class that is supplied by the <a
207
+ href="../JMS.html">JMS</a> Vendor.
208
+ </p>
209
+ <p>
210
+ There are 3 ways to establish a connection to a <a
211
+ href="../JMS.html">JMS</a> Provider
212
+ </p>
213
+ <pre>
214
+ 1. Supply the name of the JMS Providers Factory Class
215
+ 2. Supply an instance of the JMS Provider class itself
216
+ 3. Use a JNDI lookup to return the JMS Provider Factory class
217
+ </pre>
218
+ <p>
219
+ Parameters:
220
+ </p>
221
+ <pre>
222
+ :factory =&gt; String: Name of JMS Provider Factory class
223
+ =&gt; Class: JMS Provider Factory class itself
224
+
225
+ :jndi_name =&gt; String: Name of JNDI entry at which the Factory can be found
226
+ :jndi_context =&gt; Mandatory if jndi lookup is being used, contains details
227
+ on how to connect to JNDI server etc.
228
+
229
+ :require_jars =&gt; An optional array of Jar file names to load for the specified
230
+ JMS provider. By using this option it is not necessary
231
+ to put all the JMS Provider specific jar files into the
232
+ environment variable CLASSPATH prior to starting JRuby
233
+
234
+ :username =&gt; Username to connect to JMS provider with
235
+ :password =&gt; Password to use when to connecting to the JMS provider
236
+ Note: :password is ignored if :username is not supplied
237
+ </pre>
238
+ <p>
239
+ :factory and :jndi_name are mutually exclusive, both cannot be supplied at
240
+ the same time. :factory takes precedence over :jndi_name
241
+ </p>
242
+ <p>
243
+ <a href="../JMS.html">JMS</a> Provider specific properties can be set if
244
+ the <a href="../JMS.html">JMS</a> Factory itself has setters for those
245
+ properties.
246
+ </p>
247
+ <p>
248
+ For some known examples, see: [Example jms.yml](<a
249
+ href="https://github.com/reidmorrison/jruby-jms/blob/master/examples/jms.yml">github.com/reidmorrison/jruby-jms/blob/master/examples/jms.yml</a>)
250
+ </p>
251
+ <p><a class="source-toggle" href="#"
252
+ onclick="toggleCode('M000070-source');return false;">[Source]</a></p>
253
+ <div class="method-source-code" id="M000070-source">
254
+ <pre>
255
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 165</span>
256
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">params</span> = {})
257
+ <span class="ruby-comment cmt"># Used by ::on_message</span>
258
+ <span class="ruby-ivar">@sessions</span> = []
259
+ <span class="ruby-ivar">@consumers</span> = []
260
+
261
+ <span class="ruby-identifier">options</span> = <span class="ruby-identifier">params</span>.<span class="ruby-identifier">dup</span>
262
+
263
+ <span class="ruby-comment cmt"># Load Jar files on demand so that they do not need to be in the CLASSPATH</span>
264
+ <span class="ruby-comment cmt"># of JRuby lib directory</span>
265
+ <span class="ruby-identifier">fetch_dependencies</span>(<span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:require_jars</span>))
266
+
267
+ <span class="ruby-identifier">connection_factory</span> = <span class="ruby-keyword kw">nil</span>
268
+ <span class="ruby-identifier">factory</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:factory</span>)
269
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">factory</span>
270
+ <span class="ruby-comment cmt"># If factory is a string, then it is the name of a class, not the class itself</span>
271
+ <span class="ruby-identifier">factory</span> = <span class="ruby-identifier">eval</span>(<span class="ruby-identifier">factory</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:to_str</span>
272
+ <span class="ruby-identifier">connection_factory</span> = <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">new</span>
273
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">jndi_name</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:jndi_name</span>]
274
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Missing mandatory parameter :jndi_context missing in call to Connection::connect&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">jndi_context</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:jndi_context</span>]
275
+ <span class="ruby-identifier">jndi</span> = <span class="ruby-identifier">javax</span>.<span class="ruby-identifier">naming</span>.<span class="ruby-constant">InitialContext</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">java</span>.<span class="ruby-identifier">util</span>.<span class="ruby-constant">Hashtable</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">jndi_context</span>))
276
+ <span class="ruby-keyword kw">begin</span>
277
+ <span class="ruby-identifier">connection_factory</span> = <span class="ruby-identifier">jndi</span>.<span class="ruby-identifier">lookup</span> <span class="ruby-identifier">jndi_name</span>
278
+ <span class="ruby-keyword kw">ensure</span>
279
+ <span class="ruby-identifier">jndi</span>.<span class="ruby-identifier">close</span>
280
+ <span class="ruby-keyword kw">end</span>
281
+ <span class="ruby-keyword kw">else</span>
282
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Missing mandatory parameter :factory or :jndi_name missing in call to Connection::connect&quot;</span>
283
+ <span class="ruby-keyword kw">end</span>
284
+ <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:jndi_name</span>)
285
+ <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:jndi_context</span>)
286
+
287
+ <span class="ruby-constant">JMS</span><span class="ruby-operator">::</span><span class="ruby-identifier">logger</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;Using Factory: #{connection_factory.java_class}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">connection_factory</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:java_class</span>
288
+ <span class="ruby-identifier">options</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">val</span><span class="ruby-operator">|</span>
289
+ <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> [<span class="ruby-identifier">:username</span>, <span class="ruby-identifier">:password</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">key</span>)
290
+
291
+ <span class="ruby-identifier">method</span> = <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span><span class="ruby-operator">+</span><span class="ruby-value str">'='</span>
292
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">connection_factory</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">method</span>
293
+ <span class="ruby-identifier">connection_factory</span>.<span class="ruby-identifier">send</span> <span class="ruby-identifier">method</span>, <span class="ruby-identifier">val</span>
294
+ <span class="ruby-constant">JMS</span><span class="ruby-operator">::</span><span class="ruby-identifier">logger</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">&quot; #{key} = #{connection_factory.send key.to_sym}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">connection_factory</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_sym</span>
295
+ <span class="ruby-keyword kw">else</span>
296
+ <span class="ruby-constant">JMS</span><span class="ruby-operator">::</span><span class="ruby-identifier">logger</span>.<span class="ruby-identifier">warn</span> <span class="ruby-node">&quot;#{connection_factory.java_class} does not understand option: :#{key}=#{val}, ignoring :#{key}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">connection_factory</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:java_class</span>
297
+ <span class="ruby-keyword kw">end</span>
298
+ <span class="ruby-keyword kw">end</span>
299
+
300
+ <span class="ruby-comment cmt"># Check for username and password</span>
301
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:username</span>]
302
+ <span class="ruby-ivar">@jms_connection</span> = <span class="ruby-identifier">connection_factory</span>.<span class="ruby-identifier">create_connection</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:username</span>], <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:password</span>])
303
+ <span class="ruby-keyword kw">else</span>
304
+ <span class="ruby-ivar">@jms_connection</span> = <span class="ruby-identifier">connection_factory</span>.<span class="ruby-identifier">create_connection</span>
305
+ <span class="ruby-keyword kw">end</span>
306
+ <span class="ruby-keyword kw">end</span>
307
+ </pre>
308
+ </div>
309
+ </div>
310
+ </div>
311
+
312
+ <div id="method-M000068" class="method-detail">
313
+ <a name="M000068"></a>
314
+
315
+ <div class="method-heading">
316
+ <a href="#M000068" class="method-signature">
317
+ <span class="method-name">session</span><span class="method-args">(params = {}, &amp;proc)</span>
318
+ </a>
319
+ </div>
320
+
321
+ <div class="method-description">
322
+ <p>
323
+ Connect to a <a href="../JMS.html">JMS</a> Broker, create and <a
324
+ href="Connection.html#M000067">start</a> the <a
325
+ href="Connection.html#M000068">session</a>, then call the code block
326
+ passing in the <a href="Connection.html#M000068">session</a>. Both the <a
327
+ href="Session.html">Session</a> and <a
328
+ href="Connection.html">Connection</a> are closed on termination of the
329
+ block
330
+ </p>
331
+ <p>
332
+ Shortcut convenience method to both connect to the broker and create a <a
333
+ href="Connection.html#M000068">session</a> Useful when only a single <a
334
+ href="Connection.html#M000068">session</a> is required in the current
335
+ thread
336
+ </p>
337
+ <p>
338
+ Note: It is important that each thread have its own <a
339
+ href="Connection.html#M000068">session</a> to support transactions
340
+ </p>
341
+ <pre>
342
+ This method will also start the session immediately so that any
343
+ consumers using this session will start immediately
344
+ </pre>
345
+ <p><a class="source-toggle" href="#"
346
+ onclick="toggleCode('M000068-source');return false;">[Source]</a></p>
347
+ <div class="method-source-code" id="M000068-source">
348
+ <pre>
349
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 83</span>
350
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">session</span>(<span class="ruby-identifier">params</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">proc</span>)
351
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">params</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">connection</span><span class="ruby-operator">|</span>
352
+ <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">session</span>(<span class="ruby-identifier">params</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">proc</span>)
353
+ <span class="ruby-keyword kw">end</span>
354
+ <span class="ruby-keyword kw">end</span>
355
+ </pre>
356
+ </div>
357
+ </div>
358
+ </div>
359
+
360
+ <div id="method-M000067" class="method-detail">
361
+ <a name="M000067"></a>
362
+
363
+ <div class="method-heading">
364
+ <a href="#M000067" class="method-signature">
365
+ <span class="method-name">start</span><span class="method-args">(params = {}, &amp;proc)</span>
366
+ </a>
367
+ </div>
368
+
369
+ <div class="method-description">
370
+ <p>
371
+ Create a connection to the <a href="../JMS.html">JMS</a> provider, <a
372
+ href="Connection.html#M000067">start</a> the connection, call the supplied
373
+ code block, then <a href="Connection.html#M000075">close</a> the connection
374
+ upon completion
375
+ </p>
376
+ <p>
377
+ Returns the result of the supplied block
378
+ </p>
379
+ <p><a class="source-toggle" href="#"
380
+ onclick="toggleCode('M000067-source');return false;">[Source]</a></p>
381
+ <div class="method-source-code" id="M000067-source">
382
+ <pre>
383
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 62</span>
384
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">params</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">proc</span>)
385
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Missing mandatory Block when calling JMS::Connection.start&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">proc</span>
386
+ <span class="ruby-identifier">connection</span> = <span class="ruby-constant">Connection</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">params</span>)
387
+ <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">start</span>
388
+ <span class="ruby-keyword kw">begin</span>
389
+ <span class="ruby-identifier">proc</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">connection</span>)
390
+ <span class="ruby-keyword kw">ensure</span>
391
+ <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">close</span>
392
+ <span class="ruby-keyword kw">end</span>
393
+ <span class="ruby-keyword kw">end</span>
394
+ </pre>
395
+ </div>
396
+ </div>
397
+ </div>
398
+
399
+ <h3 class="section-bar">Public Instance methods</h3>
400
+
401
+ <div id="method-M000076" class="method-detail">
402
+ <a name="M000076"></a>
403
+
404
+ <div class="method-heading">
405
+ <a href="#M000076" class="method-signature">
406
+ <span class="method-name">client_id</span><span class="method-args">()</span>
407
+ </a>
408
+ </div>
409
+
410
+ <div class="method-description">
411
+ <p>
412
+ Gets the client identifier for this connection.
413
+ </p>
414
+ <p><a class="source-toggle" href="#"
415
+ onclick="toggleCode('M000076-source');return false;">[Source]</a></p>
416
+ <div class="method-source-code" id="M000076-source">
417
+ <pre>
418
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 324</span>
419
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">client_id</span>
420
+ <span class="ruby-ivar">@jms_connection</span>.<span class="ruby-identifier">getClientID</span>
421
+ <span class="ruby-keyword kw">end</span>
422
+ </pre>
423
+ </div>
424
+ </div>
425
+ </div>
426
+
427
+ <div id="method-M000077" class="method-detail">
428
+ <a name="M000077"></a>
429
+
430
+ <div class="method-heading">
431
+ <a href="#M000077" class="method-signature">
432
+ <span class="method-name">client_id=</span><span class="method-args">(client_id)</span>
433
+ </a>
434
+ </div>
435
+
436
+ <div class="method-description">
437
+ <p>
438
+ Sets the client identifier for this connection.
439
+ </p>
440
+ <p><a class="source-toggle" href="#"
441
+ onclick="toggleCode('M000077-source');return false;">[Source]</a></p>
442
+ <div class="method-source-code" id="M000077-source">
443
+ <pre>
444
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 329</span>
445
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">client_id=</span>(<span class="ruby-identifier">client_id</span>)
446
+ <span class="ruby-ivar">@jms_connection</span>.<span class="ruby-identifier">setClientID</span>(<span class="ruby-identifier">client_id</span>)
447
+ <span class="ruby-keyword kw">end</span>
448
+ </pre>
449
+ </div>
450
+ </div>
451
+ </div>
452
+
453
+ <div id="method-M000075" class="method-detail">
454
+ <a name="M000075"></a>
455
+
456
+ <div class="method-heading">
457
+ <a href="#M000075" class="method-signature">
458
+ <span class="method-name">close</span><span class="method-args">()</span>
459
+ </a>
460
+ </div>
461
+
462
+ <div class="method-description">
463
+ <p>
464
+ Close connection with the <a href="../JMS.html">JMS</a> Provider First <a
465
+ href="Connection.html#M000075">close</a> any consumers or sessions that are
466
+ active as a result of JMS::Connection::on_message
467
+ </p>
468
+ <p><a class="source-toggle" href="#"
469
+ onclick="toggleCode('M000075-source');return false;">[Source]</a></p>
470
+ <div class="method-source-code" id="M000075-source">
471
+ <pre>
472
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 313</span>
473
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">close</span>
474
+ <span class="ruby-ivar">@consumers</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">consumer</span><span class="ruby-operator">|</span> <span class="ruby-identifier">consumer</span>.<span class="ruby-identifier">close</span> } <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@consumers</span>
475
+ <span class="ruby-ivar">@consumers</span> = []
476
+
477
+ <span class="ruby-ivar">@sessions</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">session</span><span class="ruby-operator">|</span> <span class="ruby-identifier">session</span>.<span class="ruby-identifier">close</span>} <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@sessions</span>
478
+ <span class="ruby-ivar">@session</span>=[]
479
+
480
+ <span class="ruby-ivar">@jms_connection</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@jms_connection</span>
481
+ <span class="ruby-keyword kw">end</span>
482
+ </pre>
483
+ </div>
484
+ </div>
485
+ </div>
486
+
487
+ <div id="method-M000074" class="method-detail">
488
+ <a name="M000074"></a>
489
+
490
+ <div class="method-heading">
491
+ <a href="#M000074" class="method-signature">
492
+ <span class="method-name">create_session</span><span class="method-args">(params={})</span>
493
+ </a>
494
+ </div>
495
+
496
+ <div class="method-description">
497
+ <p>
498
+ Create a <a href="Connection.html#M000068">session</a> over this
499
+ connection. It is recommended to create separate sessions for each thread
500
+ </p>
501
+ <p>
502
+ Note: Remember to call <a href="Connection.html#M000075">close</a> on the
503
+ returned <a href="Connection.html#M000068">session</a> when it is no longer
504
+ </p>
505
+ <pre>
506
+ needed. Rather use JMS::Connection#session with a block whenever
507
+ possible
508
+ </pre>
509
+ <p>
510
+ Parameters:
511
+ </p>
512
+ <pre>
513
+ :transacted =&gt; true or false
514
+ Determines whether transactions are supported within this session.
515
+ I.e. Whether commit or rollback can be called
516
+ Default: false
517
+ Note: :options below are ignored if this value is set to :true
518
+
519
+ :options =&gt; any of the JMS::Session constants:
520
+ Note: :options are ignored if :transacted =&gt; true
521
+ JMS::Session::AUTO_ACKNOWLEDGE
522
+ With this acknowledgment mode, the session automatically acknowledges
523
+ a client's receipt of a message either when the session has successfully
524
+ returned from a call to receive or when the message listener the session has
525
+ called to process the message successfully returns.
526
+ JMS::Session::CLIENT_ACKNOWLEDGE
527
+ With this acknowledgment mode, the client acknowledges a consumed
528
+ message by calling the message's acknowledge method.
529
+ JMS::Session::DUPS_OK_ACKNOWLEDGE
530
+ This acknowledgment mode instructs the session to lazily acknowledge
531
+ the delivery of messages.
532
+ JMS::Session::SESSION_TRANSACTED
533
+ This value is returned from the method getAcknowledgeMode if the
534
+ session is transacted.
535
+ Default: JMS::Session::AUTO_ACKNOWLEDGE
536
+ </pre>
537
+ <p><a class="source-toggle" href="#"
538
+ onclick="toggleCode('M000074-source');return false;">[Source]</a></p>
539
+ <div class="method-source-code" id="M000074-source">
540
+ <pre>
541
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 305</span>
542
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_session</span>(<span class="ruby-identifier">params</span>={})
543
+ <span class="ruby-identifier">transacted</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:transacted</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword kw">false</span>
544
+ <span class="ruby-identifier">options</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:options</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">JMS</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span><span class="ruby-operator">::</span><span class="ruby-constant">AUTO_ACKNOWLEDGE</span>
545
+ <span class="ruby-ivar">@jms_connection</span>.<span class="ruby-identifier">create_session</span>(<span class="ruby-identifier">transacted</span>, <span class="ruby-identifier">options</span>)
546
+ <span class="ruby-keyword kw">end</span>
547
+ </pre>
548
+ </div>
549
+ </div>
550
+ </div>
551
+
552
+ <div id="method-M000085" class="method-detail">
553
+ <a name="M000085"></a>
554
+
555
+ <div class="method-heading">
556
+ <a href="#M000085" class="method-signature">
557
+ <span class="method-name">create_session_pool</span><span class="method-args">(params={})</span>
558
+ </a>
559
+ </div>
560
+
561
+ <div class="method-description">
562
+ <p>
563
+ Since a <a href="Session.html">Session</a> can only be used by one thread
564
+ at a time, we could create a <a href="Session.html">Session</a> for every
565
+ thread. That could result in excessive unused Sessions. An alternative is
566
+ to create a pool of sessions that can be shared by multiple threads.
567
+ </p>
568
+ <p>
569
+ Each thread can request a <a href="Connection.html#M000068">session</a> and
570
+ then return it once it is no longer needed by that thread. The only way to
571
+ get a <a href="Connection.html#M000068">session</a> is to pass a block so
572
+ that the <a href="Session.html">Session</a> is automatically returned to
573
+ the pool upon completion of the block.
574
+ </p>
575
+ <p>
576
+ Parameters:
577
+ </p>
578
+ <pre>
579
+ see regular session parameters from: JMS::Connection#initialize
580
+ </pre>
581
+ <p>
582
+ Additional parameters for controlling the <a
583
+ href="Connection.html#M000068">session</a> pool itself
584
+ </p>
585
+ <pre>
586
+ :pool_name Name of the pool as it shows up in the logger.
587
+ Default: 'JMS::SessionPool'
588
+ :pool_size Maximum Pool Size. Default: 10
589
+ The pool only grows as needed and will never exceed
590
+ :pool_size
591
+ :pool_warn_timeout Number of seconds to wait before logging a warning when a
592
+ session in the pool is not available. Measured in seconds
593
+ Default: 5.0
594
+ :pool_logger Supply a logger that responds to #debug, #info, #warn and #debug?
595
+ For example: Rails.logger
596
+ Default: None
597
+ </pre>
598
+ <p>
599
+ Example:
600
+ </p>
601
+ <pre>
602
+ session_pool = connection.create_session_pool(config)
603
+
604
+ session_pool.session do |session|
605
+ producer.send(session.message(&quot;Hello World&quot;))
606
+ end
607
+ </pre>
608
+ <p><a class="source-toggle" href="#"
609
+ onclick="toggleCode('M000085-source');return false;">[Source]</a></p>
610
+ <div class="method-source-code" id="M000085-source">
611
+ <pre>
612
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 512</span>
613
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_session_pool</span>(<span class="ruby-identifier">params</span>={})
614
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/session_pool'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-constant">JMS</span><span class="ruby-operator">::</span><span class="ruby-constant">SessionPool</span>
615
+ <span class="ruby-constant">JMS</span><span class="ruby-operator">::</span><span class="ruby-constant">SessionPool</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">params</span>)
616
+ <span class="ruby-keyword kw">end</span>
617
+ </pre>
618
+ </div>
619
+ </div>
620
+ </div>
621
+
622
+ <div id="method-M000078" class="method-detail">
623
+ <a name="M000078"></a>
624
+
625
+ <div class="method-heading">
626
+ <a href="#M000078" class="method-signature">
627
+ <span class="method-name">exception_listener</span><span class="method-args">()</span>
628
+ </a>
629
+ </div>
630
+
631
+ <div class="method-description">
632
+ <p>
633
+ Returns the ExceptionListener object for this connection Returned class
634
+ implements interface JMS::ExceptionListener
635
+ </p>
636
+ <p><a class="source-toggle" href="#"
637
+ onclick="toggleCode('M000078-source');return false;">[Source]</a></p>
638
+ <div class="method-source-code" id="M000078-source">
639
+ <pre>
640
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 335</span>
641
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exception_listener</span>
642
+ <span class="ruby-ivar">@jms_connection</span>.<span class="ruby-identifier">getExceptionListener</span>
643
+ <span class="ruby-keyword kw">end</span>
644
+ </pre>
645
+ </div>
646
+ </div>
647
+ </div>
648
+
649
+ <div id="method-M000079" class="method-detail">
650
+ <a name="M000079"></a>
651
+
652
+ <div class="method-heading">
653
+ <a href="#M000079" class="method-signature">
654
+ <span class="method-name">exception_listener=</span><span class="method-args">(listener)</span>
655
+ </a>
656
+ </div>
657
+
658
+ <div class="method-description">
659
+ <p>
660
+ Sets an exception listener for this connection See ::<a
661
+ href="Connection.html#M000080">on_exception</a> to set a Ruby Listener
662
+ Returns: nil
663
+ </p>
664
+ <p><a class="source-toggle" href="#"
665
+ onclick="toggleCode('M000079-source');return false;">[Source]</a></p>
666
+ <div class="method-source-code" id="M000079-source">
667
+ <pre>
668
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 342</span>
669
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exception_listener=</span>(<span class="ruby-identifier">listener</span>)
670
+ <span class="ruby-ivar">@jms_connection</span>.<span class="ruby-identifier">setExceptionListener</span>(<span class="ruby-identifier">listener</span>)
671
+ <span class="ruby-keyword kw">end</span>
672
+ </pre>
673
+ </div>
674
+ </div>
675
+ </div>
676
+
677
+ <div id="method-M000069" class="method-detail">
678
+ <a name="M000069"></a>
679
+
680
+ <div class="method-heading">
681
+ <a href="#M000069" class="method-signature">
682
+ <span class="method-name">fetch_dependencies</span><span class="method-args">(jar_list)</span>
683
+ </a>
684
+ </div>
685
+
686
+ <div class="method-description">
687
+ <p>
688
+ Load the required jar files for this <a href="../JMS.html">JMS</a> Provider
689
+ and load JRuby extensions for those classes
690
+ </p>
691
+ <p>
692
+ Rather than copying the <a href="../JMS.html">JMS</a> jar files into the
693
+ JRuby lib, load them on demand. JRuby <a href="../JMS.html">JMS</a>
694
+ extensions are only loaded once the jar files have been loaded.
695
+ </p>
696
+ <p>
697
+ Can be called multiple times if required, although it would not be
698
+ performant to do so regularly.
699
+ </p>
700
+ <p>
701
+ Parameter: jar_list is an Array of the path and filenames to jar files
702
+ </p>
703
+ <pre>
704
+ to load for this JMS Provider
705
+ </pre>
706
+ <p>
707
+ Returns nil
708
+ </p>
709
+ <p>
710
+ TODO make this a class method
711
+ </p>
712
+ <p><a class="source-toggle" href="#"
713
+ onclick="toggleCode('M000069-source');return false;">[Source]</a></p>
714
+ <div class="method-source-code" id="M000069-source">
715
+ <pre>
716
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 105</span>
717
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fetch_dependencies</span>(<span class="ruby-identifier">jar_list</span>)
718
+ <span class="ruby-identifier">jar_list</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">jar</span><span class="ruby-operator">|</span>
719
+ <span class="ruby-constant">JMS</span><span class="ruby-operator">::</span><span class="ruby-identifier">logger</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;Loading Jar File:#{jar}&quot;</span>
720
+ <span class="ruby-keyword kw">begin</span>
721
+ <span class="ruby-identifier">require</span> <span class="ruby-identifier">jar</span>
722
+ <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">exc</span>
723
+ <span class="ruby-constant">JMS</span><span class="ruby-operator">::</span><span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span> <span class="ruby-node">&quot;Failed to Load Jar File:#{jar}. #{exc.to_s}&quot;</span>
724
+ <span class="ruby-keyword kw">end</span>
725
+ <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">jar_list</span>
726
+
727
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/imports'</span>
728
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/message_listener_impl'</span>
729
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/message'</span>
730
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/text_message'</span>
731
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/map_message'</span>
732
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/bytes_message'</span>
733
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/object_message'</span>
734
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/session'</span>
735
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/message_consumer'</span>
736
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/queue_browser'</span>
737
+ <span class="ruby-identifier">require</span> <span class="ruby-value str">'jms/oracle_a_q_connection_factory'</span>
738
+ <span class="ruby-keyword kw">end</span>
739
+ </pre>
740
+ </div>
741
+ </div>
742
+ </div>
743
+
744
+ <div id="method-M000081" class="method-detail">
745
+ <a name="M000081"></a>
746
+
747
+ <div class="method-heading">
748
+ <a href="#M000081" class="method-signature">
749
+ <span class="method-name">meta_data</span><span class="method-args">()</span>
750
+ </a>
751
+ </div>
752
+
753
+ <div class="method-description">
754
+ <p>
755
+ Gets the metadata for this connection see: <a
756
+ href="http://download.oracle.com/javaee/6/api/javax/jms/ConnectionMetaData.html">download.oracle.com/javaee/6/api/javax/jms/ConnectionMetaData.html</a>
757
+ </p>
758
+ <p><a class="source-toggle" href="#"
759
+ onclick="toggleCode('M000081-source');return false;">[Source]</a></p>
760
+ <div class="method-source-code" id="M000081-source">
761
+ <pre>
762
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 365</span>
763
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">meta_data</span>
764
+ <span class="ruby-ivar">@jms_connection</span>.<span class="ruby-identifier">getMetaData</span>
765
+ <span class="ruby-keyword kw">end</span>
766
+ </pre>
767
+ </div>
768
+ </div>
769
+ </div>
770
+
771
+ <div id="method-M000080" class="method-detail">
772
+ <a name="M000080"></a>
773
+
774
+ <div class="method-heading">
775
+ <a href="#M000080" class="method-signature">
776
+ <span class="method-name">on_exception</span><span class="method-args">(&amp;block)</span>
777
+ </a>
778
+ </div>
779
+
780
+ <div class="method-description">
781
+ <p>
782
+ Whenever an exception occurs the supplied block is called This is important
783
+ when Connection::on_message has been used, since failures to the connection
784
+ would be lost otherwise
785
+ </p>
786
+ <p>
787
+ For details on the supplied parameter when the block is called, see: <a
788
+ href="http://download.oracle.com/javaee/6/api/javax/jms/JMSException.html">download.oracle.com/javaee/6/api/javax/jms/JMSException.html</a>
789
+ </p>
790
+ <p>
791
+ Example:
792
+ </p>
793
+ <pre>
794
+ connection.on_exception do |jms_exception|
795
+ puts &quot;JMS Exception has occurred: #{jms_exception}&quot;
796
+ end
797
+ </pre>
798
+ <p>
799
+ Returns: nil
800
+ </p>
801
+ <p><a class="source-toggle" href="#"
802
+ onclick="toggleCode('M000080-source');return false;">[Source]</a></p>
803
+ <div class="method-source-code" id="M000080-source">
804
+ <pre>
805
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 359</span>
806
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">on_exception</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
807
+ <span class="ruby-ivar">@jms_connection</span>.<span class="ruby-identifier">setExceptionListener</span>(<span class="ruby-identifier">block</span>)
808
+ <span class="ruby-keyword kw">end</span>
809
+ </pre>
810
+ </div>
811
+ </div>
812
+ </div>
813
+
814
+ <div id="method-M000083" class="method-detail">
815
+ <a name="M000083"></a>
816
+
817
+ <div class="method-heading">
818
+ <a href="#M000083" class="method-signature">
819
+ <span class="method-name">on_message</span><span class="method-args">(params, &amp;block)</span>
820
+ </a>
821
+ </div>
822
+
823
+ <div class="method-description">
824
+ <p>
825
+ Receive messages in a separate thread when they arrive
826
+ </p>
827
+ <p>
828
+ Allows messages to be received Asynchronously in a separate thread. This
829
+ method will return to the caller before messages are processed. It is then
830
+ the callers responsibility to keep the program active so that messages can
831
+ then be processed.
832
+ </p>
833
+ <p>
834
+ <a href="Session.html">Session</a> Parameters:
835
+ </p>
836
+ <pre>
837
+ :transacted =&gt; true or false
838
+ Determines whether transactions are supported within this session.
839
+ I.e. Whether commit or rollback can be called
840
+ Default: false
841
+ Note: :options below are ignored if this value is set to :true
842
+
843
+ :options =&gt; any of the JMS::Session constants:
844
+ Note: :options are ignored if :transacted =&gt; true
845
+ JMS::Session::AUTO_ACKNOWLEDGE
846
+ With this acknowledgment mode, the session automatically acknowledges
847
+ a client's receipt of a message either when the session has successfully
848
+ returned from a call to receive or when the message listener the session has
849
+ called to process the message successfully returns.
850
+ JMS::Session::CLIENT_ACKNOWLEDGE
851
+ With this acknowledgment mode, the client acknowledges a consumed
852
+ message by calling the message's acknowledge method.
853
+ JMS::Session::DUPS_OK_ACKNOWLEDGE
854
+ This acknowledgment mode instructs the session to lazily acknowledge
855
+ the delivery of messages.
856
+ JMS::Session::SESSION_TRANSACTED
857
+ This value is returned from the method getAcknowledgeMode if the
858
+ session is transacted.
859
+ Default: JMS::Session::AUTO_ACKNOWLEDGE
860
+
861
+ :session_count : Number of sessions to create, each with their own consumer which
862
+ in turn will call the supplied code block.
863
+ Note: The supplied block must be thread safe since it will be called
864
+ by several threads at the same time.
865
+ I.e. Don't change instance variables etc. without the
866
+ necessary semaphores etc.
867
+ Default: 1
868
+ </pre>
869
+ <p>
870
+ Consumer Parameters:
871
+ </p>
872
+ <pre>
873
+ :queue_name =&gt; String: Name of the Queue to return
874
+ Symbol: :temporary =&gt; Create temporary queue
875
+ Mandatory unless :topic_name is supplied
876
+ Or,
877
+ :topic_name =&gt; String: Name of the Topic to write to or subscribe to
878
+ Symbol: :temporary =&gt; Create temporary topic
879
+ Mandatory unless :queue_name is supplied
880
+ Or,
881
+ :destination=&gt; Explicit javaxJms::Destination to use
882
+
883
+ :selector =&gt; Filter which messages should be returned from the queue
884
+ Default: All messages
885
+
886
+ :no_local =&gt; Determine whether messages published by its own connection
887
+ should be delivered to the supplied block
888
+ Default: false
889
+
890
+ :statistics Capture statistics on how many messages have been read
891
+ true : This method will capture statistics on the number of messages received
892
+ and the time it took to process them.
893
+ The timer starts when each() is called and finishes when either the last message was received,
894
+ or when Destination::statistics is called. In this case MessageConsumer::statistics
895
+ can be called several times during processing without affecting the end time.
896
+ Also, the start time and message count is not reset until MessageConsumer::each
897
+ is called again with :statistics =&gt; true
898
+ </pre>
899
+ <p>
900
+ Usage: For transacted sessions the block supplied must return either true
901
+ or false:
902
+ </p>
903
+ <pre>
904
+ true =&gt; The session is committed
905
+ false =&gt; The session is rolled back
906
+ Any Exception =&gt; The session is rolled back
907
+ </pre>
908
+ <p>
909
+ Note: Separately invoke <a
910
+ href="Connection.html#M000080">Connection#on_exception</a> so that
911
+ connection failures can be handled
912
+ </p>
913
+ <pre>
914
+ since on_message will Not be called if the connection is lost
915
+ </pre>
916
+ <p><a class="source-toggle" href="#"
917
+ onclick="toggleCode('M000083-source');return false;">[Source]</a></p>
918
+ <div class="method-source-code" id="M000083-source">
919
+ <pre>
920
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 450</span>
921
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">on_message</span>(<span class="ruby-identifier">params</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
922
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;JMS::Connection must be connected prior to calling JMS::Connection::on_message&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@sessions</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@consumers</span>
923
+
924
+ <span class="ruby-identifier">consumer_count</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:session_count</span>] <span class="ruby-operator">||</span> <span class="ruby-value">1</span>
925
+ <span class="ruby-identifier">consumer_count</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span>
926
+ <span class="ruby-identifier">session</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">create_session</span>(<span class="ruby-identifier">params</span>)
927
+ <span class="ruby-identifier">consumer</span> = <span class="ruby-identifier">session</span>.<span class="ruby-identifier">consumer</span>(<span class="ruby-identifier">params</span>)
928
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">session</span>.<span class="ruby-identifier">transacted?</span>
929
+ <span class="ruby-identifier">consumer</span>.<span class="ruby-identifier">on_message</span>(<span class="ruby-identifier">params</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">message</span><span class="ruby-operator">|</span>
930
+ <span class="ruby-keyword kw">begin</span>
931
+ <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">message</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">session</span>.<span class="ruby-identifier">commit</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">session</span>.<span class="ruby-identifier">rollback</span>
932
+ <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">exc</span>
933
+ <span class="ruby-identifier">session</span>.<span class="ruby-identifier">rollback</span>
934
+ <span class="ruby-identifier">throw</span> <span class="ruby-identifier">exc</span>
935
+ <span class="ruby-keyword kw">end</span>
936
+ <span class="ruby-keyword kw">end</span>
937
+ <span class="ruby-keyword kw">else</span>
938
+ <span class="ruby-identifier">consumer</span>.<span class="ruby-identifier">on_message</span>(<span class="ruby-identifier">params</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
939
+ <span class="ruby-keyword kw">end</span>
940
+ <span class="ruby-ivar">@consumers</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">consumer</span>
941
+ <span class="ruby-ivar">@sessions</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">session</span>
942
+ <span class="ruby-keyword kw">end</span>
943
+ <span class="ruby-keyword kw">end</span>
944
+ </pre>
945
+ </div>
946
+ </div>
947
+ </div>
948
+
949
+ <div id="method-M000084" class="method-detail">
950
+ <a name="M000084"></a>
951
+
952
+ <div class="method-heading">
953
+ <a href="#M000084" class="method-signature">
954
+ <span class="method-name">on_message_statistics</span><span class="method-args">()</span>
955
+ </a>
956
+ </div>
957
+
958
+ <div class="method-description">
959
+ <p>
960
+ Return the statistics for every active <a
961
+ href="Connection.html#M000083">Connection#on_message</a> consumer in an
962
+ Array
963
+ </p>
964
+ <p>
965
+ For details on the contents of each element in the array, see:
966
+ Consumer#on_message_statistics
967
+ </p>
968
+ <p><a class="source-toggle" href="#"
969
+ onclick="toggleCode('M000084-source');return false;">[Source]</a></p>
970
+ <div class="method-source-code" id="M000084-source">
971
+ <pre>
972
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 478</span>
973
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">on_message_statistics</span>
974
+ <span class="ruby-ivar">@consumers</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">consumer</span><span class="ruby-operator">|</span> <span class="ruby-identifier">consumer</span>.<span class="ruby-identifier">on_message_statistics</span> }
975
+ <span class="ruby-keyword kw">end</span>
976
+ </pre>
977
+ </div>
978
+ </div>
979
+ </div>
980
+
981
+ <div id="method-M000073" class="method-detail">
982
+ <a name="M000073"></a>
983
+
984
+ <div class="method-heading">
985
+ <a href="#M000073" class="method-signature">
986
+ <span class="method-name">session</span><span class="method-args">(params={}, &amp;proc)</span>
987
+ </a>
988
+ </div>
989
+
990
+ <div class="method-description">
991
+ <p>
992
+ Create a <a href="Connection.html#M000068">session</a> over this
993
+ connection. It is recommended to create separate sessions for each thread
994
+ If a block of code is passed in, it will be called and then the <a
995
+ href="Connection.html#M000068">session</a> is automatically closed on
996
+ completion of the code block
997
+ </p>
998
+ <p>
999
+ Parameters:
1000
+ </p>
1001
+ <pre>
1002
+ :transacted =&gt; true or false
1003
+ Determines whether transactions are supported within this session.
1004
+ I.e. Whether commit or rollback can be called
1005
+ Default: false
1006
+ Note: :options below are ignored if this value is set to :true
1007
+
1008
+ :options =&gt; any of the JMS::Session constants:
1009
+ Note: :options are ignored if :transacted =&gt; true
1010
+ JMS::Session::AUTO_ACKNOWLEDGE
1011
+ With this acknowledgment mode, the session automatically acknowledges
1012
+ a client's receipt of a message either when the session has successfully
1013
+ returned from a call to receive or when the message listener the session has
1014
+ called to process the message successfully returns.
1015
+ JMS::Session::CLIENT_ACKNOWLEDGE
1016
+ With this acknowledgment mode, the client acknowledges a consumed
1017
+ message by calling the message's acknowledge method.
1018
+ JMS::Session::DUPS_OK_ACKNOWLEDGE
1019
+ This acknowledgment mode instructs the session to lazily acknowledge
1020
+ the delivery of messages.
1021
+ JMS::Session::SESSION_TRANSACTED
1022
+ This value is returned from the method getAcknowledgeMode if the
1023
+ session is transacted.
1024
+ Default: JMS::Session::AUTO_ACKNOWLEDGE
1025
+ </pre>
1026
+ <p><a class="source-toggle" href="#"
1027
+ onclick="toggleCode('M000073-source');return false;">[Source]</a></p>
1028
+ <div class="method-source-code" id="M000073-source">
1029
+ <pre>
1030
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 263</span>
1031
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>(<span class="ruby-identifier">params</span>={}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">proc</span>)
1032
+ <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Missing mandatory Block when calling JMS::Connection#session&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">proc</span>
1033
+ <span class="ruby-identifier">session</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">create_session</span>(<span class="ruby-identifier">params</span>)
1034
+ <span class="ruby-keyword kw">begin</span>
1035
+ <span class="ruby-identifier">proc</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">session</span>)
1036
+ <span class="ruby-keyword kw">ensure</span>
1037
+ <span class="ruby-identifier">session</span>.<span class="ruby-identifier">close</span>
1038
+ <span class="ruby-keyword kw">end</span>
1039
+ <span class="ruby-keyword kw">end</span>
1040
+ </pre>
1041
+ </div>
1042
+ </div>
1043
+ </div>
1044
+
1045
+ <div id="method-M000071" class="method-detail">
1046
+ <a name="M000071"></a>
1047
+
1048
+ <div class="method-heading">
1049
+ <a href="#M000071" class="method-signature">
1050
+ <span class="method-name">start</span><span class="method-args">()</span>
1051
+ </a>
1052
+ </div>
1053
+
1054
+ <div class="method-description">
1055
+ <p>
1056
+ Start (or restart) delivery of incoming messages over this connection. By
1057
+ default no messages are delivered until this method is called explicitly
1058
+ Delivery of messages to any asynchronous Destination::each() call will only
1059
+ <a href="Connection.html#M000067">start</a> after Connection::start is
1060
+ called, or <a href="Connection.html#M000067">Connection.start</a> is used
1061
+ </p>
1062
+ <p><a class="source-toggle" href="#"
1063
+ onclick="toggleCode('M000071-source');return false;">[Source]</a></p>
1064
+ <div class="method-source-code" id="M000071-source">
1065
+ <pre>
1066
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 221</span>
1067
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start</span>
1068
+ <span class="ruby-ivar">@jms_connection</span>.<span class="ruby-identifier">start</span>
1069
+ <span class="ruby-keyword kw">end</span>
1070
+ </pre>
1071
+ </div>
1072
+ </div>
1073
+ </div>
1074
+
1075
+ <div id="method-M000072" class="method-detail">
1076
+ <a name="M000072"></a>
1077
+
1078
+ <div class="method-heading">
1079
+ <a href="#M000072" class="method-signature">
1080
+ <span class="method-name">stop</span><span class="method-args">()</span>
1081
+ </a>
1082
+ </div>
1083
+
1084
+ <div class="method-description">
1085
+ <p>
1086
+ Temporarily <a href="Connection.html#M000072">stop</a> delivery of incoming
1087
+ messages on this connection Useful during a hot code update or other
1088
+ changes that need to be completed without any <a
1089
+ href="Connection.html#M000070">new</a> messages being processed Call <a
1090
+ href="Connection.html#M000067">start</a>() to resume receiving messages
1091
+ </p>
1092
+ <p><a class="source-toggle" href="#"
1093
+ onclick="toggleCode('M000072-source');return false;">[Source]</a></p>
1094
+ <div class="method-source-code" id="M000072-source">
1095
+ <pre>
1096
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 229</span>
1097
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop</span>
1098
+ <span class="ruby-ivar">@jms_connection</span>.<span class="ruby-identifier">stop</span>
1099
+ <span class="ruby-keyword kw">end</span>
1100
+ </pre>
1101
+ </div>
1102
+ </div>
1103
+ </div>
1104
+
1105
+ <div id="method-M000082" class="method-detail">
1106
+ <a name="M000082"></a>
1107
+
1108
+ <div class="method-heading">
1109
+ <a href="#M000082" class="method-signature">
1110
+ <span class="method-name">to_s</span><span class="method-args">()</span>
1111
+ </a>
1112
+ </div>
1113
+
1114
+ <div class="method-description">
1115
+ <p>
1116
+ Return a string describing the <a href="../JMS.html">JMS</a> provider and
1117
+ version
1118
+ </p>
1119
+ <p><a class="source-toggle" href="#"
1120
+ onclick="toggleCode('M000082-source');return false;">[Source]</a></p>
1121
+ <div class="method-source-code" id="M000082-source">
1122
+ <pre>
1123
+ <span class="ruby-comment cmt"># File lib/jms/connection.rb, line 370</span>
1124
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span>
1125
+ <span class="ruby-identifier">md</span> = <span class="ruby-ivar">@jms_connection</span>.<span class="ruby-identifier">getMetaData</span>
1126
+ <span class="ruby-node">&quot;JMS::Connection provider: #{md.getJMSProviderName} v#{md.getProviderVersion}, JMS v#{md.getJMSVersion}&quot;</span>
1127
+ <span class="ruby-keyword kw">end</span>
1128
+ </pre>
1129
+ </div>
1130
+ </div>
1131
+ </div>
1132
+
1133
+
1134
+ </div>
1135
+
1136
+
1137
+ </div>
1138
+
1139
+
1140
+ <div id="validator-badges">
1141
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
1142
+ </div>
1143
+
1144
+ </body>
1145
+ </html>