foreign_actor 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/bin/puppetmaster.rb +12 -12
- data/bin/router +7 -7
- data/example/Procfile +1 -1
- data/foreign_actor.gemspec +2 -1
- data/lib/foreign_actor/client.rb +3 -3
- data/lib/foreign_actor/reactor.rb +14 -14
- data/lib/foreign_actor/version.rb +1 -1
- data/lib/foreign_actor.rb +1 -1
- data/specs/unit/reactor_spec.rb +4 -4
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0520969e30d46a49a78358cdc8e89cdac4d98883
|
4
|
+
data.tar.gz: 377f120fabe7cbf6513886d393999301f56e8a1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a9763c1da67226679b5a4364f3d6ebda857a50899737d9288a33dd4c7ef647c9050bf1b21625050b19985cb632f890a9c51a4182a3e60eec63aed4c848dc509
|
7
|
+
data.tar.gz: 55f9997d7a41f5f5613b901ac73a434fc86f620f10c84867044af394f27eaadb58699587027c6a6f9ba929c148e05c6f2260f8eddf53e63cd8c3405bf3703924
|
data/Gemfile
CHANGED
data/bin/puppetmaster.rb
CHANGED
@@ -3,17 +3,17 @@ require 'ffi-rxs'
|
|
3
3
|
|
4
4
|
class PuppetMaster
|
5
5
|
def initialize(workers_endpoint, client_endpoint)
|
6
|
-
@context =
|
6
|
+
@context = ZMQ::Context.new
|
7
7
|
@source_id = nil
|
8
8
|
|
9
|
-
@workers_socket = @context.socket(
|
10
|
-
@clients_socket = @context.socket(
|
9
|
+
@workers_socket = @context.socket(ZMQ::XREQ)
|
10
|
+
@clients_socket = @context.socket(ZMQ::XREP)
|
11
11
|
|
12
12
|
@workers_socket.bind(workers_endpoint)
|
13
13
|
@clients_socket.bind(client_endpoint)
|
14
14
|
|
15
|
-
@control_socket_srv = @context.socket(
|
16
|
-
@control_socket_cl = @context.socket(
|
15
|
+
@control_socket_srv = @context.socket(ZMQ::PAIR)
|
16
|
+
@control_socket_cl = @context.socket(ZMQ::PAIR)
|
17
17
|
|
18
18
|
addr = "inproc://ctrl"
|
19
19
|
@control_socket_srv.bind(addr)
|
@@ -25,7 +25,7 @@ class PuppetMaster
|
|
25
25
|
trap('INT'){ @control_socket_cl.send_string('') }
|
26
26
|
trap('TERM'){ @control_socket_cl.send_string('') }
|
27
27
|
|
28
|
-
poller =
|
28
|
+
poller = ZMQ::Poller.new
|
29
29
|
poller.register_readable(@workers_socket)
|
30
30
|
poller.register_readable(@clients_socket)
|
31
31
|
# control socket
|
@@ -57,11 +57,11 @@ class PuppetMaster
|
|
57
57
|
@source_id = msg.shift
|
58
58
|
|
59
59
|
# send to the other side
|
60
|
-
handle_xs_err(@workers_socket, :send_string, msg[0],
|
60
|
+
handle_xs_err(@workers_socket, :send_string, msg[0], ZMQ::DONTWAIT)
|
61
61
|
|
62
62
|
else
|
63
|
-
handle_xs_err(@clients_socket, :send_string, @source_id,
|
64
|
-
handle_xs_err(@clients_socket, :send_string, msg[0],
|
63
|
+
handle_xs_err(@clients_socket, :send_string, @source_id, ZMQ::DONTWAIT | ZMQ::SNDMORE)
|
64
|
+
handle_xs_err(@clients_socket, :send_string, msg[0], ZMQ::DONTWAIT)
|
65
65
|
|
66
66
|
end
|
67
67
|
end
|
@@ -73,7 +73,7 @@ private
|
|
73
73
|
parts = []
|
74
74
|
loop do
|
75
75
|
data = ""
|
76
|
-
if s.recv_string(data,
|
76
|
+
if s.recv_string(data, ZMQ::DONTWAIT) == -1
|
77
77
|
raise "error while reading socket: #{}"
|
78
78
|
end
|
79
79
|
parts << data
|
@@ -88,8 +88,8 @@ private
|
|
88
88
|
|
89
89
|
def handle_xs_err(s, method, *args)
|
90
90
|
rc = s.send(method, *args)
|
91
|
-
unless
|
92
|
-
raise "error: #{method}: #{
|
91
|
+
unless ZMQ::Util.resultcode_ok?(rc)
|
92
|
+
raise "error: #{method}: #{ZMQ::Util.error_string}"
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
data/bin/router
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'ffi-
|
3
|
+
require 'ffi-rzmq'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
-
context =
|
7
|
-
poller =
|
6
|
+
context = ZMQ::Context.new
|
7
|
+
poller = ZMQ::Poller.new
|
8
8
|
|
9
9
|
path = nil
|
10
10
|
|
@@ -29,8 +29,8 @@ Pipe = Struct.new(:front, :back) do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
conf.each do |name, paths|
|
32
|
-
frontend = context.socket(
|
33
|
-
backend = context.socket(
|
32
|
+
frontend = context.socket(ZMQ::XREP)
|
33
|
+
backend = context.socket(ZMQ::XREQ)
|
34
34
|
|
35
35
|
frontend.bind(paths['front'])
|
36
36
|
backend.bind(paths['back'])
|
@@ -54,7 +54,7 @@ loop do
|
|
54
54
|
loop do
|
55
55
|
socket.recv_string(message = "")
|
56
56
|
more = socket.more_parts?
|
57
|
-
p.back.send_string(message, more ?
|
57
|
+
p.back.send_string(message, more ? ZMQ::SNDMORE : 0)
|
58
58
|
break unless more
|
59
59
|
end
|
60
60
|
next
|
@@ -63,7 +63,7 @@ loop do
|
|
63
63
|
loop do
|
64
64
|
socket.recv_string(message = "")
|
65
65
|
more = socket.more_parts?
|
66
|
-
p.front.send_string(message, more ?
|
66
|
+
p.front.send_string(message, more ? ZMQ::SNDMORE : 0)
|
67
67
|
break unless more
|
68
68
|
end
|
69
69
|
next
|
data/example/Procfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
master: ruby ../bin/router
|
1
|
+
master: bundle exec ruby ../bin/router
|
2
2
|
worker: ruby worker.rb
|
data/foreign_actor.gemspec
CHANGED
@@ -14,7 +14,8 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
gem.version = ForeignWorker::VERSION
|
16
16
|
|
17
|
-
gem.add_dependency 'ffi-
|
17
|
+
gem.add_dependency 'ffi-rzmq', '~> 1.0.3'
|
18
|
+
|
18
19
|
gem.add_dependency 'celluloid', '~> 0.15.0'
|
19
20
|
gem.add_dependency 'msgpack', '~> 0.5.4'
|
20
21
|
end
|
data/lib/foreign_actor/client.rb
CHANGED
@@ -72,10 +72,10 @@ module ForeignActor
|
|
72
72
|
def initialize(endpoint, request_timeout = nil, reactor_name = :xs_reactor)
|
73
73
|
@reactor_name = reactor_name
|
74
74
|
@request_timeout = request_timeout
|
75
|
-
@socket = Actor[@reactor_name].socket(
|
75
|
+
@socket = Actor[@reactor_name].socket(ZMQ::XREQ)
|
76
76
|
rc = @socket.connect(endpoint)
|
77
|
-
unless
|
78
|
-
raise IOError, "connect failed: #{
|
77
|
+
unless ZMQ::Util.resultcode_ok?(rc)
|
78
|
+
raise IOError, "connect failed: #{ZMQ::Util.error_string}"
|
79
79
|
end
|
80
80
|
|
81
81
|
end
|
@@ -9,14 +9,14 @@ module ForeignActor
|
|
9
9
|
StopLoop = Class.new(RuntimeError)
|
10
10
|
|
11
11
|
def initialize(context = nil, poller = nil, timers = nil)
|
12
|
-
@context = context ||
|
13
|
-
@poller = poller ||
|
12
|
+
@context = context || ZMQ::Context.new
|
13
|
+
@poller = poller || ZMQ::Poller.new
|
14
14
|
@waiting_readables = {}
|
15
15
|
@servers = {}
|
16
16
|
@timers = timers || Timers.new
|
17
17
|
|
18
|
-
@control_socket_srv = @context.socket(
|
19
|
-
@control_socket_cl = @context.socket(
|
18
|
+
@control_socket_srv = @context.socket(ZMQ::PAIR)
|
19
|
+
@control_socket_cl = @context.socket(ZMQ::PAIR)
|
20
20
|
@control_messages = Array.new
|
21
21
|
|
22
22
|
addr = "inproc://ctrl"
|
@@ -77,10 +77,10 @@ module ForeignActor
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def serve_actor(endpoint, actor_or_name)
|
80
|
-
s = socket(
|
80
|
+
s = socket(ZMQ::XREP)
|
81
81
|
rc = s.connect(endpoint)
|
82
|
-
unless
|
83
|
-
raise IOError, "connect failed: #{
|
82
|
+
unless ZMQ::Util.resultcode_ok?(rc)
|
83
|
+
raise IOError, "connect failed: #{ZMQ::Util.error_string}"
|
84
84
|
end
|
85
85
|
|
86
86
|
if @servers.has_key?(s)
|
@@ -107,8 +107,8 @@ module ForeignActor
|
|
107
107
|
end
|
108
108
|
|
109
109
|
rc = @poller.poll(wait_time)
|
110
|
-
unless
|
111
|
-
raise IOError, "libxs poll error: #{
|
110
|
+
unless ZMQ::Util.resultcode_ok?(rc)
|
111
|
+
raise IOError, "libxs poll error: #{ZMQ::Util.error_string}"
|
112
112
|
end
|
113
113
|
|
114
114
|
@poller.readables.each do |s|
|
@@ -237,7 +237,7 @@ module ForeignActor
|
|
237
237
|
parts = []
|
238
238
|
loop do
|
239
239
|
data = ""
|
240
|
-
if s.recv_string(data,
|
240
|
+
if s.recv_string(data, ZMQ::DONTWAIT) == -1
|
241
241
|
raise "error while reading socket: #{}"
|
242
242
|
end
|
243
243
|
parts << data
|
@@ -249,16 +249,16 @@ module ForeignActor
|
|
249
249
|
|
250
250
|
def send_msg(s, *parts)
|
251
251
|
parts[0...-1].each do |m|
|
252
|
-
handle_xs_err(s, :send_string, m,
|
252
|
+
handle_xs_err(s, :send_string, m, ZMQ::DONTWAIT | ZMQ::SNDMORE)
|
253
253
|
end
|
254
254
|
|
255
|
-
handle_xs_err(s, :send_string, parts[-1],
|
255
|
+
handle_xs_err(s, :send_string, parts[-1], ZMQ::DONTWAIT)
|
256
256
|
end
|
257
257
|
|
258
258
|
def handle_xs_err(s, method, *args)
|
259
259
|
rc = s.send(method, *args)
|
260
|
-
unless
|
261
|
-
raise "error: #{method}: #{
|
260
|
+
unless ZMQ::Util.resultcode_ok?(rc)
|
261
|
+
raise "error: #{method}: #{ZMQ::Util.error_string}"
|
262
262
|
end
|
263
263
|
end
|
264
264
|
|
data/lib/foreign_actor.rb
CHANGED
data/specs/unit/reactor_spec.rb
CHANGED
@@ -2,16 +2,16 @@ require File.expand_path('../../spec_helper', __FILE__)
|
|
2
2
|
|
3
3
|
describe 'Reactor' do
|
4
4
|
before do
|
5
|
-
# @poller = stub('
|
6
|
-
# @context = stub('
|
5
|
+
# @poller = stub('ZMQ::Poller')
|
6
|
+
# @context = stub('ZMQ::Context')
|
7
7
|
@timers = Timers.new
|
8
8
|
end
|
9
9
|
|
10
10
|
# should "initialize everything" do
|
11
11
|
# # create control sockets
|
12
12
|
# @ctrl = [stub('ServerCtrl'), stub('ClientCtrl')]
|
13
|
-
# @context.expects(:socket).with(
|
14
|
-
# @context.expects(:socket).with(
|
13
|
+
# @context.expects(:socket).with(ZMQ::PAIR).returns(@ctrl[1])
|
14
|
+
# @context.expects(:socket).with(ZMQ::PAIR).returns(@ctrl[0])
|
15
15
|
|
16
16
|
# @ctrl[0].expects(:bind)
|
17
17
|
# @ctrl[1].expects(:connect)
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreign_actor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Ammous
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: ffi-
|
14
|
+
name: ffi-rzmq
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.0.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: celluloid
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.1.11
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Distributed Actors
|