zmqmachine 0.6.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +15 -0
  2. data/AUTHORS.txt +3 -0
  3. data/History.txt +19 -0
  4. data/examples/fake_ftp.rb +9 -1
  5. data/examples/one_handed_ping_pong.rb +2 -1
  6. data/examples/ping_pong.rb +2 -2
  7. data/examples/pub_sub.rb +10 -4
  8. data/examples/pubsub_forwarder.rb +8 -3
  9. data/examples/throttled_ping_pong.rb +2 -2
  10. data/lib/zm/configuration.rb +129 -0
  11. data/lib/zm/device.rb +4 -0
  12. data/lib/zm/device/configuration.rb +24 -0
  13. data/lib/zm/{devices → device}/forwarder.rb +48 -46
  14. data/lib/zm/{devices → device}/queue.rb +63 -44
  15. data/lib/zm/log_client.rb +2 -2
  16. data/lib/zm/log_server.rb +68 -0
  17. data/lib/zm/reactor.rb +42 -29
  18. data/lib/zm/server.rb +4 -0
  19. data/lib/zm/server/base.rb +139 -0
  20. data/lib/zm/server/configuration.rb +53 -0
  21. data/lib/zm/server/pair.rb +23 -0
  22. data/lib/zm/server/pub.rb +23 -0
  23. data/lib/zm/server/pull.rb +24 -0
  24. data/lib/zm/server/push.rb +23 -0
  25. data/lib/zm/server/rep.rb +42 -0
  26. data/lib/zm/server/req.rb +41 -0
  27. data/lib/zm/server/routing_envelope.rb +26 -0
  28. data/lib/zm/server/sub.rb +40 -0
  29. data/lib/zm/sockets.rb +1 -1
  30. data/lib/zm/sockets/base.rb +3 -12
  31. data/lib/zm/sockets/envelope_help.rb +49 -0
  32. data/lib/zm/sockets/pair.rb +0 -1
  33. data/lib/zm/sockets/pub.rb +0 -1
  34. data/lib/zm/sockets/rep.rb +45 -0
  35. data/lib/zm/sockets/req.rb +46 -1
  36. data/lib/zm/sockets/sub.rb +0 -1
  37. data/lib/zm/timers.rb +26 -13
  38. data/lib/zmqmachine.rb +1 -1
  39. data/version.txt +1 -1
  40. data/zmqmachine.gemspec +6 -6
  41. metadata +90 -91
  42. data/lib/zm/devices.rb +0 -4
  43. data/lib/zm/sockets/xrep.rb +0 -86
  44. data/lib/zm/sockets/xreq.rb +0 -86
@@ -42,7 +42,7 @@ module ZMQMachine
42
42
  include ZMQMachine::Socket::Base
43
43
 
44
44
  def initialize context, handler
45
- @poll_options = 0
45
+ @poll_options = ZMQ::POLLIN
46
46
  @kind = :request
47
47
 
48
48
  super
@@ -74,6 +74,51 @@ module ZMQMachine
74
74
  end
75
75
  end # class Req
76
76
 
77
+ class XReq
78
+ include ZMQMachine::Socket::Base
79
+ include ZMQMachine::Socket::EnvelopeHelp
80
+
81
+ def initialize context, handler
82
+ @poll_options = ZMQ::POLLIN
83
+ @kind = :xrequest
84
+
85
+ super
86
+ end
87
+
88
+ # Attach a handler to the XREQ socket.
89
+ #
90
+ # A XREQ socket has no restrictions on the number of sends and
91
+ # recieves. Each send will silently prepend a message part to
92
+ # your outgoing data which the REP/XREP socket on the other end
93
+ # will use for matching up the transaction.
94
+ #
95
+ # This socket expects its +handler+ to
96
+ # implement at least the #on_readable method. This method
97
+ # will be called whenever a reply arrives. The #on_writable method
98
+ # will be called continually until the socket HWM is breached.
99
+ #
100
+ # For error handling purposes, the handler must also
101
+ # implement #on_readable_error.
102
+ #
103
+ def on_attach handler
104
+ raise ArgumentError, "Handler must implement an #on_readable method" unless handler.respond_to? :on_readable
105
+ raise ArgumentError, "Handler must implement an #on_readable_error method" unless handler.respond_to? :on_readable_error
106
+ raise ArgumentError, "Handler must implement an #on_writable method" unless handler.respond_to? :on_writable
107
+ raise ArgumentError, "Handler must implement an #on_writable_error method" unless handler.respond_to? :on_writable_error
108
+ super
109
+ end
110
+
111
+
112
+ private
113
+
114
+ def allocate_socket context
115
+ sock = ZMQ::Socket.new context.pointer, ZMQ::XREQ
116
+ sock
117
+ end
118
+ end # class XReq
119
+
120
+ Dealer = XReq
121
+
77
122
  end # module Socket
78
123
 
79
124
  end # module ZMQMachine
@@ -46,7 +46,6 @@ module ZMQMachine
46
46
  @kind = :sub
47
47
 
48
48
  super
49
- @state = :ready
50
49
  end
51
50
 
52
51
  # Attach a handler to the SUB socket.
@@ -47,7 +47,8 @@ module ZMQMachine
47
47
  # new timers are installed in the correct #Reactor.
48
48
  #
49
49
  class Timers
50
- def initialize
50
+ def initialize(exception_handler)
51
+ @exception_handler = exception_handler
51
52
  @timers = []
52
53
  end
53
54
 
@@ -70,14 +71,14 @@ module ZMQMachine
70
71
  add timer
71
72
  timer
72
73
  end
73
-
74
+
74
75
  # Adds a non-periodical, one-shot timer to be fired at
75
76
  # the specified time.
76
77
  #
77
78
  def add_oneshot_at exact_time, timer_proc = nil, &blk
78
79
  blk ||= timer_proc
79
80
  return nil unless blk
80
-
81
+
81
82
  timer = Timer.new :timers => self, :exact_time => exact_time, :periodical => false, :timer_proc => blk
82
83
  add timer
83
84
  timer
@@ -113,7 +114,7 @@ module ZMQMachine
113
114
  if i < @timers.size && timer == @timers.at(i)
114
115
  @timers.delete_at(i) ? true : false
115
116
  else
116
- # slow branch; necessary since the #index operation works
117
+ # slow branch; necessary since the #index operation works
117
118
  # solely from the timer.fire_time attribute. There
118
119
  # could be multiple timers scheduled to fire at the
119
120
  # same time so the equivalence test above could fail
@@ -121,7 +122,7 @@ module ZMQMachine
121
122
  # slower method
122
123
  size = @timers.size
123
124
  @timers.delete_if { |t| t == timer }
124
-
125
+
125
126
  # true when the array has shrunk, false otherwise
126
127
  @timers.size != size
127
128
  end
@@ -163,7 +164,20 @@ module ZMQMachine
163
164
  end
164
165
 
165
166
  remove expired_count
166
- runnables.each { |timer| timer.fire }
167
+
168
+ while timer = runnables.shift
169
+ begin
170
+ timer.fire
171
+ rescue => e
172
+ if @exception_handler
173
+ @exception_handler.call(e)
174
+ else
175
+ renew(periodicals)
176
+ raise
177
+ end
178
+ end
179
+ end
180
+
167
181
  renew periodicals
168
182
  end
169
183
 
@@ -202,7 +216,7 @@ module ZMQMachine
202
216
 
203
217
  private
204
218
 
205
- # inserts in order using a binary search (O(nlog n)) to find the
219
+ # inserts in order using a binary search (O(nlog n)) to find the
206
220
  # index to insert; this scales nicely for situations where there
207
221
  # are many thousands thousands of timers
208
222
  def add timer
@@ -277,9 +291,8 @@ module ZMQMachine
277
291
  # itself.
278
292
  #
279
293
  def fire
280
- @timer_proc.call
281
-
282
294
  schedule_firing_time if @periodical
295
+ @timer_proc.call
283
296
  end
284
297
 
285
298
  # Cancels this timer from firing.
@@ -291,7 +304,7 @@ module ZMQMachine
291
304
  def <=>(other)
292
305
  @fire_time <=> other.fire_time
293
306
  end
294
-
307
+
295
308
  def ==(other)
296
309
  # need a more specific equivalence test since multiple timers could be
297
310
  # scheduled to go off at exactly the same time
@@ -316,15 +329,15 @@ module ZMQMachine
316
329
  def reschedule
317
330
  schedule_firing_time
318
331
  end
319
-
332
+
320
333
  def to_s
321
334
  ftime = Time.at(@fire_time / 1000)
322
335
  fdelay = @fire_time - Timers.now
323
336
  name = @timer_proc.respond_to?(:name) ? @timer_proc.name : @timer_proc.to_s
324
-
337
+
325
338
  "[delay [#{@delay}], periodical? [#{@periodical}], fire_time [#{ftime}] fire_delay_ms [#{fdelay}]] proc [#{name}]"
326
339
  end
327
-
340
+
328
341
  def inspect; to_s; end
329
342
 
330
343
 
@@ -65,7 +65,7 @@ require 'singleton'
65
65
  require 'ffi-rzmq'
66
66
 
67
67
  # the order of files is important
68
- %w(address exceptions timers deferrable log_client reactor message sockets devices).each do |file|
68
+ %w(address exceptions timers deferrable configuration server log_client log_server reactor message sockets device).each do |file|
69
69
  require ZMQMachine.libpath(['zm', file])
70
70
  end
71
71
 
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.1
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{zmqmachine}
5
- s.version = "0.6.0"
5
+ s.version = "0.7.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{2011-07-21}
9
+ s.date = %q{2011-11-30}
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/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"]
25
+ s.files = `git ls-files`.split("\n")
26
26
  s.homepage = %q{http://github.com/chuckremes/zmqmachine}
27
27
  s.rdoc_options = ["--main", "README.rdoc"]
28
28
  s.require_paths = ["lib"]
@@ -35,14 +35,14 @@ descriptors. This isn't on my roadmap but patches are accepted.}
35
35
  s.specification_version = 3
36
36
 
37
37
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
38
- s.add_runtime_dependency(%q<ffi-rzmq>, [">= 0.7.0"])
38
+ s.add_runtime_dependency(%q<ffi-rzmq>, [">= 0.9.2"])
39
39
  s.add_development_dependency(%q<bones>, [">= 3.5.4"])
40
40
  else
41
- s.add_dependency(%q<ffi-rzmq>, [">= 0.7.0"])
41
+ s.add_dependency(%q<ffi-rzmq>, [">= 0.9.0"])
42
42
  s.add_dependency(%q<bones>, [">= 3.5.4"])
43
43
  end
44
44
  else
45
- s.add_dependency(%q<ffi-rzmq>, [">= 0.7.0"])
45
+ s.add_dependency(%q<ffi-rzmq>, [">= 0.9.0"])
46
46
  s.add_dependency(%q<bones>, [">= 3.5.4"])
47
47
  end
48
48
  end
metadata CHANGED
@@ -1,52 +1,40 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zmqmachine
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 6
8
- - 0
9
- version: 0.6.0
4
+ prerelease:
5
+ version: 0.7.1
10
6
  platform: ruby
11
7
  authors:
12
- - Chuck Remes
8
+ - Chuck Remes
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-07-21 00:00:00 -05:00
13
+ date: 2011-11-30 00:00:00 -06:00
18
14
  default_executable:
19
15
  dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: ffi-rzmq
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 7
31
- - 0
32
- version: 0.7.0
33
- type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: bones
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 3
45
- - 5
46
- - 4
47
- version: 3.5.4
48
- type: :development
49
- 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.9.2
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
50
38
  description: |-
51
39
  ZMQMachine is another Ruby implementation of the reactor pattern but this
52
40
  time using 0mq sockets rather than POSIX sockets.
@@ -67,76 +55,87 @@ executables: []
67
55
  extensions: []
68
56
 
69
57
  extra_rdoc_files:
70
- - History.txt
71
- - README.rdoc
72
- - version.txt
58
+ - History.txt
59
+ - README.rdoc
60
+ - version.txt
73
61
  files:
74
- - .bnsignore
75
- - History.txt
76
- - README.rdoc
77
- - Rakefile
78
- - examples/fake_ftp.rb
79
- - examples/one_handed_ping_pong.rb
80
- - examples/ping_pong.rb
81
- - examples/pub_sub.rb
82
- - examples/pubsub_forwarder.rb
83
- - examples/throttled_ping_pong.rb
84
- - lib/zm/address.rb
85
- - lib/zm/deferrable.rb
86
- - lib/zm/devices.rb
87
- - lib/zm/devices/forwarder.rb
88
- - lib/zm/devices/queue.rb
89
- - lib/zm/exceptions.rb
90
- - lib/zm/log_client.rb
91
- - lib/zm/message.rb
92
- - lib/zm/reactor.rb
93
- - lib/zm/sockets.rb
94
- - lib/zm/sockets/base.rb
95
- - lib/zm/sockets/pair.rb
96
- - lib/zm/sockets/pub.rb
97
- - lib/zm/sockets/rep.rb
98
- - lib/zm/sockets/req.rb
99
- - lib/zm/sockets/sub.rb
100
- - lib/zm/sockets/xrep.rb
101
- - lib/zm/sockets/xreq.rb
102
- - lib/zm/sockets/push.rb
103
- - lib/zm/sockets/pull.rb
104
- - lib/zm/timers.rb
105
- - lib/zmqmachine.rb
106
- - spec/spec_helper.rb
107
- - spec/reactor_spec.rb
108
- - version.txt
109
- - zmqmachine.gemspec
62
+ - .bnsignore
63
+ - .gitignore
64
+ - AUTHORS.txt
65
+ - History.txt
66
+ - README.rdoc
67
+ - Rakefile
68
+ - examples/fake_ftp.rb
69
+ - examples/one_handed_ping_pong.rb
70
+ - examples/ping_pong.rb
71
+ - examples/pub_sub.rb
72
+ - examples/pubsub_forwarder.rb
73
+ - examples/throttled_ping_pong.rb
74
+ - lib/zm/address.rb
75
+ - lib/zm/configuration.rb
76
+ - lib/zm/deferrable.rb
77
+ - lib/zm/device.rb
78
+ - lib/zm/device/configuration.rb
79
+ - lib/zm/device/forwarder.rb
80
+ - lib/zm/device/queue.rb
81
+ - lib/zm/exceptions.rb
82
+ - lib/zm/log_client.rb
83
+ - lib/zm/log_server.rb
84
+ - lib/zm/message.rb
85
+ - lib/zm/reactor.rb
86
+ - lib/zm/server.rb
87
+ - lib/zm/server/base.rb
88
+ - lib/zm/server/configuration.rb
89
+ - lib/zm/server/pair.rb
90
+ - lib/zm/server/pub.rb
91
+ - lib/zm/server/pull.rb
92
+ - lib/zm/server/push.rb
93
+ - lib/zm/server/rep.rb
94
+ - lib/zm/server/req.rb
95
+ - lib/zm/server/routing_envelope.rb
96
+ - lib/zm/server/sub.rb
97
+ - lib/zm/sockets.rb
98
+ - lib/zm/sockets/base.rb
99
+ - lib/zm/sockets/envelope_help.rb
100
+ - lib/zm/sockets/pair.rb
101
+ - lib/zm/sockets/pub.rb
102
+ - lib/zm/sockets/pull.rb
103
+ - lib/zm/sockets/push.rb
104
+ - lib/zm/sockets/rep.rb
105
+ - lib/zm/sockets/req.rb
106
+ - lib/zm/sockets/sub.rb
107
+ - lib/zm/timers.rb
108
+ - lib/zmqmachine.rb
109
+ - spec/reactor_spec.rb
110
+ - spec/spec_helper.rb
111
+ - version.txt
112
+ - zmqmachine.gemspec
110
113
  has_rdoc: true
111
114
  homepage: http://github.com/chuckremes/zmqmachine
112
115
  licenses: []
113
116
 
114
117
  post_install_message:
115
118
  rdoc_options:
116
- - --main
117
- - README.rdoc
119
+ - --main
120
+ - README.rdoc
118
121
  require_paths:
119
- - lib
122
+ - lib
120
123
  required_ruby_version: !ruby/object:Gem::Requirement
121
124
  none: false
122
125
  requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- segments:
126
- - 0
127
- version: "0"
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: "0"
128
129
  required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  none: false
130
131
  requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- segments:
134
- - 0
135
- version: "0"
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: "0"
136
135
  requirements: []
137
136
 
138
137
  rubyforge_project: zmqmachine
139
- rubygems_version: 1.3.7
138
+ rubygems_version: 1.5.1
140
139
  signing_key:
141
140
  specification_version: 3
142
141
  summary: ZMQMachine is another Ruby implementation of the reactor pattern but this time using 0mq sockets rather than POSIX sockets.