distributor 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- raise "no such command: #{command}"
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
@@ -45,4 +45,8 @@ class Distributor::Multiplexer
45
45
  rescue IOError
46
46
  end
47
47
 
48
+ def generate_id
49
+ id = "#{Time.now.to_f}-#{rand(10000)}"
50
+ end
51
+
48
52
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Distributor
2
2
 
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
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.4.0
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: &70192600707700 !ruby/object:Gem::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: *70192600707700
24
+ version_requirements: *70221318635160
25
25
  description: TCP Multiplexer
26
26
  email: ddollar@gmail.com
27
27
  executables: []