zmqmachine 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +14 -0
- data/History.txt +7 -0
- data/examples/fake_ftp.rb +4 -0
- data/examples/one_handed_ping_pong.rb +13 -6
- data/lib/zm/reactor.rb +20 -11
- data/lib/zm/sockets/base.rb +8 -3
- data/lib/zm/sockets.rb +1 -1
- data/lib/zm/timers.rb +27 -4
- data/version.txt +1 -1
- data/zmqmachine.gemspec +6 -6
- metadata +80 -79
data/.gitignore
ADDED
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 0.3.1 / 2010-08-16
|
2
|
+
* Forgot to load the xreq/xrep files during startup
|
3
|
+
* Added support for resetting a timer's firing schedule. Useful for when
|
4
|
+
the time source has been overridden; let's existing timers
|
5
|
+
reschedule themselves using the new time source.
|
6
|
+
* Fixed a logic bug with delivery of multi-part messages
|
7
|
+
|
1
8
|
== 0.3.0 / 2010-08-15
|
2
9
|
* Added XREQ/XREP socket types
|
3
10
|
* Moved the time functions for ZM::Timers into a pair of
|
data/examples/fake_ftp.rb
CHANGED
@@ -81,6 +81,10 @@ class FTPControlClient
|
|
81
81
|
def on_attach socket
|
82
82
|
@socket = socket
|
83
83
|
rc = socket.connect @address
|
84
|
+
|
85
|
+
# REQ sockets do not register for read events by default, so we need
|
86
|
+
# to turn that on here
|
87
|
+
@context.register_readable socket
|
84
88
|
end
|
85
89
|
|
86
90
|
def on_readable socket, messages
|
@@ -28,18 +28,25 @@ class PingPongHandler
|
|
28
28
|
rc = socket.bind address
|
29
29
|
when :request
|
30
30
|
rc = socket.connect address
|
31
|
-
|
32
|
-
@sent_count += 1
|
31
|
+
@context.register_readable socket
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
35
|
+
def on_writable socket
|
36
|
+
rc = socket.send_message_string "#{'a' * 2048}"
|
37
|
+
@sent_count += 1
|
38
|
+
|
39
|
+
# after sending the first message, deregister for future write events
|
40
|
+
@context.deregister_writable socket
|
41
|
+
end
|
42
|
+
|
36
43
|
def on_readable socket, messages
|
37
44
|
@received_count += 1
|
38
45
|
|
39
|
-
|
40
|
-
|
41
|
-
socket.
|
42
|
-
|
46
|
+
if :reply == socket.kind
|
47
|
+
#socket.send_message messages.first
|
48
|
+
rc = socket.send_message_string messages.first.copy_out_string
|
49
|
+
else
|
43
50
|
socket.send_message messages.first
|
44
51
|
end
|
45
52
|
|
data/lib/zm/reactor.rb
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
# Author:: Chuck Remes
|
4
4
|
# Homepage:: http://github.com/chuckremes/zmqmachine
|
5
5
|
# Date:: 20100602
|
6
|
-
#
|
6
|
+
#
|
7
7
|
#----------------------------------------------------------------------------
|
8
8
|
#
|
9
9
|
# Copyright (C) 2010 by Chuck Remes. All Rights Reserved.
|
10
10
|
# Email: cremes at mac dot com
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# (The MIT License)
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# Permission is hereby granted, free of charge, to any person obtaining
|
15
15
|
# a copy of this software and associated documentation files (the
|
16
16
|
# 'Software'), to deal in the Software without restriction, including
|
@@ -18,10 +18,10 @@
|
|
18
18
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
19
19
|
# permit persons to whom the Software is furnished to do so, subject to
|
20
20
|
# the following conditions:
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# The above copyright notice and this permission notice shall be
|
23
23
|
# included in all copies or substantial portions of the Software.
|
24
|
-
#
|
24
|
+
#
|
25
25
|
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
26
26
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
27
27
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
@@ -32,13 +32,13 @@
|
|
32
32
|
#
|
33
33
|
#---------------------------------------------------------------------------
|
34
34
|
#
|
35
|
-
#
|
35
|
+
#
|
36
36
|
|
37
37
|
module ZMQMachine
|
38
38
|
|
39
39
|
class Reactor
|
40
40
|
attr_reader :name
|
41
|
-
|
41
|
+
|
42
42
|
# +poll_interval+ is the number of milliseconds to block while
|
43
43
|
# waiting for new 0mq socket events; default is 0
|
44
44
|
#
|
@@ -61,7 +61,7 @@ module ZMQMachine
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# Returns true when the reactor is running OR while it is in the
|
64
|
-
# midst of a shutdown request.
|
64
|
+
# midst of a shutdown request.
|
65
65
|
#
|
66
66
|
# Returns false when the reactor thread does not exist.
|
67
67
|
#
|
@@ -124,12 +124,12 @@ module ZMQMachine
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
# Kills the running reactor instance by terminating its thread.
|
129
129
|
#
|
130
130
|
# After the thread exits, the reactor attempts to clean up after itself
|
131
131
|
# and kill any pending I/O.
|
132
|
-
#
|
132
|
+
#
|
133
133
|
def kill
|
134
134
|
@stopping = true
|
135
135
|
@thread.kill
|
@@ -273,7 +273,7 @@ module ZMQMachine
|
|
273
273
|
save_socket sock
|
274
274
|
sock
|
275
275
|
end
|
276
|
-
|
276
|
+
|
277
277
|
# Registers the +sock+ for POLLOUT events that will cause the
|
278
278
|
# reactor to call the handler's on_writable method.
|
279
279
|
#
|
@@ -332,6 +332,15 @@ module ZMQMachine
|
|
332
332
|
def cancel_timer timer
|
333
333
|
@timers.cancel timer
|
334
334
|
end
|
335
|
+
|
336
|
+
# Asks all timers to reschedule themselves starting from Timers.now.
|
337
|
+
# Typically called when the underlying time source for the ZM::Timers
|
338
|
+
# class has been replaced; existing timers may not fire as expected, so
|
339
|
+
# we ask them to reset themselves.
|
340
|
+
#
|
341
|
+
def reschedule_timers
|
342
|
+
@timers.reschedule
|
343
|
+
end
|
335
344
|
|
336
345
|
|
337
346
|
private
|
data/lib/zm/sockets/base.rb
CHANGED
@@ -113,8 +113,8 @@ module ZMQMachine
|
|
113
113
|
#
|
114
114
|
# May raise a ZMQ::SocketError.
|
115
115
|
#
|
116
|
-
def send_message_string message
|
117
|
-
queued = @raw_socket.send_string message, ZMQ::NOBLOCK
|
116
|
+
def send_message_string message, multipart = false
|
117
|
+
queued = @raw_socket.send_string message, ZMQ::NOBLOCK | (multipart ? ZMQ::SNDMORE : 0)
|
118
118
|
queued
|
119
119
|
end
|
120
120
|
|
@@ -159,15 +159,19 @@ module ZMQMachine
|
|
159
159
|
def resume_read
|
160
160
|
messages = []
|
161
161
|
rc = read_message_part messages
|
162
|
+
#puts "resume_read: rc1 [#{rc}], more_parts? [#{@raw_socket.more_parts?}]"
|
162
163
|
|
163
164
|
while 0 == rc && @raw_socket.more_parts?
|
165
|
+
#puts "get next part"
|
164
166
|
rc = read_message_part messages
|
167
|
+
#puts "resume_read: rc2 [#{rc}]"
|
165
168
|
end
|
169
|
+
#puts "no more parts, ready to deliver"
|
166
170
|
|
167
171
|
# only deliver the messages when rc is 0; otherwise, we
|
168
172
|
# may have gotten EAGAIN and no message was read;
|
169
173
|
# don't deliver empty messages
|
170
|
-
deliver messages, rc
|
174
|
+
deliver messages, rc if 0 == rc
|
171
175
|
end
|
172
176
|
|
173
177
|
# Used by the reactor. Never called by user code.
|
@@ -201,6 +205,7 @@ module ZMQMachine
|
|
201
205
|
end
|
202
206
|
|
203
207
|
def deliver messages, rc
|
208
|
+
#puts "deliver: rc [#{rc}], messages #{messages.inspect}"
|
204
209
|
if 0 == rc
|
205
210
|
@state = :ready
|
206
211
|
@handler.on_readable self, messages
|
data/lib/zm/sockets.rb
CHANGED
data/lib/zm/timers.rb
CHANGED
@@ -122,6 +122,19 @@ module ZMQMachine
|
|
122
122
|
save.each { |timer| @timers.add timer }
|
123
123
|
end
|
124
124
|
|
125
|
+
# Runs through all timers and asks each one to reschedule itself
|
126
|
+
# from Timers.now + whatever delay was originally recorded.
|
127
|
+
#
|
128
|
+
def reschedule
|
129
|
+
timers = @timers.dup
|
130
|
+
@timers.clear
|
131
|
+
|
132
|
+
timers.each do |timer|
|
133
|
+
timer.reschedule
|
134
|
+
@timers.add timer
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
125
138
|
# Returns the current time using the following algo:
|
126
139
|
#
|
127
140
|
# (Time.now.to_f * 1000).to_i
|
@@ -158,6 +171,7 @@ module ZMQMachine
|
|
158
171
|
attr_reader :fire_time
|
159
172
|
|
160
173
|
# +time+ is in milliseconds
|
174
|
+
#
|
161
175
|
def initialize timers, delay, periodical, timer_proc = nil, &blk
|
162
176
|
@timers = timers
|
163
177
|
@delay = delay.to_i
|
@@ -178,6 +192,8 @@ module ZMQMachine
|
|
178
192
|
schedule_firing_time if @periodical
|
179
193
|
end
|
180
194
|
|
195
|
+
# Cancels this timer from firing.
|
196
|
+
#
|
181
197
|
def cancel
|
182
198
|
@timers.cancel self
|
183
199
|
end
|
@@ -186,14 +202,22 @@ module ZMQMachine
|
|
186
202
|
self.fire_time <=> other.fire_time
|
187
203
|
end
|
188
204
|
|
205
|
+
# True when the timer should be fired; false otherwise.
|
206
|
+
#
|
189
207
|
def expired? time
|
190
208
|
time ||= now
|
191
209
|
time > @fire_time
|
192
210
|
end
|
193
211
|
|
212
|
+
# True when this is a periodical timer; false otherwise.
|
213
|
+
#
|
194
214
|
def periodical?
|
195
215
|
@periodical
|
196
216
|
end
|
217
|
+
|
218
|
+
def reschedule
|
219
|
+
schedule_firing_time
|
220
|
+
end
|
197
221
|
|
198
222
|
|
199
223
|
private
|
@@ -209,12 +233,11 @@ module ZMQMachine
|
|
209
233
|
# next timer to fire at, 17 + delay 5 = 22
|
210
234
|
# had it not been late, it would fire at 20
|
211
235
|
def schedule_firing_time
|
212
|
-
@
|
236
|
+
@initiated = Timers.now
|
237
|
+
|
238
|
+
@fire_time = @initiated + @delay
|
213
239
|
end
|
214
240
|
|
215
|
-
def now
|
216
|
-
Timers.now
|
217
|
-
end
|
218
241
|
end # class Timer
|
219
242
|
|
220
243
|
end # module ZMQMachine
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/zmqmachine.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{zmqmachine}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Chuck Remes"]
|
9
|
-
s.date = %q{2010-08-
|
9
|
+
s.date = %q{2010-08-16}
|
10
10
|
s.description = %q{ZMQMachine is another Ruby implementation of the reactor pattern but this
|
11
11
|
time using 0mq sockets rather than POSIX sockets.
|
12
12
|
|
@@ -22,7 +22,7 @@ It is possible to extend the 0mq library to "poll" normal file
|
|
22
22
|
descriptors. This isn't on my roadmap but patches are accepted.}
|
23
23
|
s.email = %q{cremes@mac.com}
|
24
24
|
s.extra_rdoc_files = ["History.txt", "README.rdoc", "version.txt"]
|
25
|
-
s.files = [".bnsignore", "History.txt", "README.rdoc", "Rakefile", "examples/fake_ftp.rb", "examples/one_handed_ping_pong.rb", "examples/ping_pong.rb", "examples/pub_sub.rb", "examples/throttled_ping_pong.rb", "lib/zm/address.rb", "lib/zm/deferrable.rb", "lib/zm/exceptions.rb", "lib/zm/message.rb", "lib/zm/reactor.rb", "lib/zm/sockets.rb", "lib/zm/sockets/base.rb", "lib/zm/sockets/pair.rb", "lib/zm/sockets/pub.rb", "lib/zm/sockets/rep.rb", "lib/zm/sockets/req.rb", "lib/zm/sockets/sub.rb", "lib/zm/sockets/xrep.rb", "lib/zm/sockets/xreq.rb", "lib/zm/timers.rb", "lib/zmqmachine.rb", "spec/spec_helper.rb", "spec/zmqmachine_spec.rb", "version.txt", "zmqmachine.gemspec"]
|
25
|
+
s.files = [".bnsignore", ".gitignore", "History.txt", "README.rdoc", "Rakefile", "examples/fake_ftp.rb", "examples/one_handed_ping_pong.rb", "examples/ping_pong.rb", "examples/pub_sub.rb", "examples/throttled_ping_pong.rb", "lib/zm/address.rb", "lib/zm/deferrable.rb", "lib/zm/exceptions.rb", "lib/zm/message.rb", "lib/zm/reactor.rb", "lib/zm/sockets.rb", "lib/zm/sockets/base.rb", "lib/zm/sockets/pair.rb", "lib/zm/sockets/pub.rb", "lib/zm/sockets/rep.rb", "lib/zm/sockets/req.rb", "lib/zm/sockets/sub.rb", "lib/zm/sockets/xrep.rb", "lib/zm/sockets/xreq.rb", "lib/zm/timers.rb", "lib/zmqmachine.rb", "spec/spec_helper.rb", "spec/zmqmachine_spec.rb", "version.txt", "zmqmachine.gemspec"]
|
26
26
|
s.homepage = %q{http://github.com/chuckremes/zmqmachine}
|
27
27
|
s.rdoc_options = ["--main", "README.rdoc"]
|
28
28
|
s.require_paths = ["lib"]
|
@@ -36,13 +36,13 @@ descriptors. This isn't on my roadmap but patches are accepted.}
|
|
36
36
|
|
37
37
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
38
38
|
s.add_runtime_dependency(%q<ffi-rzmq>, [">= 0.5.0"])
|
39
|
-
s.add_development_dependency(%q<bones>, [">= 3.4.
|
39
|
+
s.add_development_dependency(%q<bones>, [">= 3.4.7"])
|
40
40
|
else
|
41
41
|
s.add_dependency(%q<ffi-rzmq>, [">= 0.5.0"])
|
42
|
-
s.add_dependency(%q<bones>, [">= 3.4.
|
42
|
+
s.add_dependency(%q<bones>, [">= 3.4.7"])
|
43
43
|
end
|
44
44
|
else
|
45
45
|
s.add_dependency(%q<ffi-rzmq>, [">= 0.5.0"])
|
46
|
-
s.add_dependency(%q<bones>, [">= 3.4.
|
46
|
+
s.add_dependency(%q<bones>, [">= 3.4.7"])
|
47
47
|
end
|
48
48
|
end
|
metadata
CHANGED
@@ -3,48 +3,48 @@ name: zmqmachine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
version: 0.3.
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
|
-
- Chuck Remes
|
12
|
+
- Chuck Remes
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-16 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: ffi-rzmq
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 5
|
30
|
+
- 0
|
31
|
+
version: 0.5.0
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: bones
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 3
|
43
|
+
- 4
|
44
|
+
- 7
|
45
|
+
version: 3.4.7
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
48
|
description: |-
|
49
49
|
ZMQMachine is another Ruby implementation of the reactor pattern but this
|
50
50
|
time using 0mq sockets rather than POSIX sockets.
|
@@ -65,63 +65,64 @@ executables: []
|
|
65
65
|
extensions: []
|
66
66
|
|
67
67
|
extra_rdoc_files:
|
68
|
-
- History.txt
|
69
|
-
- README.rdoc
|
70
|
-
- version.txt
|
68
|
+
- History.txt
|
69
|
+
- README.rdoc
|
70
|
+
- version.txt
|
71
71
|
files:
|
72
|
-
- .bnsignore
|
73
|
-
-
|
74
|
-
-
|
75
|
-
-
|
76
|
-
-
|
77
|
-
- examples/
|
78
|
-
- examples/
|
79
|
-
- examples/
|
80
|
-
- examples/
|
81
|
-
-
|
82
|
-
- lib/zm/
|
83
|
-
- lib/zm/
|
84
|
-
- lib/zm/
|
85
|
-
- lib/zm/
|
86
|
-
- lib/zm/
|
87
|
-
- lib/zm/sockets
|
88
|
-
- lib/zm/sockets/
|
89
|
-
- lib/zm/sockets/
|
90
|
-
- lib/zm/sockets/
|
91
|
-
- lib/zm/sockets/
|
92
|
-
- lib/zm/sockets/
|
93
|
-
- lib/zm/sockets/
|
94
|
-
- lib/zm/sockets/
|
95
|
-
- lib/zm/
|
96
|
-
- lib/
|
97
|
-
-
|
98
|
-
- spec/
|
99
|
-
-
|
100
|
-
-
|
72
|
+
- .bnsignore
|
73
|
+
- .gitignore
|
74
|
+
- History.txt
|
75
|
+
- README.rdoc
|
76
|
+
- Rakefile
|
77
|
+
- examples/fake_ftp.rb
|
78
|
+
- examples/one_handed_ping_pong.rb
|
79
|
+
- examples/ping_pong.rb
|
80
|
+
- examples/pub_sub.rb
|
81
|
+
- examples/throttled_ping_pong.rb
|
82
|
+
- lib/zm/address.rb
|
83
|
+
- lib/zm/deferrable.rb
|
84
|
+
- lib/zm/exceptions.rb
|
85
|
+
- lib/zm/message.rb
|
86
|
+
- lib/zm/reactor.rb
|
87
|
+
- lib/zm/sockets.rb
|
88
|
+
- lib/zm/sockets/base.rb
|
89
|
+
- lib/zm/sockets/pair.rb
|
90
|
+
- lib/zm/sockets/pub.rb
|
91
|
+
- lib/zm/sockets/rep.rb
|
92
|
+
- lib/zm/sockets/req.rb
|
93
|
+
- lib/zm/sockets/sub.rb
|
94
|
+
- lib/zm/sockets/xrep.rb
|
95
|
+
- lib/zm/sockets/xreq.rb
|
96
|
+
- lib/zm/timers.rb
|
97
|
+
- lib/zmqmachine.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/zmqmachine_spec.rb
|
100
|
+
- version.txt
|
101
|
+
- zmqmachine.gemspec
|
101
102
|
has_rdoc: true
|
102
103
|
homepage: http://github.com/chuckremes/zmqmachine
|
103
104
|
licenses: []
|
104
105
|
|
105
106
|
post_install_message:
|
106
107
|
rdoc_options:
|
107
|
-
- --main
|
108
|
-
- README.rdoc
|
108
|
+
- --main
|
109
|
+
- README.rdoc
|
109
110
|
require_paths:
|
110
|
-
- lib
|
111
|
+
- lib
|
111
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
112
113
|
requirements:
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
118
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
120
|
requirements:
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
125
126
|
requirements: []
|
126
127
|
|
127
128
|
rubyforge_project: zmqmachine
|