stomper 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,7 @@ class TestStompServer
|
|
9
9
|
begin
|
10
10
|
@socket = TCPServer.new(@port)
|
11
11
|
rescue Exception => ex
|
12
|
+
retry
|
12
13
|
end
|
13
14
|
@session = nil
|
14
15
|
@version = version
|
@@ -59,7 +60,7 @@ class TestStompServer
|
|
59
60
|
connect_to_client(headers)
|
60
61
|
@serializer.extend_for_protocol('1.1') if version == '1.1'
|
61
62
|
@receive_thread = Thread.new do
|
62
|
-
|
63
|
+
loop do
|
63
64
|
begin
|
64
65
|
read_frame
|
65
66
|
rescue Exception => ex
|
@@ -88,30 +89,32 @@ class TestStompServer
|
|
88
89
|
|
89
90
|
def read_frame
|
90
91
|
@serializer.read_frame.tap do |f|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
case f.command
|
96
|
-
when 'DISCONNECT'
|
97
|
-
@running = false
|
98
|
-
@client_socket.close
|
99
|
-
when 'SEND'
|
100
|
-
if @subscribed[f[:destination]]
|
101
|
-
@subscribed[f[:destination]].each_with_index do |sub_id, idx|
|
102
|
-
msg = f.dup
|
103
|
-
msg[:subscription] = sub_id
|
104
|
-
msg[:'message-id'] = "m-#{(Time.now.to_f * 1000).to_i}-#{idx}"
|
105
|
-
msg.command = 'MESSAGE'
|
106
|
-
send_frame msg
|
107
|
-
end
|
92
|
+
if f
|
93
|
+
@received_frames << f
|
94
|
+
unless f[:receipt].nil? || f[:receipt].empty?
|
95
|
+
send_frame 'RECEIPT', { :'receipt-id' => f[:receipt] }
|
108
96
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
@subscribed[f[:destination]]
|
97
|
+
case f.command
|
98
|
+
when 'DISCONNECT'
|
99
|
+
@running = false
|
100
|
+
@client_socket.close
|
101
|
+
when 'SEND'
|
102
|
+
if @subscribed[f[:destination]]
|
103
|
+
@subscribed[f[:destination]].each_with_index do |sub_id, idx|
|
104
|
+
msg = f.dup
|
105
|
+
msg[:subscription] = sub_id
|
106
|
+
msg[:'message-id'] = "m-#{(Time.now.to_f * 1000).to_i}-#{idx}"
|
107
|
+
msg.command = 'MESSAGE'
|
108
|
+
send_frame msg
|
109
|
+
end
|
110
|
+
end
|
111
|
+
when 'SUBSCRIBE'
|
112
|
+
@subscribed[f[:destination]] ||= []
|
113
|
+
@subscribed[f[:destination]] << f[:id]
|
114
|
+
when 'UNSUBSCRIBE'
|
115
|
+
if @subscribed[f[:destination]]
|
116
|
+
@subscribed[f[:destination]].delete f[:id]
|
117
|
+
end
|
115
118
|
end
|
116
119
|
end
|
117
120
|
end
|
@@ -130,6 +133,7 @@ class TestStompServer
|
|
130
133
|
|
131
134
|
class StompErrorOnConnectSession < StompSession
|
132
135
|
def connect_to_client(headers)
|
136
|
+
rf = read_frame
|
133
137
|
send_frame 'ERROR'
|
134
138
|
end
|
135
139
|
end
|
data/lib/stomper/connection.rb
CHANGED
@@ -174,7 +174,7 @@ class Stomper::Connection
|
|
174
174
|
@close_mutex = ::Mutex.new
|
175
175
|
|
176
176
|
on_connected do |cf, con|
|
177
|
-
unless connected
|
177
|
+
unless @connected
|
178
178
|
@version = (cf[:version].nil?||cf[:version].empty?) ? '1.0' : cf[:version]
|
179
179
|
unless @versions.include?(@version)
|
180
180
|
close
|
@@ -312,10 +312,11 @@ class Stomper::Connection
|
|
312
312
|
alias :open :connect
|
313
313
|
end
|
314
314
|
|
315
|
-
# True if a connection with the broker has been established
|
315
|
+
# True if a connection with the broker has been established or is in the
|
316
|
+
# process of being established, false otherwise.
|
316
317
|
# @return [true,false]
|
317
318
|
def connected?
|
318
|
-
@connected && !@socket.closed?
|
319
|
+
(@connecting || @connected) && !@socket.closed?
|
319
320
|
end
|
320
321
|
|
321
322
|
# Creates an instance of the class given by {#receiver_class} and starts it.
|
@@ -371,7 +372,7 @@ class Stomper::Connection
|
|
371
372
|
# {Stomper::Extensions::Events#on_connection_terminated}
|
372
373
|
def close
|
373
374
|
@close_mutex.synchronize do
|
374
|
-
if
|
375
|
+
if connected?
|
375
376
|
begin
|
376
377
|
trigger_event(:on_connection_terminated, self) unless @disconnected
|
377
378
|
ensure
|
@@ -379,7 +380,7 @@ class Stomper::Connection
|
|
379
380
|
@socket.shutdown(2) rescue nil
|
380
381
|
@socket.close rescue nil
|
381
382
|
end
|
382
|
-
@connected = false
|
383
|
+
@connecting = @connected = false
|
383
384
|
end
|
384
385
|
trigger_event(:on_connection_closed, self)
|
385
386
|
subscription_manager.clear
|
@@ -410,8 +411,7 @@ class Stomper::Connection
|
|
410
411
|
# Receives a frame from the broker.
|
411
412
|
# @return [Stomper::Frame]
|
412
413
|
def receive
|
413
|
-
|
414
|
-
if alive? || @connecting
|
414
|
+
if alive?
|
415
415
|
trigger_event(:before_receiving, nil, self)
|
416
416
|
begin
|
417
417
|
@serializer.read_frame.tap do |f|
|
@@ -427,6 +427,8 @@ class Stomper::Connection
|
|
427
427
|
close
|
428
428
|
raise
|
429
429
|
end
|
430
|
+
else
|
431
|
+
trigger_event(:on_connection_died, self)
|
430
432
|
end
|
431
433
|
end
|
432
434
|
|
@@ -17,7 +17,7 @@ module Stomper::Extensions::Heartbeat
|
|
17
17
|
# {Stomper::Protocols::V1_1::Heartbeating#beat}.
|
18
18
|
def beat; end
|
19
19
|
|
20
|
-
# By default, a connection is alive if it is connected.
|
20
|
+
# By default, a connection is alive if it is {Stomper::Connection#connected?}.
|
21
21
|
# If the established connection utilizes the Stomp 1.1 protocol, this
|
22
22
|
# method will be overridden by {Stomper::Protocols::V1_1::Heartbeating#alive?}.
|
23
23
|
# @return [true,false]
|
@@ -41,7 +41,7 @@ module Stomper::Extensions::Heartbeat
|
|
41
41
|
end
|
42
42
|
|
43
43
|
# Stomp 1.1 {Stomper::Connection connections} are alive if they are
|
44
|
-
#
|
44
|
+
# {Stomper::Connection#connected?} and are meeting their negotiated heart-beating obligations.
|
45
45
|
# @return [true, false]
|
46
46
|
# @see #dead?
|
47
47
|
def alive?
|
data/lib/stomper/version.rb
CHANGED
@@ -343,7 +343,7 @@ module Stomper
|
|
343
343
|
triggered.should be_true
|
344
344
|
end
|
345
345
|
|
346
|
-
it "should trigger on_connection_died before receiving non-blocking
|
346
|
+
it "should not trigger on_connection_died before receiving non-blocking if socket is not ready" do
|
347
347
|
triggered = false
|
348
348
|
@connection.on_connection_died { triggered = true }
|
349
349
|
@connection.connect
|
@@ -351,6 +351,17 @@ module Stomper
|
|
351
351
|
@serializer.stub!(:read_frame).and_return(::Stomper::Frame.new('MESSAGE'))
|
352
352
|
@socket.stub!(:ready?).and_return(false)
|
353
353
|
@connection.receive_nonblock
|
354
|
+
triggered.should be_false
|
355
|
+
end
|
356
|
+
|
357
|
+
it "should trigger on_connection_died before receiving non-blocking if socket is ready" do
|
358
|
+
triggered = false
|
359
|
+
@connection.on_connection_died { triggered = true }
|
360
|
+
@connection.connect
|
361
|
+
@connection.stub!(:alive?).and_return(false)
|
362
|
+
@serializer.stub!(:read_frame).and_return(::Stomper::Frame.new('MESSAGE'))
|
363
|
+
@socket.stub!(:ready?).and_return(true)
|
364
|
+
@connection.receive_nonblock
|
354
365
|
triggered.should be_true
|
355
366
|
end
|
356
367
|
|