distributor 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
- @multiplexer.output 0, Distributor::OkJson.encode({ "id" => data["id"], "command" => "ack", "ch" => ch, "port" => port })
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 tunnel(port)
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(tcp) do |io|
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
- tcp.write data
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
@@ -1,5 +1,5 @@
1
1
  module Distributor
2
2
 
3
- VERSION = "0.5.1"
3
+ VERSION = "0.6.0"
4
4
 
5
5
  end
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.5.1
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-06-19 00:00:00.000000000 Z
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: &70284552374260 !ruby/object:Gem::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: *70284552374260
24
+ version_requirements: *70292678121600
25
25
  description: TCP Multiplexer
26
26
  email: ddollar@gmail.com
27
27
  executables: []