zmqmachine 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +22 -0
- data/lib/zm/log_client.rb +9 -2
- data/lib/zm/reactor.rb +77 -13
- data/lib/zm/sockets/base.rb +14 -17
- data/lib/zm/sockets/pull.rb +78 -0
- data/lib/zm/sockets/push.rb +79 -0
- data/lib/zm/sockets.rb +1 -1
- data/lib/zm/timers.rb +26 -9
- data/version.txt +1 -1
- data/zmqmachine.gemspec +3 -3
- metadata +74 -93
data/History.txt
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
== 0.5.2 / 2011-07-21
|
2
|
+
* Added PUSH and PULL socket types. Never needed them until now.
|
3
|
+
* Added a +context+ reader to the Reactor class.
|
4
|
+
* Changed default behavior for all sockets to use ZMQ:LINGER 1
|
5
|
+
as a socket option. By default, this prevents a call to
|
6
|
+
#close from hanging forever if there are unsent messages in
|
7
|
+
queue.
|
8
|
+
* Expose #logger accessor (read-only).
|
9
|
+
* Refactored Reactor#log so that most of the work is performed in
|
10
|
+
the LogClient (tell, don't ask!).
|
11
|
+
* Added LogClient#puts so that a logger instance can be passed to
|
12
|
+
other objects who expect an IO-like object that responds to #puts.
|
13
|
+
|
14
|
+
== 0.5.1 / 2011-05-03
|
15
|
+
* Added Reactor#oneshot_timer_at for scheduling a timer to fire at
|
16
|
+
an exact time.
|
17
|
+
* Changed Reactor#next_tick to use #shift instead of #pop for running
|
18
|
+
blocks. Originally it was running the blocks in the reverse order
|
19
|
+
that #next_tick was called. Blocks are now run in the *same* order
|
20
|
+
as they were created by a call to #next_tick.
|
21
|
+
* Added a timestamp to all messages created using Reactor#log.
|
22
|
+
|
1
23
|
== 0.5.0 / 2011-03-3
|
2
24
|
* Changed the constructor for the ZM::Reactor class. It now takes
|
3
25
|
an optional third hash argument. One of the keys that it uses
|
data/lib/zm/log_client.rb
CHANGED
@@ -71,10 +71,17 @@ module ZMQMachine
|
|
71
71
|
# All messages passed here are guaranteed to be written in the *order they were
|
72
72
|
# received*.
|
73
73
|
#
|
74
|
-
def write
|
75
|
-
|
74
|
+
def write level, message
|
75
|
+
now = Time.now
|
76
|
+
usec = sprintf "%06d", now.usec
|
77
|
+
timestamp = now.strftime "%Y%m%d-%H:%M:%S.#{usec} %Z"
|
78
|
+
@message_queue << [ZMQ::Message.new(level.to_s), ZMQ::Message.new(timestamp), ZMQ::Message.new(message.to_s)]
|
76
79
|
write_queue_to_socket
|
77
80
|
end
|
81
|
+
|
82
|
+
def puts string
|
83
|
+
write 'untagged', string
|
84
|
+
end
|
78
85
|
|
79
86
|
# Prints each message when global debugging is enabled.
|
80
87
|
#
|
data/lib/zm/reactor.rb
CHANGED
@@ -37,7 +37,7 @@
|
|
37
37
|
module ZMQMachine
|
38
38
|
|
39
39
|
class Reactor
|
40
|
-
attr_reader :name
|
40
|
+
attr_reader :name, :context, :logger
|
41
41
|
|
42
42
|
# +name+ provides a name for this reactor instance. It's unused
|
43
43
|
# at present but may be used in the future for allowing multiple
|
@@ -73,7 +73,14 @@ module ZMQMachine
|
|
73
73
|
@proc_queue_mutex = Mutex.new
|
74
74
|
|
75
75
|
# could raise if it fails
|
76
|
-
@context = opts[:zeromq_context]
|
76
|
+
@context = if opts[:zeromq_context]
|
77
|
+
@shared_context = true
|
78
|
+
opts[:zeromq_context]
|
79
|
+
else
|
80
|
+
@shared_context = false
|
81
|
+
ZMQ::Context.new
|
82
|
+
end
|
83
|
+
|
77
84
|
@poller = ZMQ::Poller.new
|
78
85
|
@sockets = []
|
79
86
|
@raw_to_socket = {}
|
@@ -85,6 +92,10 @@ module ZMQMachine
|
|
85
92
|
end
|
86
93
|
end
|
87
94
|
|
95
|
+
def shared_context?
|
96
|
+
@shared_context
|
97
|
+
end
|
98
|
+
|
88
99
|
# Returns true when the reactor is running OR while it is in the
|
89
100
|
# midst of a shutdown request.
|
90
101
|
#
|
@@ -115,16 +126,16 @@ module ZMQMachine
|
|
115
126
|
end
|
116
127
|
|
117
128
|
# Marks the reactor as eligible for termination. Then waits for the
|
118
|
-
# reactor thread to exit via #join (
|
129
|
+
# reactor thread to exit via #join (optional timeout).
|
119
130
|
#
|
120
131
|
# The reactor is not forcibly terminated if it is currently blocked
|
121
132
|
# by some long-running operation. Use #kill to forcibly terminate
|
122
133
|
# the reactor.
|
123
134
|
#
|
124
|
-
def stop
|
135
|
+
def stop delay = nil
|
125
136
|
# wait until the thread loops around again and exits on its own
|
126
137
|
@stopping = true
|
127
|
-
join
|
138
|
+
join delay
|
128
139
|
end
|
129
140
|
|
130
141
|
# Join on the thread running this reactor instance. Default behavior
|
@@ -157,9 +168,9 @@ module ZMQMachine
|
|
157
168
|
#
|
158
169
|
def kill
|
159
170
|
if running?
|
171
|
+
cleanup
|
160
172
|
@stopping = true
|
161
173
|
@thread.kill
|
162
|
-
cleanup
|
163
174
|
end
|
164
175
|
end
|
165
176
|
|
@@ -307,6 +318,40 @@ module ZMQMachine
|
|
307
318
|
sock
|
308
319
|
end
|
309
320
|
|
321
|
+
# Creates a PUSH socket and attaches +handler_instance+ to the
|
322
|
+
# resulting socket. Usually paired with one or more
|
323
|
+
# #pull_socket in the same or different reactor context.
|
324
|
+
#
|
325
|
+
# +handler_instance+ must implement the #on_writable and
|
326
|
+
# #on_writable_error methods. The reactor will call those methods
|
327
|
+
# based upon new events. This socket type can *only* write; it
|
328
|
+
# can never recv messages.
|
329
|
+
#
|
330
|
+
# All handlers must implement the #on_attach method.
|
331
|
+
#
|
332
|
+
def push_socket handler_instance
|
333
|
+
sock = ZMQMachine::Socket::Push.new @context, handler_instance
|
334
|
+
save_socket sock
|
335
|
+
sock
|
336
|
+
end
|
337
|
+
|
338
|
+
# Creates a PULL socket and attaches +handler_instance+ to the
|
339
|
+
# resulting socket. Usually paired with one or more
|
340
|
+
# #push_socket in the same or different reactor context.
|
341
|
+
#
|
342
|
+
# +handler_instance+ must implement the #on_readable and
|
343
|
+
# #on_readable_error methods. The reactor will call those methods
|
344
|
+
# based upon new events. This socket type can *only* read; it
|
345
|
+
# can never write/send messages.
|
346
|
+
#
|
347
|
+
# All handlers must implement the #on_attach method.
|
348
|
+
#
|
349
|
+
def pull_socket handler_instance
|
350
|
+
sock = ZMQMachine::Socket::Pull.new @context, handler_instance
|
351
|
+
save_socket sock
|
352
|
+
sock
|
353
|
+
end
|
354
|
+
|
310
355
|
# Registers the +sock+ for POLLOUT events that will cause the
|
311
356
|
# reactor to call the handler's on_writable method.
|
312
357
|
#
|
@@ -346,6 +391,16 @@ module ZMQMachine
|
|
346
391
|
@timers.add_oneshot delay, blk
|
347
392
|
end
|
348
393
|
|
394
|
+
# Creates a timer that will fire once at a specific
|
395
|
+
# time as returned by ZM::Timers.now_converted.
|
396
|
+
#
|
397
|
+
# +exact_time+ may be either a Time object or a Numeric.
|
398
|
+
#
|
399
|
+
def oneshot_timer_at exact_time, timer_proc = nil, &blk
|
400
|
+
blk ||= timer_proc
|
401
|
+
@timers.add_oneshot_at exact_time, blk
|
402
|
+
end
|
403
|
+
|
349
404
|
# Creates a timer that will fire every +delay+ milliseconds until
|
350
405
|
# it is explicitly cancelled. Expects either a +timer_proc+ proc
|
351
406
|
# or a block, otherwise no timer is created.
|
@@ -405,9 +460,14 @@ module ZMQMachine
|
|
405
460
|
# When no :log_transport was defined when creating the Reactor, all calls
|
406
461
|
# just discard the messages.
|
407
462
|
#
|
463
|
+
# reactor.log(:info, "some message")
|
464
|
+
#
|
465
|
+
# This produces output that looks like:
|
466
|
+
# info|20110526-10:23:47.768796 CDT|some message
|
467
|
+
#
|
408
468
|
def log level, message
|
409
469
|
if @logging_enabled
|
410
|
-
@logger.write
|
470
|
+
@logger.write level, message
|
411
471
|
end
|
412
472
|
end
|
413
473
|
|
@@ -423,9 +483,11 @@ module ZMQMachine
|
|
423
483
|
# Close each open socket and terminate the reactor context; this will
|
424
484
|
# release the native memory backing each of these objects
|
425
485
|
def cleanup
|
486
|
+
@proc_queue_mutex.synchronize { @proc_queue.clear }
|
487
|
+
|
426
488
|
# work on a dup since #close_socket deletes from @sockets
|
427
489
|
@sockets.dup.each { |sock| close_socket sock }
|
428
|
-
@context.terminate
|
490
|
+
@context.terminate unless shared_context?
|
429
491
|
@running = false
|
430
492
|
end
|
431
493
|
|
@@ -443,7 +505,7 @@ module ZMQMachine
|
|
443
505
|
end
|
444
506
|
|
445
507
|
until work.empty? do
|
446
|
-
work.
|
508
|
+
work.shift.call
|
447
509
|
end
|
448
510
|
end
|
449
511
|
|
@@ -454,7 +516,7 @@ module ZMQMachine
|
|
454
516
|
# doing so spikes the CPU even though there is no work to do
|
455
517
|
# take a short nap here (10ms by default) unless there are procs scheduled
|
456
518
|
# to run (e.g. via next_tick)
|
457
|
-
sleep(@poll_interval / 1000)
|
519
|
+
sleep(@poll_interval / 1000.0)
|
458
520
|
else
|
459
521
|
@poller.poll @poll_interval
|
460
522
|
end
|
@@ -472,9 +534,11 @@ module ZMQMachine
|
|
472
534
|
# Returns true when all steps succeed, false otherwise
|
473
535
|
#
|
474
536
|
def delete_socket sock
|
475
|
-
@poller.delete(sock.raw_socket)
|
476
|
-
@sockets.delete(sock)
|
477
|
-
@raw_to_socket.delete(sock.raw_socket)
|
537
|
+
poll_deleted = @poller.delete(sock.raw_socket)
|
538
|
+
sockets_deleted = @sockets.delete(sock)
|
539
|
+
ffi_deleted = @raw_to_socket.delete(sock.raw_socket)
|
540
|
+
|
541
|
+
poll_deleted && sockets_deleted && ffi_deleted
|
478
542
|
end
|
479
543
|
|
480
544
|
|
data/lib/zm/sockets/base.rb
CHANGED
@@ -43,13 +43,16 @@ module ZMQMachine
|
|
43
43
|
attr_reader :poll_options
|
44
44
|
|
45
45
|
def initialize context, handler
|
46
|
-
@state = :init
|
47
46
|
@context = context
|
48
47
|
@bindings = []
|
49
48
|
@connections = []
|
50
49
|
|
51
50
|
@handler = handler
|
52
51
|
@raw_socket = allocate_socket @context
|
52
|
+
|
53
|
+
# default ZMQ::LINGER to 1 millisecond so closing a socket
|
54
|
+
# doesn't block forever
|
55
|
+
@raw_socket.setsockopt ZMQ::LINGER, 1
|
53
56
|
attach @handler
|
54
57
|
end
|
55
58
|
|
@@ -168,13 +171,13 @@ module ZMQMachine
|
|
168
171
|
|
169
172
|
# loop and deliver all messages until the socket returns EAGAIN
|
170
173
|
while 0 == rc
|
171
|
-
|
172
|
-
rc = read_message_part
|
174
|
+
parts = []
|
175
|
+
rc = read_message_part parts
|
173
176
|
#puts "resume_read: rc1 [#{rc}], more_parts? [#{@raw_socket.more_parts?}]"
|
174
177
|
|
175
178
|
while 0 == rc && @raw_socket.more_parts?
|
176
179
|
#puts "get next part"
|
177
|
-
rc = read_message_part
|
180
|
+
rc = read_message_part parts
|
178
181
|
#puts "resume_read: rc2 [#{rc}]"
|
179
182
|
end
|
180
183
|
#puts "no more parts, ready to deliver"
|
@@ -182,36 +185,31 @@ module ZMQMachine
|
|
182
185
|
# only deliver the messages when rc is 0; otherwise, we
|
183
186
|
# may have gotten EAGAIN and no message was read;
|
184
187
|
# don't deliver empty messages
|
185
|
-
deliver
|
188
|
+
deliver parts, rc if 0 == rc
|
186
189
|
end
|
187
190
|
end
|
188
191
|
|
189
192
|
# Used by the reactor. Never called by user code.
|
190
193
|
#
|
191
194
|
def resume_write
|
192
|
-
@state = :ready
|
193
195
|
@handler.on_writable self
|
194
196
|
end
|
195
197
|
|
196
198
|
def inspect
|
197
|
-
"kind [#{@kind}] poll options [#{@poll_options}]
|
199
|
+
"kind [#{@kind}] poll options [#{@poll_options}]"
|
198
200
|
end
|
199
201
|
|
200
202
|
|
201
203
|
private
|
202
204
|
|
203
|
-
def
|
204
|
-
:ready == @state
|
205
|
-
end
|
206
|
-
|
207
|
-
def read_message_part messages
|
205
|
+
def read_message_part parts
|
208
206
|
message = ZMQ::Message.new
|
209
207
|
begin
|
210
208
|
rc = @raw_socket.recv message, ZMQ::NOBLOCK
|
211
209
|
|
212
210
|
if rc
|
213
211
|
rc = 0 # callers expect 0 for success, not true
|
214
|
-
|
212
|
+
parts << message
|
215
213
|
else
|
216
214
|
# got EAGAIN most likely
|
217
215
|
message.close
|
@@ -227,11 +225,10 @@ module ZMQMachine
|
|
227
225
|
rc
|
228
226
|
end
|
229
227
|
|
230
|
-
def deliver
|
231
|
-
#puts "deliver: rc [#{rc}],
|
228
|
+
def deliver parts, rc
|
229
|
+
#puts "deliver: rc [#{rc}], parts #{parts.inspect}"
|
232
230
|
if 0 == rc
|
233
|
-
@
|
234
|
-
@handler.on_readable self, messages
|
231
|
+
@handler.on_readable self, parts
|
235
232
|
else
|
236
233
|
# this branch is never called
|
237
234
|
@handler.on_readable_error self, rc
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Author:: Chuck Remes
|
4
|
+
# Homepage:: http://github.com/chuckremes/zmqmachine
|
5
|
+
# Date:: 20110721
|
6
|
+
#
|
7
|
+
#----------------------------------------------------------------------------
|
8
|
+
#
|
9
|
+
# Copyright (C) 2011 by Chuck Remes. All Rights Reserved.
|
10
|
+
# Email: cremes at mac dot com
|
11
|
+
#
|
12
|
+
# (The MIT License)
|
13
|
+
#
|
14
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
15
|
+
# a copy of this software and associated documentation files (the
|
16
|
+
# 'Software'), to deal in the Software without restriction, including
|
17
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
18
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
19
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
20
|
+
# the following conditions:
|
21
|
+
#
|
22
|
+
# The above copyright notice and this permission notice shall be
|
23
|
+
# included in all copies or substantial portions of the Software.
|
24
|
+
#
|
25
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
26
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
27
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
28
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
29
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
30
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
31
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
32
|
+
#
|
33
|
+
#---------------------------------------------------------------------------
|
34
|
+
#
|
35
|
+
#
|
36
|
+
|
37
|
+
module ZMQMachine
|
38
|
+
|
39
|
+
module Socket
|
40
|
+
|
41
|
+
class Pull
|
42
|
+
include ZMQMachine::Socket::Base
|
43
|
+
|
44
|
+
def initialize context, handler
|
45
|
+
@poll_options = ZMQ::POLLIN
|
46
|
+
@kind = :pull
|
47
|
+
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
# Attach a handler to the PULL socket.
|
52
|
+
#
|
53
|
+
# A PULL socket may *only* receive messages.
|
54
|
+
#
|
55
|
+
# This socket expects its +handler+ to
|
56
|
+
# implement the #on_readable method.
|
57
|
+
# The #on_readable method will be called whenever a
|
58
|
+
# message may be dequeued without blocking.
|
59
|
+
#
|
60
|
+
# For error handling purposes, the handler must also
|
61
|
+
# implement #on_readable_error.
|
62
|
+
#
|
63
|
+
def on_attach handler
|
64
|
+
raise ArgumentError, "Handler must implement an #on_readable method" unless handler.respond_to? :on_readable
|
65
|
+
raise ArgumentError, "Handler must implement an #on_readable_error method" unless handler.respond_to? :on_readable_error
|
66
|
+
super
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def allocate_socket context
|
72
|
+
ZMQ::Socket.new context.pointer, ZMQ::PULL
|
73
|
+
end
|
74
|
+
end # class Pull
|
75
|
+
|
76
|
+
end # module Socket
|
77
|
+
|
78
|
+
end # module ZMQMachine
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Author:: Chuck Remes
|
4
|
+
# Homepage:: http://github.com/chuckremes/zmqmachine
|
5
|
+
# Date:: 20110721
|
6
|
+
#
|
7
|
+
#----------------------------------------------------------------------------
|
8
|
+
#
|
9
|
+
# Copyright (C) 2011 by Chuck Remes. All Rights Reserved.
|
10
|
+
# Email: cremes at mac dot com
|
11
|
+
#
|
12
|
+
# (The MIT License)
|
13
|
+
#
|
14
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
15
|
+
# a copy of this software and associated documentation files (the
|
16
|
+
# 'Software'), to deal in the Software without restriction, including
|
17
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
18
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
19
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
20
|
+
# the following conditions:
|
21
|
+
#
|
22
|
+
# The above copyright notice and this permission notice shall be
|
23
|
+
# included in all copies or substantial portions of the Software.
|
24
|
+
#
|
25
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
26
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
27
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
28
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
29
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
30
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
31
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
32
|
+
#
|
33
|
+
#---------------------------------------------------------------------------
|
34
|
+
#
|
35
|
+
#
|
36
|
+
|
37
|
+
module ZMQMachine
|
38
|
+
|
39
|
+
module Socket
|
40
|
+
|
41
|
+
class Push
|
42
|
+
include ZMQMachine::Socket::Base
|
43
|
+
|
44
|
+
def initialize context, handler
|
45
|
+
@poll_options = ZMQ::POLLOUT
|
46
|
+
@kind = :push
|
47
|
+
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
# Attach a handler to the PUSH socket.
|
52
|
+
#
|
53
|
+
# A PUSH socket may *only* send messages.
|
54
|
+
#
|
55
|
+
# This socket expects its +handler+ to
|
56
|
+
# implement the #on_writable methods.
|
57
|
+
# The #on_writable method will be called whenever a
|
58
|
+
# message may be enqueued without blocking.
|
59
|
+
#
|
60
|
+
# For error handling purposes, the handler must also
|
61
|
+
# implement #on_writable_error.
|
62
|
+
#
|
63
|
+
def on_attach handler
|
64
|
+
raise ArgumentError, "Handler must implement an #on_writable method" unless handler.respond_to? :on_writable
|
65
|
+
raise ArgumentError, "Handler must implement an #on_writable_error method" unless handler.respond_to? :on_writable_error
|
66
|
+
super
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def allocate_socket context
|
72
|
+
sock = ZMQ::Socket.new context.pointer, ZMQ::PUSH
|
73
|
+
sock
|
74
|
+
end
|
75
|
+
end # class Push
|
76
|
+
|
77
|
+
end # module Socket
|
78
|
+
|
79
|
+
end # module ZMQMachine
|
data/lib/zm/sockets.rb
CHANGED
data/lib/zm/timers.rb
CHANGED
@@ -66,7 +66,19 @@ module ZMQMachine
|
|
66
66
|
blk ||= timer_proc
|
67
67
|
return nil unless blk
|
68
68
|
|
69
|
-
timer = Timer.new self, delay, false, blk
|
69
|
+
timer = Timer.new :timers => self, :delay => delay, :periodical => false, :timer_proc => blk
|
70
|
+
add timer
|
71
|
+
timer
|
72
|
+
end
|
73
|
+
|
74
|
+
# Adds a non-periodical, one-shot timer to be fired at
|
75
|
+
# the specified time.
|
76
|
+
#
|
77
|
+
def add_oneshot_at exact_time, timer_proc = nil, &blk
|
78
|
+
blk ||= timer_proc
|
79
|
+
return nil unless blk
|
80
|
+
|
81
|
+
timer = Timer.new :timers => self, :exact_time => exact_time, :periodical => false, :timer_proc => blk
|
70
82
|
add timer
|
71
83
|
timer
|
72
84
|
end
|
@@ -82,7 +94,7 @@ module ZMQMachine
|
|
82
94
|
blk ||= timer_proc
|
83
95
|
return nil unless blk
|
84
96
|
|
85
|
-
timer = Timer.new self, delay, true, blk
|
97
|
+
timer = Timer.new :timers => self, :delay => delay, :periodical => true, :timer_proc => blk
|
86
98
|
add timer
|
87
99
|
timer
|
88
100
|
end
|
@@ -249,11 +261,12 @@ module ZMQMachine
|
|
249
261
|
|
250
262
|
# +delay+ is in milliseconds
|
251
263
|
#
|
252
|
-
def initialize
|
253
|
-
@timers = timers
|
254
|
-
@delay = delay.to_i
|
255
|
-
@periodical = periodical
|
256
|
-
@timer_proc = timer_proc
|
264
|
+
def initialize opts
|
265
|
+
@timers = opts[:timers]
|
266
|
+
@delay = opts[:delay].to_i
|
267
|
+
@periodical = opts[:periodical]
|
268
|
+
@timer_proc = opts[:timer_proc]
|
269
|
+
@exact_time = opts[:exact_time]
|
257
270
|
schedule_firing_time
|
258
271
|
end
|
259
272
|
|
@@ -328,9 +341,13 @@ module ZMQMachine
|
|
328
341
|
# next timer to fire at, 17 + delay 5 = 22
|
329
342
|
# had it not been late, it would fire at 20
|
330
343
|
def schedule_firing_time
|
331
|
-
@
|
344
|
+
if @exact_time
|
345
|
+
@fire_time = @exact_time.to_f * 1_000
|
346
|
+
else
|
347
|
+
@initiated = Timers.now
|
332
348
|
|
333
|
-
|
349
|
+
@fire_time = @initiated + @delay
|
350
|
+
end
|
334
351
|
end
|
335
352
|
|
336
353
|
end # class Timer
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.2
|
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.5.
|
5
|
+
s.version = "0.5.2"
|
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{
|
9
|
+
s.date = %q{2011-07-21}
|
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/pubsub_forwarder.rb", "examples/throttled_ping_pong.rb", "lib/zm/address.rb", "lib/zm/deferrable.rb", "lib/zm/devices.rb", "lib/zm/devices/forwarder.rb", "lib/zm/devices/queue.rb", "lib/zm/exceptions.rb", "lib/zm/log_client.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/reactor_spec.rb", "version.txt", "zmqmachine.gemspec"]
|
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/pubsub_forwarder.rb", "examples/throttled_ping_pong.rb", "lib/zm/address.rb", "lib/zm/deferrable.rb", "lib/zm/devices.rb", "lib/zm/devices/forwarder.rb", "lib/zm/devices/queue.rb", "lib/zm/exceptions.rb", "lib/zm/log_client.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/sockets/push.rb", "lib/zm/sockets/pull.rb", "lib/zm/timers.rb", "lib/zmqmachine.rb", "spec/spec_helper.rb", "spec/reactor_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"]
|
metadata
CHANGED
@@ -1,55 +1,40 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zmqmachine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 11
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 0
|
10
|
-
version: 0.5.0
|
5
|
+
version: 0.5.2
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
|
-
- Chuck Remes
|
8
|
+
- Chuck Remes
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
13
|
+
date: 2011-07-21 00:00:00 -05:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 27
|
46
|
-
segments:
|
47
|
-
- 3
|
48
|
-
- 5
|
49
|
-
- 4
|
50
|
-
version: 3.5.4
|
51
|
-
type: :development
|
52
|
-
version_requirements: *id002
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: ffi-rzmq
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.7.0
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bones
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 3.5.4
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
53
38
|
description: |-
|
54
39
|
ZMQMachine is another Ruby implementation of the reactor pattern but this
|
55
40
|
time using 0mq sockets rather than POSIX sockets.
|
@@ -70,76 +55,72 @@ executables: []
|
|
70
55
|
extensions: []
|
71
56
|
|
72
57
|
extra_rdoc_files:
|
73
|
-
- History.txt
|
74
|
-
- README.rdoc
|
75
|
-
- version.txt
|
58
|
+
- History.txt
|
59
|
+
- README.rdoc
|
60
|
+
- version.txt
|
76
61
|
files:
|
77
|
-
- .bnsignore
|
78
|
-
- History.txt
|
79
|
-
- README.rdoc
|
80
|
-
- Rakefile
|
81
|
-
- examples/fake_ftp.rb
|
82
|
-
- examples/one_handed_ping_pong.rb
|
83
|
-
- examples/ping_pong.rb
|
84
|
-
- examples/pub_sub.rb
|
85
|
-
- examples/pubsub_forwarder.rb
|
86
|
-
- examples/throttled_ping_pong.rb
|
87
|
-
- lib/zm/address.rb
|
88
|
-
- lib/zm/deferrable.rb
|
89
|
-
- lib/zm/devices.rb
|
90
|
-
- lib/zm/devices/forwarder.rb
|
91
|
-
- lib/zm/devices/queue.rb
|
92
|
-
- lib/zm/exceptions.rb
|
93
|
-
- lib/zm/log_client.rb
|
94
|
-
- lib/zm/message.rb
|
95
|
-
- lib/zm/reactor.rb
|
96
|
-
- lib/zm/sockets.rb
|
97
|
-
- lib/zm/sockets/base.rb
|
98
|
-
- lib/zm/sockets/pair.rb
|
99
|
-
- lib/zm/sockets/pub.rb
|
100
|
-
- lib/zm/sockets/rep.rb
|
101
|
-
- lib/zm/sockets/req.rb
|
102
|
-
- lib/zm/sockets/sub.rb
|
103
|
-
- lib/zm/sockets/xrep.rb
|
104
|
-
- lib/zm/sockets/xreq.rb
|
105
|
-
- lib/zm/
|
106
|
-
- lib/
|
107
|
-
-
|
108
|
-
-
|
109
|
-
-
|
110
|
-
-
|
62
|
+
- .bnsignore
|
63
|
+
- History.txt
|
64
|
+
- README.rdoc
|
65
|
+
- Rakefile
|
66
|
+
- examples/fake_ftp.rb
|
67
|
+
- examples/one_handed_ping_pong.rb
|
68
|
+
- examples/ping_pong.rb
|
69
|
+
- examples/pub_sub.rb
|
70
|
+
- examples/pubsub_forwarder.rb
|
71
|
+
- examples/throttled_ping_pong.rb
|
72
|
+
- lib/zm/address.rb
|
73
|
+
- lib/zm/deferrable.rb
|
74
|
+
- lib/zm/devices.rb
|
75
|
+
- lib/zm/devices/forwarder.rb
|
76
|
+
- lib/zm/devices/queue.rb
|
77
|
+
- lib/zm/exceptions.rb
|
78
|
+
- lib/zm/log_client.rb
|
79
|
+
- lib/zm/message.rb
|
80
|
+
- lib/zm/reactor.rb
|
81
|
+
- lib/zm/sockets.rb
|
82
|
+
- lib/zm/sockets/base.rb
|
83
|
+
- lib/zm/sockets/pair.rb
|
84
|
+
- lib/zm/sockets/pub.rb
|
85
|
+
- lib/zm/sockets/rep.rb
|
86
|
+
- lib/zm/sockets/req.rb
|
87
|
+
- lib/zm/sockets/sub.rb
|
88
|
+
- lib/zm/sockets/xrep.rb
|
89
|
+
- lib/zm/sockets/xreq.rb
|
90
|
+
- lib/zm/sockets/push.rb
|
91
|
+
- lib/zm/sockets/pull.rb
|
92
|
+
- lib/zm/timers.rb
|
93
|
+
- lib/zmqmachine.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
- spec/reactor_spec.rb
|
96
|
+
- version.txt
|
97
|
+
- zmqmachine.gemspec
|
111
98
|
has_rdoc: true
|
112
99
|
homepage: http://github.com/chuckremes/zmqmachine
|
113
100
|
licenses: []
|
114
101
|
|
115
102
|
post_install_message:
|
116
103
|
rdoc_options:
|
117
|
-
- --main
|
118
|
-
- README.rdoc
|
104
|
+
- --main
|
105
|
+
- README.rdoc
|
119
106
|
require_paths:
|
120
|
-
- lib
|
107
|
+
- lib
|
121
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
109
|
none: false
|
123
110
|
requirements:
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
segments:
|
128
|
-
- 0
|
129
|
-
version: "0"
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: "0"
|
130
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
115
|
none: false
|
132
116
|
requirements:
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
segments:
|
137
|
-
- 0
|
138
|
-
version: "0"
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: "0"
|
139
120
|
requirements: []
|
140
121
|
|
141
122
|
rubyforge_project: zmqmachine
|
142
|
-
rubygems_version: 1.5.
|
123
|
+
rubygems_version: 1.5.1
|
143
124
|
signing_key:
|
144
125
|
specification_version: 3
|
145
126
|
summary: ZMQMachine is another Ruby implementation of the reactor pattern but this time using 0mq sockets rather than POSIX sockets.
|