distributor 0.5.1 → 0.6.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/lib/distributor/client.rb +5 -0
- data/lib/distributor/server.rb +22 -8
- data/lib/distributor/version.rb +1 -1
- metadata +4 -4
data/lib/distributor/client.rb
CHANGED
@@ -68,6 +68,11 @@ class Distributor::Client
|
|
68
68
|
@handlers[id] = handler
|
69
69
|
end
|
70
70
|
|
71
|
+
def socket(path, &handler)
|
72
|
+
id = command("socket", "path" => path)
|
73
|
+
@handlers[id] = handler
|
74
|
+
end
|
75
|
+
|
71
76
|
def tunnel(port, &handler)
|
72
77
|
id = command("tunnel", "port" => port)
|
73
78
|
@handlers[id] = handler
|
data/lib/distributor/server.rb
CHANGED
@@ -30,10 +30,14 @@ class Distributor::Server
|
|
30
30
|
|
31
31
|
dequeue_json do |data|
|
32
32
|
case command = data["command"]
|
33
|
+
when "socket" then
|
34
|
+
path = data["path"]
|
35
|
+
ch = socket(path)
|
36
|
+
ack data["id"], "ch" => ch, "path" => path
|
33
37
|
when "tunnel" then
|
34
38
|
port = (data["port"] || ENV["PORT"] || 5000).to_i
|
35
39
|
ch = tunnel(port)
|
36
|
-
|
40
|
+
ack data["id"], "ch" => ch, "port" => port
|
37
41
|
when "close" then
|
38
42
|
@multiplexer.close data["ch"]
|
39
43
|
when "run" then
|
@@ -46,6 +50,10 @@ class Distributor::Server
|
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
53
|
+
def ack(id, options={})
|
54
|
+
@multiplexer.output 0, Distributor::OkJson.encode(options.merge({ "id" => id, "command" => "ack" }))
|
55
|
+
end
|
56
|
+
|
49
57
|
def run(command)
|
50
58
|
ch = @multiplexer.reserve
|
51
59
|
|
@@ -70,13 +78,9 @@ class Distributor::Server
|
|
70
78
|
ch
|
71
79
|
end
|
72
80
|
|
73
|
-
def
|
74
|
-
ch = @multiplexer.reserve
|
75
|
-
|
76
|
-
tcp = TCPSocket.new("localhost", port)
|
77
|
-
|
81
|
+
def handle_socket(ch, socket)
|
78
82
|
# handle data incoming from process
|
79
|
-
@connector.handle(
|
83
|
+
@connector.handle(socket) do |io|
|
80
84
|
begin
|
81
85
|
@multiplexer.output(ch, io.readpartial(4096))
|
82
86
|
rescue EOFError
|
@@ -88,12 +92,22 @@ class Distributor::Server
|
|
88
92
|
# handle data incoming on the multiplexer
|
89
93
|
@connector.handle(@multiplexer.reader(ch)) do |input_io|
|
90
94
|
data = input_io.readpartial(4096)
|
91
|
-
|
95
|
+
socket.write data
|
92
96
|
end
|
93
97
|
|
94
98
|
ch
|
95
99
|
end
|
96
100
|
|
101
|
+
def socket(path)
|
102
|
+
ch = @multiplexer.reserve
|
103
|
+
handle_socket ch, UNIXSocket.new(path)
|
104
|
+
end
|
105
|
+
|
106
|
+
def tunnel(port)
|
107
|
+
ch = @multiplexer.reserve
|
108
|
+
handle_socket ch, TCPSocket.new("localhost", port)
|
109
|
+
end
|
110
|
+
|
97
111
|
def command(command, data={})
|
98
112
|
data["id"] ||= @multiplexer.generate_id
|
99
113
|
data["command"] = command
|
data/lib/distributor/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: distributor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70292678121600 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 0.13.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70292678121600
|
25
25
|
description: TCP Multiplexer
|
26
26
|
email: ddollar@gmail.com
|
27
27
|
executables: []
|