dripdrop 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/dripdrop.gemspec +11 -11
- data/lib/dripdrop/handlers/zeromq.rb +35 -11
- data/spec/node/zmq_xrepxreq_spec.rb +3 -1
- metadata +16 -10
data/Rakefile
CHANGED
@@ -10,11 +10,11 @@ begin
|
|
10
10
|
gem.email = "andrew@andrewvc.com"
|
11
11
|
gem.homepage = "http://github.com/andrewvc/dripdrop"
|
12
12
|
gem.authors = ["Andrew Cholakian"]
|
13
|
-
gem.add_dependency('ffi-rzmq')
|
14
|
-
gem.add_dependency('eventmachine')
|
13
|
+
gem.add_dependency('ffi-rzmq', '>= 0.7.1')
|
14
|
+
gem.add_dependency('eventmachine', '>= 0.12.10')
|
15
15
|
gem.add_dependency('em-websocket')
|
16
16
|
gem.add_dependency('thin')
|
17
|
-
gem.add_dependency('em-zeromq')
|
17
|
+
gem.add_dependency('em-zeromq', '>= 0.1.2')
|
18
18
|
gem.add_dependency('msgpack')
|
19
19
|
gem.add_dependency('yajl-ruby')
|
20
20
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.3
|
data/dripdrop.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dripdrop}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Cholakian"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-02}
|
13
13
|
s.description = %q{Evented framework for ZeroMQ and EventMachine Apps. }
|
14
14
|
s.email = %q{andrew@andrewvc.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -84,28 +84,28 @@ Gem::Specification.new do |s|
|
|
84
84
|
s.specification_version = 3
|
85
85
|
|
86
86
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
87
|
-
s.add_runtime_dependency(%q<ffi-rzmq>, [">= 0"])
|
88
|
-
s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
|
87
|
+
s.add_runtime_dependency(%q<ffi-rzmq>, [">= 0.7.1"])
|
88
|
+
s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.10"])
|
89
89
|
s.add_runtime_dependency(%q<em-websocket>, [">= 0"])
|
90
90
|
s.add_runtime_dependency(%q<thin>, [">= 0"])
|
91
|
-
s.add_runtime_dependency(%q<em-zeromq>, [">= 0"])
|
91
|
+
s.add_runtime_dependency(%q<em-zeromq>, [">= 0.1.2"])
|
92
92
|
s.add_runtime_dependency(%q<msgpack>, [">= 0"])
|
93
93
|
s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
|
94
94
|
else
|
95
|
-
s.add_dependency(%q<ffi-rzmq>, [">= 0"])
|
96
|
-
s.add_dependency(%q<eventmachine>, [">= 0"])
|
95
|
+
s.add_dependency(%q<ffi-rzmq>, [">= 0.7.1"])
|
96
|
+
s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
|
97
97
|
s.add_dependency(%q<em-websocket>, [">= 0"])
|
98
98
|
s.add_dependency(%q<thin>, [">= 0"])
|
99
|
-
s.add_dependency(%q<em-zeromq>, [">= 0"])
|
99
|
+
s.add_dependency(%q<em-zeromq>, [">= 0.1.2"])
|
100
100
|
s.add_dependency(%q<msgpack>, [">= 0"])
|
101
101
|
s.add_dependency(%q<yajl-ruby>, [">= 0"])
|
102
102
|
end
|
103
103
|
else
|
104
|
-
s.add_dependency(%q<ffi-rzmq>, [">= 0"])
|
105
|
-
s.add_dependency(%q<eventmachine>, [">= 0"])
|
104
|
+
s.add_dependency(%q<ffi-rzmq>, [">= 0.7.1"])
|
105
|
+
s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
|
106
106
|
s.add_dependency(%q<em-websocket>, [">= 0"])
|
107
107
|
s.add_dependency(%q<thin>, [">= 0"])
|
108
|
-
s.add_dependency(%q<em-zeromq>, [">= 0"])
|
108
|
+
s.add_dependency(%q<em-zeromq>, [">= 0.1.2"])
|
109
109
|
s.add_dependency(%q<msgpack>, [">= 0"])
|
110
110
|
s.add_dependency(%q<yajl-ruby>, [">= 0"])
|
111
111
|
end
|
@@ -2,6 +2,7 @@ require 'ffi-rzmq'
|
|
2
2
|
require 'em-zeromq'
|
3
3
|
|
4
4
|
class DripDrop
|
5
|
+
SEQ_CTR_KEY = '_dd/xctr'
|
5
6
|
|
6
7
|
#Setup the default message class handler first
|
7
8
|
class << self
|
@@ -37,6 +38,7 @@ class DripDrop
|
|
37
38
|
def initialize(*args)
|
38
39
|
super(*args)
|
39
40
|
@send_queue = []
|
41
|
+
@send_queue_enabled = true
|
40
42
|
end
|
41
43
|
|
42
44
|
def on_writable(socket)
|
@@ -46,20 +48,20 @@ class DripDrop
|
|
46
48
|
num_parts = message.length
|
47
49
|
message.each_with_index do |part,i|
|
48
50
|
# Set the multi-part flag unless this is the last message
|
49
|
-
|
51
|
+
flags = (i + 1 < num_parts ? ZMQ::SNDMORE : 0) + ZMQ::NOBLOCK
|
50
52
|
|
51
53
|
if part.class == ZMQ::Message
|
52
|
-
socket.send(part,
|
54
|
+
socket.send(part, flags)
|
53
55
|
else
|
54
56
|
if part.class == String
|
55
|
-
socket.send_string(part,
|
57
|
+
socket.send_string(part, flags)
|
56
58
|
else
|
57
59
|
$stderr.write "Can only send Strings, not #{part.class}: #{part}" if @debug
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
61
63
|
else
|
62
|
-
@connection.deregister_writable
|
64
|
+
@connection.deregister_writable if @send_queue_enabled
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
@@ -76,7 +78,16 @@ class DripDrop
|
|
76
78
|
else
|
77
79
|
@send_queue.push([message])
|
78
80
|
end
|
79
|
-
|
81
|
+
|
82
|
+
|
83
|
+
if @send_queue_enabled
|
84
|
+
@connection.register_writable
|
85
|
+
|
86
|
+
# Not sure why this is necessary, this is likely a bug in em-zeromq
|
87
|
+
on_writable(@connection.socket)
|
88
|
+
else
|
89
|
+
on_writable(@connection.socket)
|
90
|
+
end
|
80
91
|
end
|
81
92
|
end
|
82
93
|
|
@@ -104,6 +115,10 @@ class DripDrop
|
|
104
115
|
raise "Unknown message format '#{@msg_format}'"
|
105
116
|
end
|
106
117
|
end
|
118
|
+
|
119
|
+
def post_setup
|
120
|
+
@connection.register_readable
|
121
|
+
end
|
107
122
|
end
|
108
123
|
|
109
124
|
class ZMQSubHandler < ZMQBaseHandler
|
@@ -132,6 +147,7 @@ class DripDrop
|
|
132
147
|
end
|
133
148
|
|
134
149
|
def post_setup
|
150
|
+
super
|
135
151
|
@connection.socket.setsockopt(ZMQ::SUBSCRIBE, '')
|
136
152
|
end
|
137
153
|
end
|
@@ -173,7 +189,7 @@ class DripDrop
|
|
173
189
|
identities = messages[0..-2].map {|m| m.copy_out_string}
|
174
190
|
body = messages.last.copy_out_string
|
175
191
|
message = decode_message(body)
|
176
|
-
seq = message.head[
|
192
|
+
seq = message.head[SEQ_CTR_KEY]
|
177
193
|
response = ZMQXRepHandler::Response.new(self, identities,seq)
|
178
194
|
@recv_cbak.call(message,response)
|
179
195
|
else
|
@@ -183,10 +199,13 @@ class DripDrop
|
|
183
199
|
|
184
200
|
def send_message(message,identities,seq)
|
185
201
|
if message.is_a?(DripDrop::Message)
|
186
|
-
message.head[
|
187
|
-
|
202
|
+
message.head[SEQ_CTR_KEY] = seq
|
203
|
+
|
204
|
+
resp = identities + ['', message.encoded]
|
205
|
+
super(resp)
|
188
206
|
else
|
189
|
-
|
207
|
+
resp = identities + ['', message]
|
208
|
+
super(resp)
|
190
209
|
end
|
191
210
|
end
|
192
211
|
end
|
@@ -217,7 +236,7 @@ class DripDrop
|
|
217
236
|
@promises = {}
|
218
237
|
|
219
238
|
self.on_recv do |message|
|
220
|
-
seq = message.head[
|
239
|
+
seq = message.head[SEQ_CTR_KEY]
|
221
240
|
raise "Missing Seq Counter" unless seq
|
222
241
|
promise = @promises.delete(seq)
|
223
242
|
promise.call(message) if promise
|
@@ -228,11 +247,16 @@ class DripDrop
|
|
228
247
|
dd_message = dd_messagify(message)
|
229
248
|
if dd_message.is_a?(DripDrop::Message)
|
230
249
|
@seq_counter += 1
|
231
|
-
dd_message.head[
|
250
|
+
dd_message.head[SEQ_CTR_KEY] = @seq_counter
|
232
251
|
@promises[@seq_counter] = block if block
|
233
252
|
message = dd_message
|
234
253
|
end
|
235
254
|
super(message)
|
236
255
|
end
|
256
|
+
|
257
|
+
def on_readable(socket, messages)
|
258
|
+
# Strip out empty delimiter
|
259
|
+
super(socket, messages[1..-1])
|
260
|
+
end
|
237
261
|
end
|
238
262
|
end
|
@@ -7,7 +7,7 @@ describe "zmq xreq/xrep" do
|
|
7
7
|
req = nil
|
8
8
|
rep = nil
|
9
9
|
|
10
|
-
@node = run_reactor(
|
10
|
+
@node = run_reactor(1.5) do
|
11
11
|
addr = rand_addr
|
12
12
|
|
13
13
|
rep = zmq_xrep(addr, :bind)
|
@@ -41,12 +41,14 @@ describe "zmq xreq/xrep" do
|
|
41
41
|
|
42
42
|
it "should receive all sent messages in order" do
|
43
43
|
@sent.zip(@recvd).each do |sent,recvd|
|
44
|
+
recvd[:message].should be_a(DripDrop::Message)
|
44
45
|
recvd[:message].name.should == sent.name
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
49
|
it "should receive a reply message for each sent message" do
|
49
50
|
@sent.zip(@replied).each do |sent, replied|
|
51
|
+
replied.should be_a(DripDrop::Message)
|
50
52
|
replied.body['orig_name'].should == sent.name
|
51
53
|
end
|
52
54
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dripdrop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 61
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 3
|
10
|
+
version: 0.9.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Cholakian
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-02 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,10 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 1
|
30
30
|
segments:
|
31
31
|
- 0
|
32
|
-
|
32
|
+
- 7
|
33
|
+
- 1
|
34
|
+
version: 0.7.1
|
33
35
|
type: :runtime
|
34
36
|
version_requirements: *id001
|
35
37
|
- !ruby/object:Gem::Dependency
|
@@ -40,10 +42,12 @@ dependencies:
|
|
40
42
|
requirements:
|
41
43
|
- - ">="
|
42
44
|
- !ruby/object:Gem::Version
|
43
|
-
hash:
|
45
|
+
hash: 59
|
44
46
|
segments:
|
45
47
|
- 0
|
46
|
-
|
48
|
+
- 12
|
49
|
+
- 10
|
50
|
+
version: 0.12.10
|
47
51
|
type: :runtime
|
48
52
|
version_requirements: *id002
|
49
53
|
- !ruby/object:Gem::Dependency
|
@@ -82,10 +86,12 @@ dependencies:
|
|
82
86
|
requirements:
|
83
87
|
- - ">="
|
84
88
|
- !ruby/object:Gem::Version
|
85
|
-
hash:
|
89
|
+
hash: 31
|
86
90
|
segments:
|
87
91
|
- 0
|
88
|
-
|
92
|
+
- 1
|
93
|
+
- 2
|
94
|
+
version: 0.1.2
|
89
95
|
type: :runtime
|
90
96
|
version_requirements: *id005
|
91
97
|
- !ruby/object:Gem::Dependency
|