celluloid-zmq 0.9.0 → 0.10.0
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/CHANGES.md +5 -0
- data/Gemfile +2 -2
- data/README.md +85 -39
- data/celluloid-zmq.gemspec +3 -3
- data/lib/celluloid/zmq/sockets.rb +22 -6
- data/lib/celluloid/zmq/version.rb +1 -1
- data/logo.png +0 -0
- metadata +19 -22
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
gem 'celluloid', :git => 'git://github.com/
|
4
|
-
gem 'celluloid-io', :git => 'git://github.com/
|
3
|
+
gem 'celluloid', :git => 'git://github.com/celluloid/celluloid'
|
4
|
+
gem 'celluloid-io', :git => 'git://github.com/celluloid/celluloid-io'
|
5
5
|
|
6
6
|
# Specify your gem's dependencies in celluloid-zmq.gemspec
|
7
7
|
gemspec
|
data/README.md
CHANGED
@@ -1,56 +1,102 @@
|
|
1
|
-
Celluloid::ZMQ
|
2
|
-
|
1
|
+

|
2
|
+
=================
|
3
|
+
[](http://travis-ci.org/celluloid/celluloid-zmq)
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
Celluloid::ZMQ provides Celluloid actors that can interact with [0MQ sockets][0mq].
|
6
|
+
Underneath, it's built on the [ffi-rzmq][ffi-rzmq] library. Celluloid::ZMQ was
|
7
|
+
primarily created for the purpose of writing [DCell][dcell], distributed Celluloid
|
8
|
+
over 0MQ, so before you go building your own distributed Celluloid systems with
|
9
|
+
Celluloid::ZMQ, be sure to give DCell a look and decide if it fits your purposes.
|
6
10
|
|
7
|
-
|
8
|
-
|
11
|
+
[0mq]: http://www.zeromq.org/
|
12
|
+
[ffi-rzmq]: https://github.com/chuckremes/ffi-rzmq
|
13
|
+
[dcell]: https://github.com/celluloid/dcell
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
given socket's message buffer to send another message
|
15
|
+
It provides different `Celluloid::ZMQ::Socket` classes which can be initialized
|
16
|
+
then sent `bind` or `connect`. Once bound or connected, the socket can
|
17
|
+
`read` or `send` depending on whether it's readable or writable.
|
14
18
|
|
15
|
-
|
19
|
+
## Supported Platforms
|
16
20
|
|
17
|
-
|
21
|
+
Celluloid::IO requires Ruby 1.9 support on all Ruby VMs. You will also need
|
22
|
+
the ZeroMQ library installed as it's accessed via FFI.
|
18
23
|
|
19
|
-
|
24
|
+
Supported VMs are Ruby 1.9.3, JRuby 1.6, and Rubinius 2.0.
|
20
25
|
|
21
|
-
|
22
|
-
|
26
|
+
To use JRuby in 1.9 mode, you'll need to pass the "--1.9" command line option
|
27
|
+
to the JRuby executable, or set the "JRUBY_OPTS=--1.9" environment variable.
|
23
28
|
|
24
|
-
|
25
|
-
@socket = ZMQ_CONTEXT.socket(ZMQ::PUSH)
|
29
|
+
## 0MQ Socket Types
|
26
30
|
|
27
|
-
|
28
|
-
@socket.close
|
29
|
-
raise "error connecting to #{addr}: #{ZMQ::Util.error_string}"
|
30
|
-
end
|
31
|
-
end
|
31
|
+
The following 0MQ socket types are supported (see [sockets.rb][socketsrb] for more info)
|
32
32
|
|
33
|
-
|
34
|
-
wait_writeable @socket
|
35
|
-
unless ZMQ::Util.resultcode_ok? @socket.send_string message
|
36
|
-
raise "error sending 0MQ message: #{ZMQ::Util.error_string}"
|
37
|
-
end
|
38
|
-
end
|
33
|
+
[socketsrb]: https://github.com/celluloid/celluloid-zmq/blob/master/lib/celluloid/zmq/sockets.rb
|
39
34
|
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
* ReqSocket / RepSocket
|
36
|
+
* PushSocket / PullSocket
|
37
|
+
* PubSocket / SubSocket
|
43
38
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'celluloid/zmq'
|
43
|
+
|
44
|
+
Celluloid::ZMQ.init
|
45
|
+
|
46
|
+
class Server
|
47
|
+
include Celluloid::ZMQ
|
48
|
+
|
49
|
+
def initialize(address)
|
50
|
+
@socket = PullSocket.new
|
51
|
+
|
52
|
+
begin
|
53
|
+
@socket.bind(address)
|
54
|
+
rescue IOError
|
55
|
+
@socket.close
|
56
|
+
raise
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def run
|
61
|
+
while true; handle_message! @socket.read; end
|
62
|
+
end
|
63
|
+
|
64
|
+
def handle_message(message)
|
65
|
+
puts "got message: #{message}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Client
|
70
|
+
include Celluloid::ZMQ
|
71
|
+
|
72
|
+
def initialize(address)
|
73
|
+
@socket = PushSocket.new
|
74
|
+
|
75
|
+
begin
|
76
|
+
@socket.connect(address)
|
77
|
+
rescue IOError
|
78
|
+
@socket.close
|
79
|
+
raise
|
51
80
|
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def write(message)
|
84
|
+
@socket.send(message)
|
85
|
+
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
addr = 'tcp://127.0.0.1:3435'
|
91
|
+
|
92
|
+
server = Server.new(addr)
|
93
|
+
client = Client.new(addr)
|
94
|
+
|
95
|
+
server.run!
|
96
|
+
client.write('hi')
|
97
|
+
```
|
52
98
|
|
53
99
|
Copyright
|
54
100
|
---------
|
55
101
|
|
56
|
-
Copyright (c)
|
102
|
+
Copyright (c) 2012 Tony Arcieri. See LICENSE.txt for further details.
|
data/celluloid-zmq.gemspec
CHANGED
@@ -6,13 +6,13 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["tony.arcieri@gmail.com"]
|
7
7
|
gem.description = "Celluloid bindings to the ffi-rzmq library"
|
8
8
|
gem.summary = "Celluloid::ZMQ provides concurrent Celluloid actors that can listen for 0MQ events"
|
9
|
-
gem.homepage = "http://github.com/
|
9
|
+
gem.homepage = "http://github.com/celluloid/celluloid-zmq"
|
10
10
|
|
11
11
|
gem.name = "celluloid-zmq"
|
12
12
|
gem.version = Celluloid::ZMQ::VERSION
|
13
13
|
|
14
|
-
gem.add_dependency "celluloid", "~> 0.
|
15
|
-
gem.add_dependency "celluloid-io", "~> 0.
|
14
|
+
gem.add_dependency "celluloid", "~> 0.10.0"
|
15
|
+
gem.add_dependency "celluloid-io", "~> 0.10.0"
|
16
16
|
gem.add_dependency "ffi"
|
17
17
|
gem.add_dependency "ffi-rzmq"
|
18
18
|
|
@@ -1,29 +1,34 @@
|
|
1
1
|
module Celluloid
|
2
2
|
module ZMQ
|
3
|
+
attr_reader :linger
|
4
|
+
|
3
5
|
class Socket
|
4
6
|
# Create a new socket
|
5
7
|
def initialize(type)
|
6
8
|
@socket = Celluloid::ZMQ.context.socket ::ZMQ.const_get(type.to_s.upcase)
|
9
|
+
@linger = 0
|
7
10
|
end
|
8
11
|
|
9
12
|
# Connect to the given 0MQ address
|
10
13
|
# Address should be in the form: tcp://1.2.3.4:5678/
|
11
14
|
def connect(addr)
|
12
|
-
puts "zomg connecting"
|
13
15
|
unless ::ZMQ::Util.resultcode_ok? @socket.connect addr
|
14
16
|
raise IOError, "error connecting to #{addr}: #{::ZMQ::Util.error_string}"
|
15
17
|
end
|
16
18
|
true
|
17
19
|
end
|
18
20
|
|
21
|
+
def linger=(value)
|
22
|
+
@linger = value || -1
|
23
|
+
|
24
|
+
unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(::ZMQ::LINGER, value)
|
25
|
+
raise IOError, "couldn't set linger: #{::ZMQ::Util.error_string}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
19
29
|
# Bind to the given 0MQ address
|
20
30
|
# Address should be in the form: tcp://1.2.3.4:5678/
|
21
31
|
def bind(addr)
|
22
|
-
unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(::ZMQ::LINGER, 0)
|
23
|
-
@socket.close
|
24
|
-
raise IOError, "couldn't set ZMQ::LINGER: #{::ZMQ::Util.error_string}"
|
25
|
-
end
|
26
|
-
|
27
32
|
unless ::ZMQ::Util.resultcode_ok? @socket.bind(addr)
|
28
33
|
raise IOError, "couldn't bind to #{addr}: #{::ZMQ::Util.error_string}"
|
29
34
|
end
|
@@ -49,6 +54,17 @@ module Celluloid
|
|
49
54
|
|
50
55
|
# Readable 0MQ sockets have a read method
|
51
56
|
module ReadableSocket
|
57
|
+
# always set LINGER on readable sockets
|
58
|
+
def bind(addr)
|
59
|
+
self.linger = @linger
|
60
|
+
super(addr)
|
61
|
+
end
|
62
|
+
|
63
|
+
def connect(addr)
|
64
|
+
self.linger = @linger
|
65
|
+
super(addr)
|
66
|
+
end
|
67
|
+
|
52
68
|
# Read a message from the socket
|
53
69
|
def read(buffer = '')
|
54
70
|
Celluloid.current_actor.wait_readable(@socket) if evented?
|
data/logo.png
ADDED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid-zmq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,33 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02
|
12
|
+
date: 2012-04-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: celluloid
|
16
|
-
requirement: &
|
16
|
+
requirement: &70300524096260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.10.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70300524096260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: celluloid-io
|
27
|
-
requirement: &
|
27
|
+
requirement: &70300524095640 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
32
|
+
version: 0.10.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70300524095640
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ffi
|
38
|
-
requirement: &
|
38
|
+
requirement: &70300524095260 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70300524095260
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: ffi-rzmq
|
49
|
-
requirement: &
|
49
|
+
requirement: &70300524094760 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70300524094760
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &70300551724880 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70300551724880
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70300551724460 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70300551724460
|
80
80
|
description: Celluloid bindings to the ffi-rzmq library
|
81
81
|
email:
|
82
82
|
- tony.arcieri@gmail.com
|
@@ -92,15 +92,13 @@ files:
|
|
92
92
|
- lib/celluloid/zmq/version.rb
|
93
93
|
- lib/celluloid/zmq/waker.rb
|
94
94
|
- lib/celluloid/zmq.rb
|
95
|
-
-
|
96
|
-
- pkg/celluloid-zmq-0.7.0.gem
|
97
|
-
- pkg/celluloid-zmq-0.8.0.gem
|
95
|
+
- logo.png
|
98
96
|
- Rakefile
|
99
97
|
- README.md
|
100
98
|
- spec/celluloid/zmq/actor_spec.rb
|
101
99
|
- spec/spec_helper.rb
|
102
100
|
- .gitignore
|
103
|
-
homepage: http://github.com/
|
101
|
+
homepage: http://github.com/celluloid/celluloid-zmq
|
104
102
|
licenses: []
|
105
103
|
post_install_message:
|
106
104
|
rdoc_options: []
|
@@ -120,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
118
|
version: '0'
|
121
119
|
requirements: []
|
122
120
|
rubyforge_project:
|
123
|
-
rubygems_version: 1.8.
|
121
|
+
rubygems_version: 1.8.17
|
124
122
|
signing_key:
|
125
123
|
specification_version: 3
|
126
124
|
summary: Celluloid::ZMQ provides concurrent Celluloid actors that can listen for 0MQ
|
@@ -129,4 +127,3 @@ test_files:
|
|
129
127
|
- spec/celluloid/zmq/actor_spec.rb
|
130
128
|
- spec/spec_helper.rb
|
131
129
|
- .gitignore
|
132
|
-
has_rdoc:
|