celluloid-zmq 0.16.1 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +13 -7
  3. data/Gemfile +2 -8
  4. data/celluloid-zmq.gemspec +2 -5
  5. data/culture/CODE_OF_CONDUCT.md +28 -0
  6. data/culture/Gemfile +9 -0
  7. data/culture/README.md +22 -0
  8. data/culture/Rakefile +5 -0
  9. data/culture/SYNC.md +70 -0
  10. data/culture/celluloid-culture.gemspec +18 -0
  11. data/culture/gems/README.md +39 -0
  12. data/culture/gems/dependencies.yml +84 -0
  13. data/culture/gems/loader.rb +101 -0
  14. data/culture/rubocop/README.md +38 -0
  15. data/culture/rubocop/lint.yml +8 -0
  16. data/culture/rubocop/metrics.yml +15 -0
  17. data/culture/rubocop/rubocop.yml +4 -0
  18. data/culture/rubocop/style.yml +48 -0
  19. data/culture/spec/gems_spec.rb +2 -0
  20. data/culture/spec/spec_helper.rb +0 -0
  21. data/culture/spec/sync_spec.rb +2 -0
  22. data/culture/sync.rb +56 -0
  23. data/culture/tasks/rspec.rake +5 -0
  24. data/culture/tasks/rubocop.rake +2 -0
  25. data/examples/publish_subscribe.rb +8 -6
  26. data/lib/celluloid/zmq.rb +17 -3
  27. data/lib/celluloid/zmq/current.rb +2 -0
  28. data/lib/celluloid/zmq/deprecate.rb +15 -0
  29. data/lib/celluloid/zmq/mailbox.rb +1 -1
  30. data/lib/celluloid/zmq/reactor.rb +4 -3
  31. data/lib/celluloid/zmq/socket.rb +75 -0
  32. data/lib/celluloid/zmq/socket/readable.rb +46 -0
  33. data/lib/celluloid/zmq/socket/types.rb +104 -0
  34. data/lib/celluloid/zmq/socket/writable.rb +30 -0
  35. data/lib/celluloid/zmq/version.rb +1 -1
  36. data/lib/celluloid/zmq/waker.rb +4 -2
  37. data/log/test.log +23785 -0
  38. data/spec/celluloid/zmq/actor_spec.rb +1 -1
  39. data/spec/celluloid/zmq/socket_spec.rb +1 -1
  40. data/spec/celluloid/zmq_spec.rb +4 -4
  41. data/spec/spec_helper.rb +23 -0
  42. metadata +287 -35
  43. data/lib/celluloid/zmq/sockets.rb +0 -222
@@ -1,222 +0,0 @@
1
- module Celluloid
2
- module ZMQ
3
- class Socket
4
- # Create a new socket
5
- def initialize(type)
6
- @socket = Celluloid::ZMQ.context.socket ::ZMQ.const_get(type.to_s.upcase)
7
- @linger = 0
8
- end
9
- attr_reader :linger
10
-
11
- # Connect to the given 0MQ address
12
- # Address should be in the form: tcp://1.2.3.4:5678/
13
- def connect(addr)
14
- unless ::ZMQ::Util.resultcode_ok? @socket.connect addr
15
- raise IOError, "error connecting to #{addr}: #{::ZMQ::Util.error_string}"
16
- end
17
- true
18
- end
19
-
20
- def linger=(value)
21
- @linger = value || -1
22
-
23
- unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(::ZMQ::LINGER, value)
24
- raise IOError, "couldn't set linger: #{::ZMQ::Util.error_string}"
25
- end
26
- end
27
-
28
- def identity=(value)
29
- @socket.identity = value
30
- end
31
-
32
- def identity
33
- @socket.identity
34
- end
35
-
36
- def set(option, value, length = nil)
37
- unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(option, value, length)
38
- raise IOError, "couldn't set value for option #{option}: #{::ZMQ::Util.error_string}"
39
- end
40
- end
41
-
42
- def get(option)
43
- option_value = []
44
-
45
- unless ::ZMQ::Util.resultcode_ok? @socket.getsockopt(option, option_value)
46
- raise IOError, "couldn't get value for option #{option}: #{::ZMQ::Util.error_string}"
47
- end
48
-
49
- option_value[0]
50
- end
51
-
52
- # Bind to the given 0MQ address
53
- # Address should be in the form: tcp://1.2.3.4:5678/
54
- def bind(addr)
55
- unless ::ZMQ::Util.resultcode_ok? @socket.bind(addr)
56
- raise IOError, "couldn't bind to #{addr}: #{::ZMQ::Util.error_string}"
57
- end
58
- end
59
-
60
- # Close the socket
61
- def close
62
- @socket.close
63
- end
64
-
65
- # Hide ffi-rzmq internals
66
- alias_method :inspect, :to_s
67
- end
68
-
69
- # Readable 0MQ sockets have a read method
70
- module ReadableSocket
71
- extend Forwardable
72
-
73
- # always set LINGER on readable sockets
74
- def bind(addr)
75
- self.linger = @linger
76
- super(addr)
77
- end
78
-
79
- def connect(addr)
80
- self.linger = @linger
81
- super(addr)
82
- end
83
-
84
- # Read a message from the socket
85
- def read(buffer = '')
86
- ZMQ.wait_readable(@socket) if ZMQ.evented?
87
-
88
- unless ::ZMQ::Util.resultcode_ok? @socket.recv_string buffer
89
- raise IOError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}"
90
- end
91
- buffer
92
- end
93
-
94
- # Multiparts message ?
95
- def_delegator :@socket, :more_parts?
96
-
97
- # Reads a multipart message, stores it into the given buffer and returns
98
- # the buffer.
99
- def read_multipart(buffer = [])
100
- ZMQ.wait_readable(@socket) if ZMQ.evented?
101
-
102
- unless ::ZMQ::Util.resultcode_ok? @socket.recv_strings buffer
103
- raise IOError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}"
104
- end
105
- buffer
106
- end
107
- end
108
-
109
- # Writable 0MQ sockets have a send method
110
- module WritableSocket
111
- # Send a message to the socket
112
- def write(*messages)
113
- unless ::ZMQ::Util.resultcode_ok? @socket.send_strings messages.flatten
114
- raise IOError, "error sending 0MQ message: #{::ZMQ::Util.error_string}"
115
- end
116
-
117
- messages
118
- end
119
- alias_method :<<, :write
120
- alias_method :send, :write # deprecated
121
- end
122
-
123
- # ReqSockets are the counterpart of RepSockets (REQ/REP)
124
- class ReqSocket < Socket
125
- include ReadableSocket
126
- include WritableSocket
127
-
128
- def initialize
129
- super :req
130
- end
131
- end
132
-
133
- # RepSockets are the counterpart of ReqSockets (REQ/REP)
134
- class RepSocket < Socket
135
- include ReadableSocket
136
- include WritableSocket
137
-
138
- def initialize
139
- super :rep
140
- end
141
- end
142
-
143
- # DealerSockets are like ReqSockets but more flexible
144
- class DealerSocket < Socket
145
- include ReadableSocket
146
- include WritableSocket
147
-
148
- def initialize
149
- super :dealer
150
- end
151
- end
152
-
153
- # RouterSockets are like RepSockets but more flexible
154
- class RouterSocket < Socket
155
- include ReadableSocket
156
- include WritableSocket
157
-
158
- def initialize
159
- super :router
160
- end
161
- end
162
-
163
- # PushSockets are the counterpart of PullSockets (PUSH/PULL)
164
- class PushSocket < Socket
165
- include WritableSocket
166
-
167
- def initialize
168
- super :push
169
- end
170
- end
171
-
172
- # PullSockets are the counterpart of PushSockets (PUSH/PULL)
173
- class PullSocket < Socket
174
- include ReadableSocket
175
-
176
- def initialize
177
- super :pull
178
- end
179
- end
180
-
181
- # PubSockets are the counterpart of SubSockets (PUB/SUB)
182
- class PubSocket < Socket
183
- include WritableSocket
184
-
185
- def initialize
186
- super :pub
187
- end
188
- end
189
-
190
- # XPubSockets are just like PubSockets but reading from them gives you the
191
- # subscription/unsubscription channels as they're joined/left.
192
- class XPubSocket < Socket
193
- include WritableSocket
194
- include ReadableSocket
195
-
196
- def initialize
197
- super :xpub
198
- end
199
- end
200
-
201
- # SubSockets are the counterpart of PubSockets (PUB/SUB)
202
- class SubSocket < Socket
203
- include ReadableSocket
204
-
205
- def initialize
206
- super :sub
207
- end
208
-
209
- def subscribe(topic)
210
- unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(::ZMQ::SUBSCRIBE, topic)
211
- raise IOError, "couldn't set subscribe: #{::ZMQ::Util.error_string}"
212
- end
213
- end
214
-
215
- def unsubscribe(topic)
216
- unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(::ZMQ::UNSUBSCRIBE, topic)
217
- raise IOError, "couldn't set unsubscribe: #{::ZMQ::Util.error_string}"
218
- end
219
- end
220
- end
221
- end
222
- end