distributor 0.4.0 → 0.4.1
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 +7 -6
- data/lib/distributor/multiplexer.rb +4 -0
- data/lib/distributor/server.rb +7 -0
- data/lib/distributor/version.rb +1 -1
- metadata +3 -3
data/lib/distributor/client.rb
CHANGED
@@ -13,6 +13,7 @@ class Distributor::Client
|
|
13
13
|
@processes = []
|
14
14
|
@on_close = Hash.new { |hash,key| hash[key] = Array.new }
|
15
15
|
@on_hello = []
|
16
|
+
@on_command = Proc.new {}
|
16
17
|
@hookup_lock = Mutex.new
|
17
18
|
|
18
19
|
# reserve a command channel
|
@@ -45,7 +46,7 @@ class Distributor::Client
|
|
45
46
|
@handlers.delete(data["id"])
|
46
47
|
@processes << ch
|
47
48
|
else
|
48
|
-
|
49
|
+
@on_command.call(command, data)
|
49
50
|
end
|
50
51
|
end
|
51
52
|
end
|
@@ -56,7 +57,7 @@ class Distributor::Client
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def command(command, data={})
|
59
|
-
data["id"] ||= generate_id
|
60
|
+
data["id"] ||= @multiplexer.generate_id
|
60
61
|
data["command"] = command
|
61
62
|
@multiplexer.output 0, Distributor::OkJson.encode(data)
|
62
63
|
data["id"]
|
@@ -107,16 +108,16 @@ class Distributor::Client
|
|
107
108
|
@on_hello << blk
|
108
109
|
end
|
109
110
|
|
111
|
+
def on_command(&blk)
|
112
|
+
@on_command = blk
|
113
|
+
end
|
114
|
+
|
110
115
|
def start
|
111
116
|
loop { @connector.listen }
|
112
117
|
end
|
113
118
|
|
114
119
|
private
|
115
120
|
|
116
|
-
def generate_id
|
117
|
-
id = "#{Time.now.to_f}-#{rand(10000)}"
|
118
|
-
end
|
119
|
-
|
120
121
|
def append_json(data)
|
121
122
|
@json ||= ""
|
122
123
|
@json += data
|
data/lib/distributor/server.rb
CHANGED
@@ -94,6 +94,13 @@ class Distributor::Server
|
|
94
94
|
ch
|
95
95
|
end
|
96
96
|
|
97
|
+
def command(command, data={})
|
98
|
+
data["id"] ||= @multiplexer.generate_id
|
99
|
+
data["command"] = command
|
100
|
+
@multiplexer.output 0, Distributor::OkJson.encode(data)
|
101
|
+
data["id"]
|
102
|
+
end
|
103
|
+
|
97
104
|
def on_command(&blk)
|
98
105
|
@on_command = blk
|
99
106
|
end
|
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.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-06-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70221318635160 !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: *70221318635160
|
25
25
|
description: TCP Multiplexer
|
26
26
|
email: ddollar@gmail.com
|
27
27
|
executables: []
|