stomp 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,11 @@
1
+ == 1.2.6 20120913
2
+
3
+ * Provide ability to eliminate checks for closed in protocol methods
4
+ * Cover ssl.connect with connection timeout parameter
5
+ * If heartbeat send raises, do not reraise unless client requests that
6
+ * Remove methods that invoke __send__
7
+ * Move internal methods to 'private'
8
+
1
9
  == 1.2.5 20120804
2
10
 
3
11
  * Issue #48 any forks with modifications will be affected!
@@ -10,6 +10,7 @@ An implementation of the Stomp protocol for Ruby. See:
10
10
 
11
11
  ===New
12
12
 
13
+ * Gem version 1.2.6. Miscellaneous fixes and changes. See _CHANGELOG.rdoc_ for details.
13
14
  * Gem version 1.2.5. Restructure. Forks with modifcations will be affected. See _CHANGELOG.rdoc_ for details.
14
15
  * Gem version 1.2.4. Stomp 1.1 heartbeat fix, autoflush capability, miscellaneous fixes.
15
16
  * Gem version 1.2.3. Miscellaneous fixes, see changelog for details.
@@ -23,23 +24,26 @@ See _CHANGELOG.rdoc_ for details.
23
24
 
24
25
  hash = {
25
26
  :hosts => [
27
+ # First connect is to remotehost1
26
28
  {:login => "login1", :passcode => "passcode1", :host => "remotehost1", :port => 61612, :ssl => true},
29
+ # First failover connect is to remotehost2
27
30
  {:login => "login2", :passcode => "passcode2", :host => "remotehost2", :port => 61613, :ssl => false},
28
31
 
29
32
  ],
30
- # These are the default parameters, don't need to be set
31
- :reliable => true, # true for hash login
32
- :initial_reconnect_delay => 0.01,
33
- :max_reconnect_delay => 30.0,
34
- :use_exponential_back_off => true,
35
- :back_off_multiplier => 2,
36
- :max_reconnect_attempts => 0,
37
- :randomize => false,
38
- :backup => false,
39
- :timeout => -1,
40
- :connect_headers => {},
41
- :parse_timeout => 5,
42
- :logger => nil,
33
+ # These are the default parameters and do not need to be set
34
+ :reliable => true, # reliable (use failover)
35
+ :initial_reconnect_delay => 0.01, # initial delay before reconnect (secs)
36
+ :max_reconnect_delay => 30.0, # max delay before reconnect
37
+ :use_exponential_back_off => true, # increase delay between reconnect attpempts
38
+ :back_off_multiplier => 2, # next delay multiplier
39
+ :max_reconnect_attempts => 0, # retry forever, use # for maximum attempts
40
+ :randomize => false, # do not radomize hosts hash before reconnect
41
+ :connect_headers => {}, # user supplied CONNECT headers (req'd for Stomp 1.1+)
42
+ :parse_timeout => 5, # receive / read timeout, secs
43
+ :logger => nil, # user suplied callback logger instance
44
+ :dmh => false, # do not support multihomed IPV4 / IPV6 hosts during failover
45
+ :closed_check => true, # check first if closed in each protocol method
46
+ :hbser => false, # raise on heartbeat send exception
43
47
  }
44
48
 
45
49
  # for client
@@ -101,8 +105,8 @@ The following people have contributed to Stomp:
101
105
  * jstrachan
102
106
  * Marius Mathiesen <marius.mathiesen@gmail.com>
103
107
  * Johan S√∏rensen <johan@johansorensen.com>
104
- * Thiago Morello <stompgem@gmail.com>
105
- * Guy M. Allard
108
+ * Thiago Morello
109
+ * Guy M. Allard <stompgem@gmail.com>
106
110
  * kookster
107
111
  * Tony Garnock-Jones <tonyg@lshift.net>
108
112
  * chirino
@@ -56,7 +56,6 @@ module Stomp
56
56
  end
57
57
 
58
58
  # A very basic check of required arguments.
59
- # *NOTE* This method will be made private in the next release.
60
59
  def check_arguments!()
61
60
  raise ArgumentError if @host.nil? || @host.empty?
62
61
  raise ArgumentError if @port.nil? || @port == '' || @port < 1 || @port > 65535
@@ -72,8 +71,7 @@ module Stomp
72
71
  new_options[:back_off_multiplier] = (options["backOffMultiplier"] || 2 ).to_i
73
72
  new_options[:max_reconnect_attempts] = (options["maxReconnectAttempts"] || 0 ).to_i
74
73
  new_options[:randomize] = options["randomize"] == "true" # Default: false
75
- new_options[:backup] = false # Not implemented yet: I'm using a master X slave solution
76
- new_options[:timeout] = -1 # Not implemented yet: a "timeout(5) do ... end" would do the trick, feel free
74
+ new_options[:connect_timeout] = 0
77
75
 
78
76
  new_options
79
77
  end
@@ -108,9 +106,11 @@ module Stomp
108
106
  listener.call(message)
109
107
  end
110
108
  end
111
- end
109
+ end # while true
112
110
  end
113
- end
114
- end
115
- end
111
+ end # method start_listeners
112
+
113
+ end # class Client
114
+
115
+ end # module Stomp
116
116
 
@@ -25,7 +25,7 @@ module Stomp
25
25
  # Init.
26
26
 
27
27
  #
28
- @cx = @cy = @sx = @sy = 0, # Variable names as in spec
28
+ @cx = @cy = @sx = @sy = 0 # Variable names as in spec
29
29
 
30
30
  #
31
31
  @hbsend_interval = @hbrecv_interval = 0.0 # Send/Receive ticker interval.
@@ -60,13 +60,13 @@ module Stomp
60
60
 
61
61
  # See if we are doing anything at all.
62
62
 
63
- #
64
63
  @hbs = @hbr = true # Sending/Receiving heartbeats. Assume yes at first.
65
64
  # Check if sending is possible.
66
- @hbs = false if @cx == 0 || @sy == 0
65
+ @hbs = false if @cx == 0 || @sy == 0 # Reset if neither side wants
67
66
  # Check if receiving is possible.
68
- @hbr = false if @sx == 0 || @cy == 0
69
- # Should not do heartbeats at all
67
+ @hbr = false if @sx == 0 || @cy == 0 # Reset if neither side wants
68
+
69
+ # Check if we should not do heartbeats at all
70
70
  return if (!@hbs && !@hbr)
71
71
 
72
72
  # If sending
@@ -115,7 +115,9 @@ module Stomp
115
115
  @logger.on_hbwrite_fail(log_params, {"ticker_interval" => @hbsend_interval,
116
116
  "exception" => sendex})
117
117
  end
118
- raise # Re-raise. What else could be done here?
118
+ if @hbser
119
+ raise # Re-raise if user requested this, otherwise ignore
120
+ end
119
121
  end
120
122
  end
121
123
  end
@@ -167,7 +169,7 @@ module Stomp
167
169
  }
168
170
  end
169
171
 
170
- end # class
172
+ end # class Connection
171
173
 
172
- end # module
174
+ end # module Stomp
173
175
 
@@ -244,11 +244,11 @@ module Stomp
244
244
 
245
245
  Timeout::timeout(@connect_timeout, Stomp::Error::SocketOpenTimeout) do
246
246
  ssl = OpenSSL::SSL::SSLSocket.new(open_tcp_socket, ctx)
247
+ ssl.connect
247
248
  end
248
249
  def ssl.ready?
249
250
  ! @rbuffer.empty? || @io.ready?
250
251
  end
251
- ssl.connect
252
252
  if @ssl != true
253
253
  # Pass back results if possible
254
254
  if RUBY_VERSION =~ /1\.8\.[56]/
@@ -316,7 +316,7 @@ module Stomp
316
316
  @subscriptions.each { |k,v| _transmit(used_socket, Stomp::CMD_SUBSCRIBE, v) }
317
317
  end
318
318
 
319
- end # class
319
+ end # class Connection
320
320
 
321
- end # module
321
+ end # module Stomp
322
322
 
@@ -288,7 +288,7 @@ module Stomp
288
288
  dh
289
289
  end
290
290
 
291
- end # class
291
+ end # class Connection
292
292
 
293
- end # module
293
+ end # module Stomp
294
294
 
@@ -79,7 +79,7 @@ module Stomp
79
79
  _validate_hbheader()
80
80
  end
81
81
 
82
- # _post_connect handles low level logic just post a physical connect.
82
+ # _post_connect handles low level logic just after a physical connect.
83
83
  def _post_connect()
84
84
  return unless (@connect_headers[:"accept-version"] && @connect_headers[:host])
85
85
  return if @connection_frame.command == Stomp::CMD_ERROR
@@ -98,7 +98,136 @@ module Stomp
98
98
  _init_heartbeats()
99
99
  end
100
100
 
101
- end # class
101
+ # socket creates and returns a new socket for use by the connection.
102
+ def socket()
103
+ @socket_semaphore.synchronize do
104
+ used_socket = @socket
105
+ used_socket = nil if closed?
102
106
 
103
- end # module
107
+ while used_socket.nil? || !@failure.nil?
108
+ @failure = nil
109
+ begin
110
+ used_socket = open_socket()
111
+ # Open is complete
112
+ connect(used_socket)
113
+ if @logger && @logger.respond_to?(:on_connected)
114
+ @logger.on_connected(log_params)
115
+ end
116
+ @connection_attempts = 0
117
+ rescue
118
+ @failure = $!
119
+ used_socket = nil
120
+ raise unless @reliable
121
+ raise if @failure.is_a?(Stomp::Error::LoggerConnectionError)
122
+ @closed = true
123
+ if @logger && @logger.respond_to?(:on_connectfail)
124
+ # on_connectfail may raise
125
+ begin
126
+ @logger.on_connectfail(log_params)
127
+ rescue Exception => aex
128
+ raise if aex.is_a?(Stomp::Error::LoggerConnectionError)
129
+ end
130
+ else
131
+ $stderr.print "connect to #{@host} failed: #{$!} will retry(##{@connection_attempts}) in #{@reconnect_delay}\n"
132
+ end
133
+ raise Stomp::Error::MaxReconnectAttempts if max_reconnect_attempts?
134
+
135
+ sleep(@reconnect_delay)
136
+
137
+ @connection_attempts += 1
138
+
139
+ if @parameters
140
+ change_host()
141
+ increase_reconnect_delay()
142
+ end
143
+ end
144
+ end
145
+ @socket = used_socket
146
+ end
147
+ end
148
+
149
+ # refine_params sets up defaults for a Hash initialize.
150
+ def refine_params(params)
151
+ params = params.uncamelize_and_symbolize_keys
152
+ default_params = {
153
+ :connect_headers => {},
154
+ :reliable => true,
155
+ # Failover parameters
156
+ :initial_reconnect_delay => 0.01,
157
+ :max_reconnect_delay => 30.0,
158
+ :use_exponential_back_off => true,
159
+ :back_off_multiplier => 2,
160
+ :max_reconnect_attempts => 0,
161
+ :randomize => false,
162
+ :connect_timeout => 0,
163
+ # Parse Timeout
164
+ :parse_timeout => 5,
165
+ :dmh => false,
166
+ # Closed check logic
167
+ :closed_check => true,
168
+ :hbser => false,
169
+ }
170
+
171
+ res_params = default_params.merge(params)
172
+ if res_params[:dmh]
173
+ res_params = _expand_hosts(res_params)
174
+ end
175
+ return res_params
176
+ end
177
+
178
+ # change_host selects the next host for retires.
179
+ def change_host
180
+ @parameters[:hosts] = @parameters[:hosts].sort_by { rand } if @parameters[:randomize]
181
+
182
+ # Set first as master and send it to the end of array
183
+ current_host = @parameters[:hosts].shift
184
+ @parameters[:hosts] << current_host
185
+
186
+ @ssl = current_host[:ssl]
187
+ @host = current_host[:host]
188
+ @port = current_host[:port] || Connection::default_port(@ssl)
189
+ @login = current_host[:login] || ""
190
+ @passcode = current_host[:passcode] || ""
191
+
192
+ end
193
+
194
+ # max_reconnect_attempts? returns nil or the number of maximum reconnect
195
+ # attempts.
196
+ def max_reconnect_attempts?
197
+ !(@parameters.nil? || @parameters[:max_reconnect_attempts].nil?) && @parameters[:max_reconnect_attempts] != 0 && @connection_attempts >= @parameters[:max_reconnect_attempts]
198
+ end
199
+
200
+ # increase_reconnect_delay increases the reconnect delay for the next connection
201
+ # attempt.
202
+ def increase_reconnect_delay
203
+
204
+ @reconnect_delay *= @parameters[:back_off_multiplier] if @parameters[:use_exponential_back_off]
205
+ @reconnect_delay = @parameters[:max_reconnect_delay] if @reconnect_delay > @parameters[:max_reconnect_delay]
206
+
207
+ @reconnect_delay
208
+ end
209
+
210
+ # __old_receive receives a frame, blocks until the frame is received.
211
+ def __old_receive()
212
+ # The receive may fail so we may need to retry.
213
+ while TRUE
214
+ begin
215
+ used_socket = socket
216
+ return _receive(used_socket)
217
+ rescue
218
+ @failure = $!
219
+ raise unless @reliable
220
+ errstr = "receive failed: #{$!}"
221
+ if @logger && @logger.respond_to?(:on_miscerr)
222
+ @logger.on_miscerr(log_params, errstr)
223
+ else
224
+ $stderr.print errstr
225
+ end
226
+ end
227
+ end
228
+ end
229
+
230
+ end # class Connection
231
+
232
+ end # module Stomp
104
233
 
@@ -48,7 +48,6 @@ module Stomp
48
48
  # :back_off_multiplier => 2,
49
49
  # :max_reconnect_attempts => 0,
50
50
  # :randomize => false,
51
- # :backup => false,
52
51
  # :connect_timeout => 0,
53
52
  # :connect_headers => {},
54
53
  # :parse_timeout => 5,
@@ -141,7 +140,7 @@ module Stomp
141
140
 
142
141
  end
143
142
 
144
- # open is syntactic sugar for 'Client.new' See 'initialize' for usage.
143
+ # open is syntactic sugar for 'Client.new', see 'initialize' for usage.
145
144
  def self.open(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false)
146
145
  Client.new(login, passcode, host, port, reliable)
147
146
  end
@@ -161,7 +160,7 @@ module Stomp
161
160
  def abort(name, headers = {})
162
161
  @connection.abort(name, headers)
163
162
 
164
- # lets replay any ack'd messages in this transaction
163
+ # replay any ack'd messages in this transaction
165
164
  replay_list = @replay_messages_by_txn[name]
166
165
  if replay_list
167
166
  replay_list.each do |message|
@@ -243,13 +242,6 @@ module Stomp
243
242
  @connection.publish(destination, message, headers)
244
243
  end
245
244
 
246
- # :TODO: This should not be used. Currently only referenced in the
247
- # spec tests.
248
- # *NOTE* This will be removed in the next release.
249
- def obj_send(*args)
250
- __send__(*args)
251
- end
252
-
253
245
  # Return the broker's CONNECTED frame to the client. Misnamed.
254
246
  def connection_frame()
255
247
  @connection.connection_frame
@@ -42,7 +42,7 @@ module Stomp
42
42
 
43
43
  # A new Connection object can be initialized using two forms:
44
44
  #
45
- # Hash (this is the recommended Connection initialization method:
45
+ # Hash (this is the recommended Connection initialization method):
46
46
  #
47
47
  # hash = {
48
48
  # :hosts => [
@@ -56,11 +56,13 @@ module Stomp
56
56
  # :back_off_multiplier => 2,
57
57
  # :max_reconnect_attempts => 0,
58
58
  # :randomize => false,
59
- # :backup => false,
60
59
  # :connect_timeout => 0,
61
60
  # :connect_headers => {},
62
61
  # :parse_timeout => 5,
63
62
  # :logger => nil,
63
+ # :dmh => false,
64
+ # :closed_check => true,
65
+ # :hbser => false,
64
66
  # }
65
67
  #
66
68
  # e.g. c = Stomp::Connection.new(hash)
@@ -77,11 +79,10 @@ module Stomp
77
79
  # e.g. c = Stomp::Connection.new("username", "password", "localhost", 61613, true)
78
80
  #
79
81
  def initialize(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false, reconnect_delay = 5, connect_headers = {})
80
- @received_messages = []
81
82
  @protocol = Stomp::SPL_10 # Assumed at first
82
- @hb_received = true # Assumed at first
83
- @hb_sent = true # Assumed at first
84
- @hbs = @hbr = false # Sending/Receiving heartbeats. Assume no for now.
83
+ @hb_received = true # Assumed at first
84
+ @hb_sent = true # Assumed at first
85
+ @hbs = @hbr = false # Sending/Receiving heartbeats. Assume no for now.
85
86
 
86
87
  if login.is_a?(Hash)
87
88
  hashed_initialize(login)
@@ -99,11 +100,13 @@ module Stomp
99
100
  @connect_timeout = 0 # To override, use hashed parameters
100
101
  @logger = nil # To override, use hashed parameters
101
102
  @autoflush = false # To override, use hashed parameters or setter
103
+ @closed_check = true # Run closed check in each protocol method
104
+ @hbser = false # Raise if heartbeat send exception
102
105
  warn "login looks like a URL, do you have the correct parameters?" if @login =~ /:\/\//
103
106
  end
104
107
 
105
- # Use Mutexes: only one lock per each thread
106
- # Revert to original implementation attempt
108
+ # Use Mutexes: only one lock per each thread.
109
+ # Reverted to original implementation attempt using Mutex.
107
110
  @transmit_semaphore = Mutex.new
108
111
  @read_semaphore = Mutex.new
109
112
  @socket_semaphore = Mutex.new
@@ -127,128 +130,17 @@ module Stomp
127
130
  @connect_timeout = @parameters[:connect_timeout]
128
131
  @logger = @parameters[:logger]
129
132
  @autoflush = @parameters[:autoflush]
133
+ @closed_check = @parameters[:closed_check]
134
+ @hbser = @parameters[:hbser]
130
135
  #sets the first host to connect
131
136
  change_host
132
137
  end
133
138
 
134
- # open is syntactic sugar for 'Connection.new' See 'initialize' for usage.
139
+ # open is syntactic sugar for 'Connection.new', see 'initialize' for usage.
135
140
  def Connection.open(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false, reconnect_delay = 5, connect_headers = {})
136
141
  Connection.new(login, passcode, host, port, reliable, reconnect_delay, connect_headers)
137
142
  end
138
143
 
139
- # socket creates and returns a new socket for use by the connection.
140
- # *NOTE* this method will be made private in the next realease.
141
- def socket()
142
- @socket_semaphore.synchronize do
143
- used_socket = @socket
144
- used_socket = nil if closed?
145
-
146
- while used_socket.nil? || !@failure.nil?
147
- @failure = nil
148
- begin
149
- used_socket = open_socket()
150
- # Open complete
151
-
152
- connect(used_socket)
153
- if @logger && @logger.respond_to?(:on_connected)
154
- @logger.on_connected(log_params)
155
- end
156
- @connection_attempts = 0
157
- rescue
158
- @failure = $!
159
- used_socket = nil
160
- raise unless @reliable
161
- raise if @failure.is_a?(Stomp::Error::LoggerConnectionError)
162
- @closed = true
163
- if @logger && @logger.respond_to?(:on_connectfail)
164
- # on_connectfail may raise
165
- begin
166
- @logger.on_connectfail(log_params)
167
- rescue Exception => aex
168
- raise if aex.is_a?(Stomp::Error::LoggerConnectionError)
169
- end
170
- else
171
- $stderr.print "connect to #{@host} failed: #{$!} will retry(##{@connection_attempts}) in #{@reconnect_delay}\n"
172
- end
173
- raise Stomp::Error::MaxReconnectAttempts if max_reconnect_attempts?
174
-
175
- sleep(@reconnect_delay)
176
-
177
- @connection_attempts += 1
178
-
179
- if @parameters
180
- change_host()
181
- increase_reconnect_delay()
182
- end
183
- end
184
- end
185
- @socket = used_socket
186
- end
187
- end
188
-
189
- # refine_params sets up defaults for a Hash initialize.
190
- # *NOTE* This method will be made private in the next release.
191
- def refine_params(params)
192
- params = params.uncamelize_and_symbolize_keys
193
- default_params = {
194
- :connect_headers => {},
195
- :reliable => true,
196
- # Failover parameters
197
- :initial_reconnect_delay => 0.01,
198
- :max_reconnect_delay => 30.0,
199
- :use_exponential_back_off => true,
200
- :back_off_multiplier => 2,
201
- :max_reconnect_attempts => 0,
202
- :randomize => false,
203
- :backup => false,
204
- :connect_timeout => 0,
205
- # Parse Timeout
206
- :parse_timeout => 5,
207
- :dmh => false,
208
- }
209
-
210
- res_params = default_params.merge(params)
211
- if res_params[:dmh]
212
- res_params = _expand_hosts(res_params)
213
- end
214
- return res_params
215
- end
216
-
217
- # change_host selects the next host for retires.
218
- # *NOTE* This method will be made private in the next release.
219
- def change_host
220
- @parameters[:hosts] = @parameters[:hosts].sort_by { rand } if @parameters[:randomize]
221
-
222
- # Set first as master and send it to the end of array
223
- current_host = @parameters[:hosts].shift
224
- @parameters[:hosts] << current_host
225
-
226
- @ssl = current_host[:ssl]
227
- @host = current_host[:host]
228
- @port = current_host[:port] || Connection::default_port(@ssl)
229
- @login = current_host[:login] || ""
230
- @passcode = current_host[:passcode] || ""
231
-
232
- end
233
-
234
- # max_reconnect_attempts? returns nil or the number of maximum reconnect
235
- # attempts.
236
- # *NOTE* This method will be made private in the next release.
237
- def max_reconnect_attempts?
238
- !(@parameters.nil? || @parameters[:max_reconnect_attempts].nil?) && @parameters[:max_reconnect_attempts] != 0 && @connection_attempts >= @parameters[:max_reconnect_attempts]
239
- end
240
-
241
- # increase_reconnect_delay increases the reconnect delay for the next connection
242
- # attempt.
243
- # *NOTE* This method will be made private in the next release.
244
- def increase_reconnect_delay
245
-
246
- @reconnect_delay *= @parameters[:back_off_multiplier] if @parameters[:use_exponential_back_off]
247
- @reconnect_delay = @parameters[:max_reconnect_delay] if @reconnect_delay > @parameters[:max_reconnect_delay]
248
-
249
- @reconnect_delay
250
- end
251
-
252
144
  # open? tests if this connection is open.
253
145
  def open?
254
146
  !@closed
@@ -261,7 +153,7 @@ module Stomp
261
153
 
262
154
  # Begin starts a transaction, and requires a name for the transaction
263
155
  def begin(name, headers = {})
264
- raise Stomp::Error::NoCurrentConnection if closed?
156
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
265
157
  headers = headers.symbolize_keys
266
158
  headers[:transaction] = name
267
159
  _headerCheck(headers)
@@ -272,7 +164,7 @@ module Stomp
272
164
  # client acknowledgement i.e. connection.subscribe("/queue/a", :ack => 'client').
273
165
  # Accepts a transaction header ( :transaction => 'some_transaction_id' )
274
166
  def ack(message_id, headers = {})
275
- raise Stomp::Error::NoCurrentConnection if closed?
167
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
276
168
  raise Stomp::Error::MessageIDRequiredError if message_id.nil? || message_id == ""
277
169
  headers = headers.symbolize_keys
278
170
  headers[:'message-id'] = message_id
@@ -285,7 +177,7 @@ module Stomp
285
177
 
286
178
  # STOMP 1.1+ NACK.
287
179
  def nack(message_id, headers = {})
288
- raise Stomp::Error::NoCurrentConnection if closed?
180
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
289
181
  raise Stomp::Error::UnsupportedProtocolError if @protocol == Stomp::SPL_10
290
182
  raise Stomp::Error::MessageIDRequiredError if message_id.nil? || message_id == ""
291
183
  headers = headers.symbolize_keys
@@ -297,7 +189,7 @@ module Stomp
297
189
 
298
190
  # Commit commits a transaction by name.
299
191
  def commit(name, headers = {})
300
- raise Stomp::Error::NoCurrentConnection if closed?
192
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
301
193
  headers = headers.symbolize_keys
302
194
  headers[:transaction] = name
303
195
  _headerCheck(headers)
@@ -306,7 +198,7 @@ module Stomp
306
198
 
307
199
  # Abort aborts a transaction by name.
308
200
  def abort(name, headers = {})
309
- raise Stomp::Error::NoCurrentConnection if closed?
201
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
310
202
  headers = headers.symbolize_keys
311
203
  headers[:transaction] = name
312
204
  _headerCheck(headers)
@@ -314,9 +206,9 @@ module Stomp
314
206
  end
315
207
 
316
208
  # Subscribe subscribes to a destination. A subscription name is required.
317
- # For Stomp 1.1 a session unique subscription ID is required.
209
+ # For Stomp 1.1+ a session unique subscription ID is also required.
318
210
  def subscribe(name, headers = {}, subId = nil)
319
- raise Stomp::Error::NoCurrentConnection if closed?
211
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
320
212
  headers = headers.symbolize_keys
321
213
  headers[:destination] = name
322
214
  if @protocol >= Stomp::SPL_11
@@ -328,7 +220,7 @@ module Stomp
328
220
  @logger.on_subscribe(log_params, headers)
329
221
  end
330
222
 
331
- # Store the sub so that we can replay if we reconnect.
223
+ # Store the subscription so that we can replay if we reconnect.
332
224
  if @reliable
333
225
  subId = name if subId.nil?
334
226
  raise Stomp::Error::DuplicateSubscription if @subscriptions[subId]
@@ -339,9 +231,9 @@ module Stomp
339
231
  end
340
232
 
341
233
  # Unsubscribe from a destination. A subscription name is required.
342
- # For Stomp 1.1 a session unique subscription ID is required.
234
+ # For Stomp 1.1+ a session unique subscription ID is also required.
343
235
  def unsubscribe(dest, headers = {}, subId = nil)
344
- raise Stomp::Error::NoCurrentConnection if closed?
236
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
345
237
  headers = headers.symbolize_keys
346
238
  headers[:destination] = dest
347
239
  if @protocol >= Stomp::SPL_11
@@ -359,7 +251,7 @@ module Stomp
359
251
  # To disable content length header use header ( :suppress_content_length => true ).
360
252
  # Accepts a transaction header ( :transaction => 'some_transaction_id' ).
361
253
  def publish(destination, message, headers = {})
362
- raise Stomp::Error::NoCurrentConnection if closed?
254
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
363
255
  headers = headers.symbolize_keys
364
256
  headers[:destination] = destination
365
257
  _headerCheck(headers)
@@ -369,18 +261,12 @@ module Stomp
369
261
  transmit(Stomp::CMD_SEND, headers, message)
370
262
  end
371
263
 
372
- # :TODO: Remove this method.
373
- # *NOTE* This method will be removed in the next release.
374
- def obj_send(*args)
375
- __send__(*args)
376
- end
377
-
378
264
  # Send a message back to the source or to the dead letter queue.
379
265
  # Accepts a dead letter queue option ( :dead_letter_queue => "/queue/DLQ" ).
380
266
  # Accepts a limit number of redeliveries option ( :max_redeliveries => 6 ).
381
267
  # Accepts a force client acknowledgement option (:force_client_ack => true).
382
268
  def unreceive(message, options = {})
383
- raise Stomp::Error::NoCurrentConnection if closed?
269
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
384
270
  options = { :dead_letter_queue => "/queue/DLQ", :max_redeliveries => 6 }.merge(options)
385
271
  # Lets make sure all keys are symbols
386
272
  message.headers = message.headers.symbolize_keys
@@ -421,9 +307,9 @@ module Stomp
421
307
  end
422
308
 
423
309
  # disconnect closes this connection. If requested, a disconnect RECEIPT
424
- # is received.
310
+ # will be received.
425
311
  def disconnect(headers = {})
426
- raise Stomp::Error::NoCurrentConnection if closed?
312
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
427
313
  headers = headers.symbolize_keys
428
314
  _headerCheck(headers)
429
315
  if @protocol >= Stomp::SPL_11
@@ -441,37 +327,16 @@ module Stomp
441
327
  # poll returns a pending message if one is available, otherwise
442
328
  # returns nil.
443
329
  def poll()
444
- raise Stomp::Error::NoCurrentConnection if closed?
330
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
445
331
  # No need for a read lock here. The receive method eventually fulfills
446
332
  # that requirement.
447
333
  return nil if @socket.nil? || !@socket.ready?
448
334
  receive()
449
335
  end
450
336
 
451
- # __old_receive receives a frame, blocks until the frame is received.
452
- # *NOTE* This method will be made private in the next release.
453
- def __old_receive()
454
- # The receive may fail so we may need to retry.
455
- while TRUE
456
- begin
457
- used_socket = socket
458
- return _receive(used_socket)
459
- rescue
460
- @failure = $!
461
- raise unless @reliable
462
- errstr = "receive failed: #{$!}"
463
- if @logger && @logger.respond_to?(:on_miscerr)
464
- @logger.on_miscerr(log_params, errstr)
465
- else
466
- $stderr.print errstr
467
- end
468
- end
469
- end
470
- end
471
-
472
337
  # receive returns the next Message off of the wire.
473
338
  def receive()
474
- raise Stomp::Error::NoCurrentConnection if closed?
339
+ raise Stomp::Error::NoCurrentConnection if @closed_check && closed?
475
340
  super_result = __old_receive
476
341
  if super_result.nil? && @reliable && !closed?
477
342
  errstr = "connection.receive returning EOF as nil - resetting connection.\n"
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Stomp
4
4
 
5
- # Client side
5
+ # Client generated frames
6
6
  CMD_CONNECT = "CONNECT"
7
7
  CMD_STOMP = "STOMP"
8
8
  CMD_DISCONNECT = "DISCONNECT"
@@ -15,7 +15,7 @@ module Stomp
15
15
  CMD_COMMIT = "COMMIT"
16
16
  CMD_ABORT = "ABORT"
17
17
 
18
- # Server side
18
+ # Server generated names
19
19
  CMD_CONNECTED = "CONNECTED"
20
20
  CMD_MESSAGE = "MESSAGE"
21
21
  CMD_RECEIPT = "RECEIPT"
@@ -75,6 +75,7 @@ module Stomp
75
75
  "\\c", ":",
76
76
  ]
77
77
 
78
+ # A fairly safe and generally supported ciphers list.
78
79
  DEFAULT_CIPHERS = [
79
80
  ["DHE-RSA-AES256-SHA", "TLSv1/SSLv3", 256, 256],
80
81
  ["DHE-DSS-AES256-SHA", "TLSv1/SSLv3", 256, 256],
@@ -97,4 +98,4 @@ module Stomp
97
98
  ["EXP-RC4-MD5", "TLSv1/SSLv3", 40, 128],
98
99
  ]
99
100
 
100
- end
101
+ end # Module Stomp
@@ -48,6 +48,7 @@ module Stomp
48
48
 
49
49
  # NoCurrentConnection is raised if:
50
50
  # * Any method is called when a current connection does not exist.
51
+ # * And @closed_check is true (the default).
51
52
  class NoCurrentConnection < RuntimeError
52
53
  def message
53
54
  "no current connection exists"
@@ -189,5 +190,6 @@ module Stomp
189
190
  end
190
191
 
191
192
  end # module Error
193
+
192
194
  end # module Stomp
193
195
 
@@ -27,4 +27,5 @@ class ::Hash
27
27
 
28
28
  symbolized
29
29
  end unless self.method_defined?(:symbolize_keys)
30
- end
30
+
31
+ end # class Hash
@@ -94,7 +94,7 @@ module Stomp
94
94
  self.body = work_body[0..body_length]
95
95
  end
96
96
 
97
- # to_s returns a string prepresentation of this Message
97
+ # to_s returns a string prepresentation of this Message.
98
98
  def to_s
99
99
  "<Stomp::Message headers=#{headers.inspect} body='#{body}' command='#{command}' >"
100
100
  end
@@ -111,7 +111,7 @@ module Stomp
111
111
  is_blank?(command) && is_blank?(headers) && is_blank?(body)
112
112
  end
113
113
 
114
- end
114
+ end # class Message
115
115
 
116
- end
116
+ end # module Stomp
117
117
 
@@ -41,7 +41,7 @@ module Stomp
41
41
  # Client wants file existance check on initialize. true/value or false/nil.
42
42
  attr_reader :fsck #
43
43
 
44
- # initialize returns a valid set of SSLParams or raises an error.
44
+ # initialize returns a valid instance of SSLParams or raises an error.
45
45
  def initialize(opts={})
46
46
 
47
47
  # Server authentication parameters
@@ -6,7 +6,7 @@ module Stomp
6
6
  module Version #:nodoc: all
7
7
  MAJOR = 1
8
8
  MINOR = 2
9
- PATCH = 5
9
+ PATCH = 6
10
10
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
11
11
  end
12
12
  end
@@ -236,8 +236,7 @@ describe Stomp::Client do
236
236
  :back_off_multiplier => 2,
237
237
  :max_reconnect_attempts => 0,
238
238
  :randomize => false,
239
- :backup => false,
240
- :timeout => -1
239
+ :connect_timeout => 0
241
240
  }
242
241
  end
243
242
  it "should properly parse a URL with failover://" do
@@ -311,8 +310,7 @@ describe Stomp::Client do
311
310
  :back_off_multiplier => 3,
312
311
  :max_reconnect_attempts => 4,
313
312
  :randomize => true,
314
- :backup => false,
315
- :timeout => -1
313
+ :connect_timeout => 0
316
314
  }
317
315
 
318
316
  @parameters[:hosts] = [
@@ -17,11 +17,12 @@ describe Stomp::Connection do
17
17
  :back_off_multiplier => 2,
18
18
  :max_reconnect_attempts => 0,
19
19
  :randomize => false,
20
- :backup => false,
21
20
  :connect_timeout => 0,
22
21
  :parse_timeout => 5,
23
22
  :connect_headers => {},
24
- :dmh => false
23
+ :dmh => false,
24
+ :closed_check => true,
25
+ :hbser => false,
25
26
  }
26
27
 
27
28
  #POG:
@@ -52,7 +53,6 @@ describe Stomp::Connection do
52
53
  "backOffMultiplier" => 2,
53
54
  "maxReconnectAttempts" => 0,
54
55
  "randomize" => false,
55
- "backup" => false,
56
56
  "connect_timeout" => 0,
57
57
  "parse_timeout" => 5,
58
58
  }
@@ -85,7 +85,6 @@ describe Stomp::Connection do
85
85
  "backOffMultiplier" => 2,
86
86
  "maxReconnectAttempts" => 0,
87
87
  "randomize" => false,
88
- "backup" => false,
89
88
  "connect_timeout" => 0,
90
89
  "parse_timeout" => 5
91
90
  }
@@ -99,7 +98,7 @@ describe Stomp::Connection do
99
98
  end
100
99
 
101
100
  it "should change host to next one with randomize false" do
102
- @connection.change_host
101
+ @connection.send(:change_host) # use .send(:name) to test a private method!
103
102
  @connection.instance_variable_get(:@host).should == "remotehost"
104
103
  end
105
104
 
@@ -287,21 +286,21 @@ describe Stomp::Connection do
287
286
 
288
287
  describe "when called to increase reconnect delay" do
289
288
  it "should exponentialy increase when use_exponential_back_off is true" do
290
- @connection.increase_reconnect_delay.should == 0.02
291
- @connection.increase_reconnect_delay.should == 0.04
292
- @connection.increase_reconnect_delay.should == 0.08
289
+ @connection.send(:increase_reconnect_delay).should == 0.02
290
+ @connection.send(:increase_reconnect_delay).should == 0.04
291
+ @connection.send(:increase_reconnect_delay).should == 0.08
293
292
  end
294
293
  it "should not increase when use_exponential_back_off is false" do
295
294
  @parameters[:use_exponential_back_off] = false
296
295
  @connection = Stomp::Connection.new(@parameters)
297
- @connection.increase_reconnect_delay.should == 0.01
298
- @connection.increase_reconnect_delay.should == 0.01
296
+ @connection.send(:increase_reconnect_delay).should == 0.01
297
+ @connection.send(:increase_reconnect_delay).should == 0.01
299
298
  end
300
299
  it "should not increase when max_reconnect_delay is reached" do
301
300
  @parameters[:initial_reconnect_delay] = 8.0
302
301
  @connection = Stomp::Connection.new(@parameters)
303
- @connection.increase_reconnect_delay.should == 16.0
304
- @connection.increase_reconnect_delay.should == 30.0
302
+ @connection.send(:increase_reconnect_delay).should == 16.0
303
+ @connection.send(:increase_reconnect_delay).should == 30.0
305
304
  end
306
305
 
307
306
  it "should change to next host on socket error" do
@@ -311,7 +310,7 @@ describe Stomp::Connection do
311
310
  #tries the new host
312
311
  TCPSocket.should_receive(:open).and_return @tcp_socket
313
312
 
314
- @connection.socket
313
+ @connection.send(:socket)
315
314
  @connection.instance_variable_get(:@host).should == "remotehost"
316
315
  end
317
316
 
@@ -329,11 +328,12 @@ describe Stomp::Connection do
329
328
  :back_off_multiplier => 2,
330
329
  :max_reconnect_attempts => 0,
331
330
  :randomize => false,
332
- :backup => false,
333
331
  :connect_timeout => 0,
334
332
  :parse_timeout => 5,
335
333
  :connect_headers => {},
336
334
  :dmh => false,
335
+ :closed_check => true,
336
+ :hbser => false,
337
337
  }
338
338
 
339
339
  used_hash = {
@@ -367,12 +367,14 @@ describe Stomp::Connection do
367
367
  :dead_letter_queue => "queue/Error",
368
368
  :max_redeliveries => 10,
369
369
  :dmh => false,
370
+ :closed_check => true,
371
+ :hbser => false,
370
372
  }
371
373
 
372
374
  @connection = Stomp::Connection.new(used_hash)
373
375
  received_hash = @connection.instance_variable_get(:@parameters)
374
376
 
375
- #Using randomize we can't assure the hosts order
377
+ # Using randomize we can't assure the hosts order
376
378
  received_hash.delete(:hosts)
377
379
  used_hash.delete(:hosts)
378
380
 
@@ -386,11 +388,11 @@ describe Stomp::Connection do
386
388
  describe "when closing a socket" do
387
389
  it "should close the tcp connection" do
388
390
  @tcp_socket.should_receive(:close)
389
- @connection.obj_send(:close_socket).should be_true
391
+ @connection.__send__(:close_socket).should be_true # Use Object.__send__
390
392
  end
391
393
  it "should ignore exceptions" do
392
394
  @tcp_socket.should_receive(:close).and_raise "exception"
393
- @connection.obj_send(:close_socket).should be_true
395
+ @connection.__send__(:close_socket).should be_true # Use Object.__send__
394
396
  end
395
397
  end
396
398
 
@@ -399,11 +401,11 @@ describe Stomp::Connection do
399
401
  host = @parameters[:hosts][0]
400
402
  @connection = Stomp::Connection.new(host[:login], host[:passcode], host[:host], host[:port], reliable = true, 5, connect_headers = {})
401
403
  @connection.instance_variable_set(:@connection_attempts, 10000)
402
- @connection.max_reconnect_attempts?.should be_false
404
+ @connection.send(:max_reconnect_attempts?).should be_false
403
405
  end
404
406
  it "should return false if max_reconnect_attempts = 0" do
405
407
  @connection.instance_variable_set(:@connection_attempts, 10000)
406
- @connection.max_reconnect_attempts?.should be_false
408
+ @connection.send(:max_reconnect_attempts?).should be_false
407
409
  end
408
410
  it "should return true if connection attempts > max_reconnect_attempts" do
409
411
  limit = 10000
@@ -411,10 +413,10 @@ describe Stomp::Connection do
411
413
  @connection = Stomp::Connection.new(@parameters)
412
414
 
413
415
  @connection.instance_variable_set(:@connection_attempts, limit-1)
414
- @connection.max_reconnect_attempts?.should be_false
416
+ @connection.send(:max_reconnect_attempts?).should be_false
415
417
 
416
418
  @connection.instance_variable_set(:@connection_attempts, limit)
417
- @connection.max_reconnect_attempts?.should be_true
419
+ @connection.send(:max_reconnect_attempts?).should be_true
418
420
 
419
421
  end
420
422
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{stomp}
8
- s.version = "1.2.5"
8
+ s.version = "1.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian McCallister", "Marius Mathiesen", "Thiago Morello", "Guy M. Allard"]
12
- s.date = %q{2012-08-04}
12
+ s.date = %q{2012-10-05}
13
13
  s.description = %q{Ruby client for the Stomp messaging protocol. Note that this gem is no longer supported on rubyforge.}
14
14
  s.email = ["brianm@apache.org", "marius@stones.com", "morellon@gmail.com", "allard.guy.m@gmail.com"]
15
15
  s.executables = ["catstomp", "stompcat"]
@@ -93,16 +93,6 @@ class Tlogger
93
93
  end
94
94
  end
95
95
 
96
- # Stomp 1.1+ - heart beat read (receive) failed
97
- def on_hbread_fail(parms, ticker_data)
98
- begin
99
- @log.debug "Hbreadf Parms #{info(parms)}"
100
- @log.debug "Hbreadf Result #{ticker_data}"
101
- rescue
102
- @log.debug "Hbreadf oops"
103
- end
104
- end
105
-
106
96
  # Stomp 1.1+ - heart beat send (transmit) failed
107
97
  def on_hbwrite_fail(parms, ticker_data)
108
98
  begin
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stomp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 5
10
- version: 1.2.5
9
+ - 6
10
+ version: 1.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian McCallister
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2012-08-04 00:00:00 -04:00
21
+ date: 2012-10-05 00:00:00 -04:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency