jruby-jms 1.1.0-java → 1.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +24 -7
  3. data/README.md +49 -49
  4. data/Rakefile +17 -12
  5. data/lib/jms.rb +8 -17
  6. data/lib/jms/bytes_message.rb +3 -19
  7. data/lib/jms/connection.rb +63 -83
  8. data/lib/jms/map_message.rb +9 -25
  9. data/lib/jms/message.rb +22 -173
  10. data/lib/jms/message_consumer.rb +23 -35
  11. data/lib/jms/message_listener_impl.rb +22 -38
  12. data/lib/jms/message_producer.rb +9 -25
  13. data/lib/jms/mq_workaround.rb +11 -26
  14. data/lib/jms/object_message.rb +1 -17
  15. data/lib/jms/oracle_a_q_connection_factory.rb +4 -21
  16. data/lib/jms/queue_browser.rb +2 -18
  17. data/lib/jms/session.rb +92 -106
  18. data/lib/jms/session_pool.rb +34 -41
  19. data/lib/jms/text_message.rb +0 -16
  20. data/lib/jms/version.rb +1 -1
  21. data/test/connection_test.rb +35 -81
  22. data/test/jms.yml +18 -8
  23. data/test/message_test.rb +27 -43
  24. data/test/session_pool_test.rb +30 -46
  25. data/test/session_test.rb +30 -45
  26. data/test/test_helper.rb +33 -0
  27. metadata +20 -26
  28. data/Gemfile +0 -8
  29. data/Gemfile.lock +0 -36
  30. data/examples/advanced/session_pool.rb +0 -37
  31. data/examples/client-server/replier.rb +0 -29
  32. data/examples/client-server/requestor.rb +0 -40
  33. data/examples/file-to-q/files_to_q.rb +0 -51
  34. data/examples/file-to-q/q_to_files.rb +0 -44
  35. data/examples/invm/invm.rb +0 -44
  36. data/examples/invm/log4j.properties +0 -58
  37. data/examples/jms.yml +0 -149
  38. data/examples/performance/consumer.rb +0 -25
  39. data/examples/performance/producer.rb +0 -31
  40. data/examples/producer-consumer/browser.rb +0 -24
  41. data/examples/producer-consumer/consumer.rb +0 -24
  42. data/examples/producer-consumer/consumer_async.rb +0 -41
  43. data/examples/producer-consumer/producer.rb +0 -25
  44. data/examples/publish-subscribe/publish.rb +0 -24
  45. data/examples/publish-subscribe/subscribe.rb +0 -31
  46. data/lib/jms/logging.rb +0 -50
  47. data/nbproject/private/private.properties +0 -3
  48. data/nbproject/private/rake-d.txt +0 -5
  49. data/parallel_minion.gemspec +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 601d2d745dab0bb052eaf0516faabda7afcc4ef3
4
- data.tar.gz: 66a1ea9158a02a782acb728c890c4654c48cb67c
3
+ metadata.gz: c58dfbbab766a5b4ad1f7f383e256294e658089f
4
+ data.tar.gz: 7ec282e9a6f7b9ab24fa9502be32c7a16f66a2ea
5
5
  SHA512:
6
- metadata.gz: b0a7f76e0fc27018d8de20761f57be8f181a5c3aac528e657df4cfe8943db3ad0efaa5485c79a5d5d911495229090fd2088dd530091f3d81fd8dd12f03aa3eeb
7
- data.tar.gz: 1970f9dabe77b456b70e1cd8ed519db44d827a6b9e245fc04e143b6f631344869bfc6d9f5db9d8bd1ccff223258e0cb195369ca32d4a6f914437eaa369a85981
6
+ metadata.gz: 7099c5bc513f3616e5a01073671a2e40cc33b7a697e6807cf7c4ada87d76ae61a8c0056397e5bc72bfb6aeeac5df58f448c2c9946d20fc64580884b7b6db2c77
7
+ data.tar.gz: bda4d42a7fa8f4f299e9120042caf7e707117fe755628edd7ad167ec4ba65a9a0c1f053be5ff4de54b8a2f3f99a8b7e4ad8dceacb6f47ea1aa11c692c3abe636
data/HISTORY.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## 1.2.0 (2015-08-29)
2
+
3
+ * Tested against JRuby 9.0.0.0
4
+ * Drop support for JRuby 1.5 and 1.6
5
+ * Tested against ActiveMQ 5.11, and HornetQ 2.4
6
+ * Raises ArgumentError instead of RuntimeError for missing arguments
7
+ * Update tests
8
+ * Upgrade to Minitest 5.8
9
+ * Switch to Ruby 1.9 hash syntax
10
+ * Reformat code
11
+
12
+ ## 1.1.0 (2014-04-10)
13
+
14
+ * Support Oracle AQ 11gR2
15
+ * Tibco EMS Examples
16
+ * Add .gemspec file
17
+
1
18
  ## 1.0.0 (2012-10-21)
2
19
 
3
20
  * Issue #10 Support WebSphereMQ V7
@@ -18,16 +35,16 @@
18
35
 
19
36
  * Compatibility with JRuby 1.6
20
37
  * I hate doing this, but unfortunately there is a small breaking change in this release:
21
- ** We can no longer pass symbols into the following methods:
22
- *** jms_delivery_mode
23
- *** jms_delivery_mode=
24
- ** Just rename existing uses of the above methods to:
25
- *** jms_delivery_mode_sym
26
- *** jms_delivery_mode_sym=
38
+ * We can no longer pass symbols into the following methods:
39
+ * jms_delivery_mode
40
+ * jms_delivery_mode=
41
+ * Just rename existing uses of the above methods to:
42
+ * jms_delivery_mode_sym
43
+ * jms_delivery_mode_sym=
27
44
  * Added Session Pool - requires GenePool as a dependency if used
28
45
  * Generate warning log entry for any parameters not known to the ConnectionFactory
29
46
  * Use java_import for all javax.jms classes
30
- ** Rename all Java source files to match new names
47
+ * Rename all Java source files to match new names
31
48
 
32
49
  ## 0.10.1 (2011-02-21)
33
50
 
data/README.md CHANGED
@@ -2,14 +2,18 @@
2
2
 
3
3
  * http://github.com/reidmorrison/jruby-jms
4
4
 
5
- ### Introduction
5
+ jruby-jms is a complete JRuby API into Java Messaging Specification (JMS) V1.1.
6
+
7
+ Note: jruby-jms is for JRuby only.
8
+
9
+ ### Design
6
10
 
7
11
  jruby-jms attempts to "rubify" the Java JMS API without
8
12
  compromising performance. It does this by sprinkling "Ruby-goodness" into the
9
13
  existing JMS Java interfaces, I.e. By adding Ruby methods to the existing
10
14
  classes and interfaces. Since jruby-jms exposes the JMS
11
15
  Java classes directly there is no performance impact that would have been
12
- introduced had the entire API been wrapped in a Ruby layer.
16
+ introduced had the entire API been wrapped with an extra Ruby layer.
13
17
 
14
18
  In this way, using regular Ruby constructs a Ruby program can easily
15
19
  interact with JMS in a highly performant way. Also, in this way you are not
@@ -18,7 +22,23 @@ API is available to you at any time.
18
22
 
19
23
  ### Install
20
24
 
21
- jgem install jruby-jms
25
+ Add to Gemfile if using bundler:
26
+
27
+ ```ruby
28
+ gem 'jruby-jms'
29
+ ```
30
+
31
+ Install using bundler:
32
+
33
+ bundle
34
+
35
+ If not using Bundler:
36
+
37
+ gem install jruby-jms
38
+
39
+ ### Documentation
40
+
41
+ * [API Reference](http://www.rubydoc.info/gems/jruby-jms)
22
42
 
23
43
  ### Simplification
24
44
 
@@ -56,7 +76,7 @@ for passing messages between threads in the same JVM.
56
76
 
57
77
  In order to connect to any broker the Client JMS application must create a
58
78
  connection. In traditional JMS a ConnectionFactory is used to create connections.
59
- In jruby-jms the JMS::Connection takes care of the complexities of dealing with
79
+ In jruby-jms the `JMS::Connection` takes care of the complexities of dealing with
60
80
  the factory class, just pass the required parameters to Connection.new and
61
81
  jruby-jms takes care of the rest.
62
82
 
@@ -79,23 +99,21 @@ Producers write messages to queues or topics
79
99
  ActiveMQ Example:
80
100
 
81
101
  ```ruby
82
- require 'rubygems'
83
102
  require 'jms'
84
103
 
85
104
  # Connect to ActiveMQ
86
105
  config = {
87
- :factory => 'org.apache.activemq.ActiveMQConnectionFactory',
88
- :broker_url => 'tcp://localhost:61616',
89
- :require_jars => [
90
- "~/Applications/apache-activemq-5.7.0/activemq-all-5.7.0.jar",
91
- "~/Applications/apache-activemq-5.5.0/lib/optional/log4j-1.2.17.jar"
92
- ]
106
+ :factory: org.apache.activemq.ActiveMQConnectionFactory
107
+ :broker_url: tcp://localhost:61616
108
+ :require_jars:
109
+ - /usr/local/Cellar/activemq/5.11.1/libexec/activemq-all-5.11.1.jar
110
+ - /usr/local/Cellar/activemq/5.11.1/libexec/lib/optional/log4j-1.2.17.jar
93
111
  }
94
112
 
95
113
  JMS::Connection.session(config) do |session|
96
- session.producer(:queue_name => 'ExampleQueue') do |producer|
114
+ session.producer(queue_name: 'ExampleQueue') do |producer|
97
115
  producer.send(session.message("Hello World"))
98
- end
116
+ end
99
117
  end
100
118
  ```
101
119
 
@@ -111,34 +129,32 @@ require 'jms'
111
129
 
112
130
  # Connect to ActiveMQ
113
131
  config = {
114
- :factory => 'org.apache.activemq.ActiveMQConnectionFactory',
115
- :broker_url => 'tcp://localhost:61616',
116
- :require_jars => [
117
- "~/Applications/apache-activemq-5.7.0/activemq-all-5.7.0.jar",
118
- "~/Applications/apache-activemq-5.5.0/lib/optional/log4j-1.2.17.jar"
119
- ]
132
+ :factory: org.apache.activemq.ActiveMQConnectionFactory
133
+ :broker_url: tcp://localhost:61616
134
+ :require_jars:
135
+ - /usr/local/Cellar/activemq/5.11.1/libexec/activemq-all-5.11.1.jar
136
+ - /usr/local/Cellar/activemq/5.11.1/libexec/lib/optional/log4j-1.2.17.jar
120
137
  }
121
138
 
122
139
  JMS::Connection.session(config) do |session|
123
- session.consume(:queue_name => 'ExampleQueue', :timeout=>1000) do |message|
140
+ session.consume(queue_name: 'ExampleQueue', timeout: 1000) do |message|
124
141
  p message
125
- end
142
+ end
126
143
  end
127
144
  ```
128
145
 
129
- ## Overview
146
+ ## More Examples
130
147
 
131
- jruby-jms is a complete JRuby API into the Java Messaging Specification (JMS) V1.1
132
- followed by several JMS Providers.
148
+ There are several more examples available at https://github.com/reidmorrison/jruby-jms/tree/master/examples
133
149
 
134
150
  ## Threading
135
151
 
136
- A JMS::Connection instance can be shared between threads, whereas a session,
152
+ A `JMS::Connection` instance can be shared between threads, whereas a session,
137
153
  consumer, producer, and any artifacts created by the session should only be
138
154
  used by one thread at a time.
139
155
 
140
156
  For consumers, it is recommended to create a session for each thread and leave
141
- that thread blocked on Consumer.receive. Or, even better use Connection.on_message
157
+ that thread blocked on `Consumer#receive`. Or, even better use `Connection#on_message`
142
158
  which will create a session, within which any message received from the specified
143
159
  queue or topic will be passed to the block.
144
160
 
@@ -146,7 +162,7 @@ queue or topic will be passed to the block.
146
162
 
147
163
  jruby-jms detects the logging available in the current environment.
148
164
  When running under Rails it will use the Rails logger, otherwise it will use the
149
- standard Ruby logger. The logger can also be replaced by calling Connection.logger=
165
+ standard Ruby logger. The logger can also be replaced by calling `JMS.logger=`
150
166
 
151
167
  ## Dependencies
152
168
 
@@ -154,35 +170,19 @@ standard Ruby logger. The logger can also be replaced by calling Connection.logg
154
170
 
155
171
  In order to communicate with a JMS V 1.1 provider jruby-jms needs the jar files supplied
156
172
  by the JMS provider. As in the examples above the jar files can be specified in
157
- the configuration element :require_jars. Otherwise, the jars must be explicitly
173
+ the configuration element `:require_jars`. Otherwise, the jars must be explicitly
158
174
  required in the Ruby code:
159
175
 
160
176
  ```ruby
161
- require "~/Applications/apache-activemq-5.7.0/activemq-all-5.7.0.jar"
177
+ require '/usr/local/Cellar/activemq/5.11.1/libexec/activemq-all-5.11.1.jar'
178
+ require '/usr/local/Cellar/activemq/5.11.1/libexec/lib/optional/log4j-1.2.17.jar'
162
179
  ```
163
180
 
164
181
  ### JRuby
165
182
 
166
- jruby-jms has been tested against JRuby 1.5.1, 1.6.1, and 1.7.0 RC2
167
-
168
- ## Contributing
169
-
170
- Once you've made your great commits:
171
-
172
- 1. [Fork](http://help.github.com/forking/) jruby-jms
173
- 2. Create a topic branch - `git checkout -b my_branch`
174
- 3. Push to your branch - `git push origin my_branch`
175
- 4. Create an [Issue](http://github.com/reidmorrison/jruby-jms/issues) with a link to your branch
176
- 5. That's it!
177
-
178
- ## Meta
179
-
180
- * Code: `git clone git://github.com/reidmorrison/jruby-jms.git`
181
- * Home: <http://github.com/reidmorrison/jruby-jms>
182
- * Bugs: <http://github.com/reidmorrison/jruby-jms/issues>
183
- * Gems: <http://rubygems.org/gems/jruby-jms>
183
+ jruby-jms has been tested against JRuby 1.7, and JRuby 9.0.0.0
184
184
 
185
- This project uses [Semantic Versioning](http://semver.org/).
185
+ ## Versioning
186
186
 
187
187
  ## Author
188
188
 
@@ -190,7 +190,7 @@ Reid Morrison :: reidmo@gmail.com :: @reidmorrison
190
190
 
191
191
  ## License
192
192
 
193
- Copyright 2008 - 2012 J. Reid Morrison
193
+ Copyright 2008 - 2015 J. Reid Morrison
194
194
 
195
195
  Licensed under the Apache License, Version 2.0 (the "License");
196
196
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -1,20 +1,23 @@
1
- lib = File.expand_path('../lib/', __FILE__)
2
- $:.unshift lib unless $:.include?(lib)
3
-
4
- raise "jruby-jms must be built with JRuby: try again with `jruby -S rake'" unless defined?(JRUBY_VERSION)
5
-
6
- require 'rubygems'
7
- require 'rubygems/package'
8
1
  require 'rake/clean'
9
2
  require 'rake/testtask'
3
+
4
+ raise 'jruby-jms must be built with JRuby' unless defined?(JRUBY_VERSION)
5
+
6
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
10
7
  require 'jms/version'
11
8
 
12
- desc "Build gem"
13
- task :gem do |t|
14
- Gem::Package.build(Gem::Specification.load('parallel_minion.gemspec'))
9
+ task :gem do
10
+ system 'gem build jruby-jms.gemspec'
15
11
  end
16
12
 
17
- desc "Run Test Suite"
13
+ task :publish => :gem do
14
+ system "git tag -a v#{JMS::VERSION} -m 'Tagging #{JMS::VERSION}'"
15
+ system 'git push --tags'
16
+ system "gem push jruby-jms-#{JMS::VERSION}-java.gem"
17
+ system "rm jruby-jms-#{JMS::VERSION}-java.gem"
18
+ end
19
+
20
+ desc 'Run Test Suite'
18
21
  task :test do
19
22
  Rake::TestTask.new(:functional) do |t|
20
23
  t.test_files = FileList['test/*_test.rb']
@@ -24,7 +27,9 @@ task :test do
24
27
  Rake::Task['functional'].invoke
25
28
  end
26
29
 
27
- desc "Generate RDOC documentation"
30
+ task :default => :test
31
+
32
+ desc 'Generate RDOC documentation'
28
33
  task :doc do
29
34
  system "rdoc --main README.md --inline-source --quiet README.md `find lib -name '*.rb'`"
30
35
  end
data/lib/jms.rb CHANGED
@@ -1,20 +1,11 @@
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
1
  require 'java'
18
2
  require 'jms/version'
19
- require 'jms/logging'
20
3
  require 'jms/connection'
4
+ require 'semantic_logger'
5
+
6
+ module JMS
7
+ # Add Logging capabilities
8
+ include SemanticLogger::Loggable
9
+
10
+ autoload :SessionPool, 'jms/session_pool'
11
+ end
@@ -1,20 +1,4 @@
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
- #Interface javax.jms.BytesMessage
1
+ # Interface javax.jms.BytesMessage
18
2
  module JMS::BytesMessage
19
3
  def data
20
4
  # Puts the message body in read-only mode and repositions the stream of
@@ -25,9 +9,9 @@ module JMS::BytesMessage
25
9
 
26
10
  return nil if available == 0
27
11
 
28
- result = ""
12
+ result = ''
29
13
  bytes_size = 1024
30
- bytes = Java::byte[bytes_size].new
14
+ bytes = Java::byte[bytes_size].new
31
15
 
32
16
  while (n = available < bytes_size ? available : bytes_size) > 0
33
17
  self.read_bytes(bytes, n)
@@ -1,19 +1,4 @@
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
-
1
+ require 'semantic_logger'
17
2
  # Module: Java Messaging System (JMS) Interface
18
3
  module JMS
19
4
  # Every JMS session must have at least one Connection instance
@@ -32,12 +17,11 @@ module JMS
32
17
  # require 'jms'
33
18
  #
34
19
  # JMS::Connection.create_session(
35
- # :factory => 'org.apache.activemq.ActiveMQConnectionFactory',
36
- # :broker_url => 'tcp://localhost:61616',
37
- # :require_jars => [
38
- # '~/Applications/apache-activemq-5.5.0/activemq-all-5.5.0.jar',
39
- # '~/Applications/apache-activemq-5.5.0/lib/optional/slf4j-log4j12-1.5.11.jar',
40
- # '~/Applications/apache-activemq-5.5.0/lib/optional/log4j-1.2.14.jar',
20
+ # factory: 'org.apache.activemq.ActiveMQConnectionFactory',
21
+ # broker_url: 'tcp://localhost:61616',
22
+ # require_jars: [
23
+ # '/usr/local/Cellar/activemq/5.11.1/libexec/activemq-all-5.11.1.jar',
24
+ # '/usr/local/Cellar/activemq/5.11.1/libexec/lib/optional/log4j-1.2.17.jar'
41
25
  # ]
42
26
  # ) do |session|
43
27
  # session.consumer(:queue_name=>'TEST') do |consumer|
@@ -55,16 +39,18 @@ module JMS
55
39
  # See: http://download.oracle.com/javaee/6/api/javax/jms/Connection.html
56
40
  #
57
41
  class Connection
42
+ include SemanticLogger::Loggable
43
+
58
44
  # Create a connection to the JMS provider, start the connection,
59
45
  # call the supplied code block, then close the connection upon completion
60
46
  #
61
47
  # Returns the result of the supplied block
62
- def self.start(params = {}, &proc)
63
- raise "Missing mandatory Block when calling JMS::Connection.start" unless proc
48
+ def self.start(params = {}, &block)
49
+ raise(ArgumentError, 'Missing mandatory Block when calling JMS::Connection.start') unless block
64
50
  connection = Connection.new(params)
65
51
  connection.start
66
52
  begin
67
- proc.call(connection)
53
+ block.call(connection)
68
54
  ensure
69
55
  connection.close
70
56
  end
@@ -80,9 +66,9 @@ module JMS
80
66
  # Note: It is important that each thread have its own session to support transactions
81
67
  # This method will also start the session immediately so that any
82
68
  # consumers using this session will start immediately
83
- def self.session(params = {}, &proc)
69
+ def self.session(params = {}, &block)
84
70
  self.start(params) do |connection|
85
- connection.session(params, &proc)
71
+ connection.session(params, &block)
86
72
  end
87
73
  end
88
74
 
@@ -100,15 +86,13 @@ module JMS
100
86
  # to load for this JMS Provider
101
87
  #
102
88
  # Returns nil
103
- #
104
- # TODO make this a class method
105
89
  def fetch_dependencies(jar_list)
106
90
  jar_list.each do |jar|
107
- JMS::logger.debug "Loading Jar File:#{jar}"
91
+ logger.debug "Loading Jar File:#{jar}"
108
92
  begin
109
93
  require jar
110
94
  rescue Exception => exc
111
- JMS::logger.error "Failed to Load Jar File:#{jar}. #{exc.to_s}"
95
+ logger.error "Failed to Load Jar File:#{jar}", exc
112
96
  end
113
97
  end if jar_list
114
98
 
@@ -139,21 +123,21 @@ module JMS
139
123
  # 2. Supply an instance of the JMS Provider class itself
140
124
  # 3. Use a JNDI lookup to return the JMS Provider Factory class
141
125
  # Parameters:
142
- # :factory => String: Name of JMS Provider Factory class
143
- # => Class: JMS Provider Factory class itself
126
+ # factory: [String] Name of JMS Provider Factory class
127
+ # [Class] JMS Provider Factory class itself
144
128
  #
145
- # :jndi_name => String: Name of JNDI entry at which the Factory can be found
146
- # :jndi_context => Mandatory if jndi lookup is being used, contains details
147
- # on how to connect to JNDI server etc.
129
+ # jndi_name: [String] Name of JNDI entry at which the Factory can be found
130
+ # jndi_context: Mandatory if jndi lookup is being used, contains details
131
+ # on how to connect to JNDI server etc.
148
132
  #
149
- # :require_jars => An optional array of Jar file names to load for the specified
150
- # JMS provider. By using this option it is not necessary
151
- # to put all the JMS Provider specific jar files into the
152
- # environment variable CLASSPATH prior to starting JRuby
133
+ # require_jars: [Array<String>] An optional array of Jar file names to load for the specified
134
+ # JMS provider. By using this option it is not necessary
135
+ # to put all the JMS Provider specific jar files into the
136
+ # environment variable CLASSPATH prior to starting JRuby
153
137
  #
154
- # :username => Username to connect to JMS provider with
155
- # :password => Password to use when to connecting to the JMS provider
156
- # Note: :password is ignored if :username is not supplied
138
+ # username: [String] Username to connect to JMS provider with
139
+ # password: [String] Password to use when to connecting to the JMS provider
140
+ # Note: :password is ignored if :username is not supplied
157
141
  #
158
142
  # :factory and :jndi_name are mutually exclusive, both cannot be supplied at the
159
143
  # same time. :factory takes precedence over :jndi_name
@@ -162,10 +146,9 @@ module JMS
162
146
  # has setters for those properties.
163
147
  #
164
148
  # For some known examples, see: [Example jms.yml](https://github.com/reidmorrison/jruby-jms/blob/master/examples/jms.yml)
165
- #
166
149
  def initialize(params = {})
167
- # Used by ::on_message
168
- @sessions = []
150
+ # Used by #on_message
151
+ @sessions = []
169
152
  @consumers = []
170
153
 
171
154
  options = params.dup
@@ -175,19 +158,17 @@ module JMS
175
158
  fetch_dependencies(options.delete(:require_jars))
176
159
 
177
160
  connection_factory = nil
178
- factory = options.delete(:factory)
161
+ factory = options.delete(:factory)
179
162
  if factory
180
163
  # If factory check if oracle is needed.
181
- if (factory.include? 'AQjmsFactory')
182
- require 'jms/oracle_a_q_connection_factory'
183
- end
164
+ require('jms/oracle_a_q_connection_factory') if factory.include?('AQjmsFactory')
184
165
 
185
166
  # If factory is a string, then it is the name of a class, not the class itself
186
- factory = eval(factory) if factory.respond_to? :to_str
167
+ factory = eval(factory) if factory.respond_to?(:to_str)
187
168
  connection_factory = factory.new
188
169
  elsif jndi_name = options[:jndi_name]
189
- raise "Missing mandatory parameter :jndi_context missing in call to Connection::connect" unless jndi_context = options[:jndi_context]
190
- if jndi_context['java.naming.factory.initial'].include? 'AQjmsInitialContextFactory'
170
+ raise(ArgumentError, 'Missing mandatory parameter :jndi_context in call to Connection::connect') unless jndi_context = options[:jndi_context]
171
+ if jndi_context['java.naming.factory.initial'].include?('AQjmsInitialContextFactory')
191
172
  require 'jms/oracle_a_q_connection_factory'
192
173
  end
193
174
 
@@ -198,21 +179,21 @@ module JMS
198
179
  jndi.close
199
180
  end
200
181
  else
201
- raise "Missing mandatory parameter :factory or :jndi_name missing in call to Connection::connect"
182
+ raise(ArgumentError, 'Missing mandatory parameter :factory or :jndi_name missing in call to Connection::connect')
202
183
  end
203
184
  options.delete(:jndi_name)
204
185
  options.delete(:jndi_context)
205
186
 
206
- JMS::logger.debug "Using Factory: #{connection_factory.java_class}" if connection_factory.respond_to? :java_class
187
+ logger.debug "Using Factory: #{connection_factory.java_class}" if connection_factory.respond_to? :java_class
207
188
  options.each_pair do |key, val|
208
189
  next if [:username, :password].include?(key)
209
190
 
210
191
  method = key.to_s+'='
211
192
  if connection_factory.respond_to? method
212
193
  connection_factory.send method, val
213
- JMS::logger.debug " #{key} = #{connection_factory.send key.to_sym}" if connection_factory.respond_to? key.to_sym
194
+ logger.debug " #{key} = #{connection_factory.send key.to_sym}" if connection_factory.respond_to? key.to_sym
214
195
  else
215
- JMS::logger.warn "#{connection_factory.java_class} does not understand option: :#{key}=#{val}, ignoring :#{key}" if connection_factory.respond_to? :java_class
196
+ logger.warn "#{connection_factory.java_class} does not understand option: :#{key}=#{val}, ignoring :#{key}" if connection_factory.respond_to? :java_class
216
197
  end
217
198
  end
218
199
 
@@ -246,14 +227,14 @@ module JMS
246
227
  # closed on completion of the code block
247
228
  #
248
229
  # Parameters:
249
- # :transacted => true or false
230
+ # transacted: [true|false]
250
231
  # Determines whether transactions are supported within this session.
251
232
  # I.e. Whether commit or rollback can be called
252
233
  # Default: false
253
234
  # Note: :options below are ignored if this value is set to :true
254
235
  #
255
- # :options => any of the JMS::Session constants:
256
- # Note: :options are ignored if :transacted => true
236
+ # options: any of the JMS::Session constants:
237
+ # Note: :options are ignored if transacted: true
257
238
  # JMS::Session::AUTO_ACKNOWLEDGE
258
239
  # With this acknowledgment mode, the session automatically acknowledges
259
240
  # a client's receipt of a message either when the session has successfully
@@ -270,11 +251,11 @@ module JMS
270
251
  # session is transacted.
271
252
  # Default: JMS::Session::AUTO_ACKNOWLEDGE
272
253
  #
273
- def session(params={}, &proc)
274
- raise "Missing mandatory Block when calling JMS::Connection#session" unless proc
254
+ def session(params={}, &block)
255
+ raise(ArgumentError, 'Missing mandatory Block when calling JMS::Connection#session') unless block
275
256
  session = self.create_session(params)
276
257
  begin
277
- proc.call(session)
258
+ block.call(session)
278
259
  ensure
279
260
  session.close
280
261
  end
@@ -288,14 +269,14 @@ module JMS
288
269
  # possible
289
270
  #
290
271
  # Parameters:
291
- # :transacted => true or false
272
+ # transacted: true or false
292
273
  # Determines whether transactions are supported within this session.
293
274
  # I.e. Whether commit or rollback can be called
294
275
  # Default: false
295
276
  # Note: :options below are ignored if this value is set to :true
296
277
  #
297
- # :options => any of the JMS::Session constants:
298
- # Note: :options are ignored if :transacted => true
278
+ # options: any of the JMS::Session constants:
279
+ # Note: :options are ignored if transacted: true
299
280
  # JMS::Session::AUTO_ACKNOWLEDGE
300
281
  # With this acknowledgment mode, the session automatically acknowledges
301
282
  # a client's receipt of a message either when the session has successfully
@@ -314,17 +295,17 @@ module JMS
314
295
  #
315
296
  def create_session(params={})
316
297
  transacted = params[:transacted] || false
317
- options = params[:options] || JMS::Session::AUTO_ACKNOWLEDGE
298
+ options = params[:options] || JMS::Session::AUTO_ACKNOWLEDGE
318
299
  @jms_connection.create_session(transacted, options)
319
300
  end
320
301
 
321
302
  # Close connection with the JMS Provider
322
303
  # First close any consumers or sessions that are active as a result of JMS::Connection::on_message
323
304
  def close
324
- @consumers.each {|consumer| consumer.close } if @consumers
305
+ @consumers.each { |consumer| consumer.close } if @consumers
325
306
  @consumers = []
326
307
 
327
- @sessions.each {|session| session.close} if @sessions
308
+ @sessions.each { |session| session.close } if @sessions
328
309
  @session=[]
329
310
 
330
311
  @jms_connection.close if @jms_connection
@@ -390,14 +371,14 @@ module JMS
390
371
  # can then be processed.
391
372
  #
392
373
  # Session Parameters:
393
- # :transacted => true or false
374
+ # transacted: true or false
394
375
  # Determines whether transactions are supported within this session.
395
376
  # I.e. Whether commit or rollback can be called
396
377
  # Default: false
397
378
  # Note: :options below are ignored if this value is set to :true
398
379
  #
399
- # :options => any of the JMS::Session constants:
400
- # Note: :options are ignored if :transacted => true
380
+ # options: any of the JMS::Session constants:
381
+ # Note: :options are ignored if transacted: true
401
382
  # JMS::Session::AUTO_ACKNOWLEDGE
402
383
  # With this acknowledgment mode, the session automatically acknowledges
403
384
  # a client's receipt of a message either when the session has successfully
@@ -423,20 +404,20 @@ module JMS
423
404
  # Default: 1
424
405
  #
425
406
  # Consumer Parameters:
426
- # :queue_name => String: Name of the Queue to return
427
- # Symbol: :temporary => Create temporary queue
407
+ # queue_name: String: Name of the Queue to return
408
+ # Symbol: temporary: Create temporary queue
428
409
  # Mandatory unless :topic_name is supplied
429
410
  # Or,
430
- # :topic_name => String: Name of the Topic to write to or subscribe to
431
- # Symbol: :temporary => Create temporary topic
411
+ # topic_name: String: Name of the Topic to write to or subscribe to
412
+ # Symbol: temporary: Create temporary topic
432
413
  # Mandatory unless :queue_name is supplied
433
414
  # Or,
434
- # :destination=> Explicit javaxJms::Destination to use
415
+ # destination:Explicit javaxJms::Destination to use
435
416
  #
436
- # :selector => Filter which messages should be returned from the queue
417
+ # selector: Filter which messages should be returned from the queue
437
418
  # Default: All messages
438
419
  #
439
- # :no_local => Determine whether messages published by its own connection
420
+ # no_local: Determine whether messages published by its own connection
440
421
  # should be delivered to the supplied block
441
422
  # Default: false
442
423
  #
@@ -447,7 +428,7 @@ module JMS
447
428
  # or when Destination::statistics is called. In this case MessageConsumer::statistics
448
429
  # can be called several times during processing without affecting the end time.
449
430
  # Also, the start time and message count is not reset until MessageConsumer::each
450
- # is called again with :statistics => true
431
+ # is called again with statistics: true
451
432
  #
452
433
  # Usage: For transacted sessions the block supplied must return either true or false:
453
434
  # true => The session is committed
@@ -458,11 +439,11 @@ module JMS
458
439
  # since on_message will Not be called if the connection is lost
459
440
  #
460
441
  def on_message(params, &block)
461
- raise "JMS::Connection must be connected prior to calling JMS::Connection::on_message" unless @sessions && @consumers
442
+ raise 'JMS::Connection must be connected prior to calling JMS::Connection::on_message' unless @sessions && @consumers
462
443
 
463
444
  consumer_count = params[:session_count] || 1
464
445
  consumer_count.times do
465
- session = self.create_session(params)
446
+ session = self.create_session(params)
466
447
  consumer = session.consumer(params)
467
448
  if session.transacted?
468
449
  consumer.on_message(params) do |message|
@@ -520,7 +501,6 @@ module JMS
520
501
  # producer.send(session.message("Hello World"))
521
502
  # end
522
503
  def create_session_pool(params={})
523
- require 'jms/session_pool' unless defined? JMS::SessionPool
524
504
  JMS::SessionPool.new(self, params)
525
505
  end
526
506