qrpc 0.4.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/CHANGES.txt +9 -6
  2. data/Gemfile +10 -4
  3. data/Gemfile.lock +34 -12
  4. data/LICENSE.txt +1 -1
  5. data/README.md +92 -25
  6. data/Rakefile +2 -1
  7. data/TODO.md +1 -3
  8. data/VERSION +1 -1
  9. data/lib/qrpc/client.rb +13 -5
  10. data/lib/qrpc/client/dispatcher.rb +66 -50
  11. data/lib/qrpc/client/exception.rb +8 -37
  12. data/lib/qrpc/client/job.rb +49 -16
  13. data/lib/qrpc/general.rb +61 -1
  14. data/lib/qrpc/generator/object-id.rb +43 -0
  15. data/lib/qrpc/generator/uuid.rb +43 -0
  16. data/lib/qrpc/locator.rb +11 -85
  17. data/lib/qrpc/locator/em-jack.rb +160 -0
  18. data/lib/qrpc/locator/evented-queue.rb +101 -0
  19. data/lib/qrpc/protocol/abstract.rb +119 -0
  20. data/lib/qrpc/protocol/abstract/error.rb +54 -0
  21. data/lib/qrpc/protocol/abstract/object.rb +81 -0
  22. data/lib/qrpc/protocol/abstract/request.rb +126 -0
  23. data/lib/qrpc/protocol/abstract/response.rb +103 -0
  24. data/lib/qrpc/protocol/json-rpc.rb +32 -0
  25. data/lib/qrpc/protocol/json-rpc/error.rb +71 -0
  26. data/lib/qrpc/protocol/json-rpc/native/exception-data.rb +247 -0
  27. data/lib/qrpc/protocol/json-rpc/native/qrpc-object.rb +137 -0
  28. data/lib/qrpc/protocol/json-rpc/request.rb +140 -0
  29. data/lib/qrpc/protocol/json-rpc/response.rb +146 -0
  30. data/lib/qrpc/protocol/object.rb +32 -0
  31. data/lib/qrpc/protocol/object/error.rb +46 -0
  32. data/lib/qrpc/protocol/object/request.rb +111 -0
  33. data/lib/qrpc/protocol/object/response.rb +93 -0
  34. data/lib/qrpc/server.rb +63 -48
  35. data/lib/qrpc/server/dispatcher.rb +5 -107
  36. data/lib/qrpc/server/job.rb +69 -19
  37. data/qrpc.gemspec +55 -19
  38. data/test-both.rb +85 -0
  39. data/test-client.rb +36 -8
  40. data/test-server.rb +17 -12
  41. metadata +181 -31
  42. data/lib/qrpc/protocol/exception-data.rb +0 -227
  43. data/lib/qrpc/protocol/qrpc-object.rb +0 -103
  44. data/lib/qrpc/protocol/request.rb +0 -46
data/CHANGES.txt CHANGED
@@ -1,9 +1,11 @@
1
1
 
2
- 0.4.0
3
- * #precall and #postcall handler support on API object
4
- * missing default value for options in Server#start_listening
5
- * in some responses ID isn't available, but tried to be converted to
6
- the symbol
2
+ 0.9.0 (2012-05-24)
3
+ * transfer agents generic support
4
+ * protocols generic support
5
+ * ID generators generic support
6
+ * serializers generic support
7
+ * server synchronicity option support
8
+ * substantial code reorganization
7
9
 
8
10
  0.3.2 (2011-08-28)
9
11
  * UUID of the client now generated in compact format
@@ -13,7 +15,8 @@
13
15
  * UUID of the jobs now generated in compact format
14
16
 
15
17
  0.3.0 (2011-02-27)
16
- * invalid json-rpc-object dependency
18
+ * bad json-rpc-object dependency (but noncritical, some special cases
19
+ performance lag only)
17
20
  * all public methods from Client moved to Client::Dispatcher
18
21
 
19
22
  0.2.2 (2011-02-13)
data/Gemfile CHANGED
@@ -1,11 +1,17 @@
1
1
  source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
- gem "json-rpc-objects", ">= 0.3.3"
5
- gem "depq", ">= 0.4"
6
- gem "em-jack", ">= 0.1.3"
4
+ gem "json-rpc-objects", ">= 0.4.1"
5
+ gem "PriorityQueue", ">= 0.1.2"
6
+ gem "unified-queues", ">= 0"
7
+ gem "evented-queue", ">= 0"
7
8
  gem "eventmachine", ">= 0"
8
- gem "uuid", ">= 2.3.2"
9
+ gem "hash-utils", ">= 1.1.0"
10
+ gem "em-wrapper", ">= 0"
11
+ gem "abstract", ">= 0"
12
+ gem "em-jack", ">= 0.1.3"
13
+ gem "hashie", ">= 1.0.0"
14
+ gem "uuid", ">= 2.0.0"
9
15
 
10
16
  # Add dependencies to develop your gem here.
11
17
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -1,29 +1,45 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ PriorityQueue (0.1.2)
4
5
  abstract (1.0.0)
5
- addressable (2.2.6)
6
- depq (0.6)
6
+ addressable (2.2.8)
7
7
  em-jack (0.1.5)
8
8
  eventmachine (>= 0.12.10)
9
- eventmachine (1.0.0.beta.4)
9
+ em-wrapper (0.1.0)
10
+ eventmachine
11
+ hash-utils (>= 0.17.0)
12
+ object-proxy (>= 0.3.0)
13
+ evented-queue (0.1.0)
14
+ abstract
15
+ unified-queues
16
+ eventmachine (0.12.10)
10
17
  git (1.2.5)
11
- hash-utils (1.1.0)
18
+ hash-utils (2.0.0)
12
19
  ruby-version
20
+ hashie (1.2.0)
13
21
  jeweler2 (2.0.9)
14
22
  git (>= 1.2.5)
15
- json-rpc-objects (0.4.3)
23
+ json-rpc-objects (0.4.2)
16
24
  abstract (>= 1.0.0)
17
25
  addressable (>= 2.2.2)
18
26
  hash-utils (>= 0.18.0)
19
27
  json-rpc-objects-json (>= 0.1.1)
20
28
  json-rpc-objects-json (0.1.1)
21
29
  multi_json
22
- macaddr (1.5.0)
23
- systemu (>= 2.4.0)
24
- multi_json (1.0.4)
30
+ lookup-hash (0.2.0)
31
+ hash-utils (>= 0.11.0)
32
+ macaddr (1.6.0)
33
+ systemu (~> 2.2.0)
34
+ multi_json (1.3.5)
35
+ object-proxy (0.3.0)
36
+ hash-utils (>= 0.12.1)
25
37
  ruby-version (0.3.1)
26
- systemu (2.4.2)
38
+ systemu (2.2.0)
39
+ unified-queues (0.1.0)
40
+ abstract (>= 1.0.0)
41
+ hash-utils (>= 0.18.1)
42
+ lookup-hash
27
43
  uuid (2.3.5)
28
44
  macaddr (~> 1.0)
29
45
 
@@ -31,10 +47,16 @@ PLATFORMS
31
47
  ruby
32
48
 
33
49
  DEPENDENCIES
50
+ PriorityQueue (>= 0.1.2)
51
+ abstract
34
52
  bundler (>= 1.0.0)
35
- depq (>= 0.4)
36
53
  em-jack (>= 0.1.3)
54
+ em-wrapper
55
+ evented-queue
37
56
  eventmachine
57
+ hash-utils (>= 1.1.0)
58
+ hashie (>= 1.0.0)
38
59
  jeweler2 (>= 2.0.0)
39
- json-rpc-objects (>= 0.3.3)
40
- uuid (>= 2.3.2)
60
+ json-rpc-objects (>= 0.4.1)
61
+ unified-queues
62
+ uuid (>= 2.0.0)
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Martin Kozák
1
+ Copyright (c) 2011 - 2012 Martin Kozák (martinkozak@martinkozak.net)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -6,14 +6,15 @@ which works as normal RPC server, but through queue interface, so allows
6
6
  highly scalable, distributed and asynchronous remote API implementation
7
7
  and fast data processing.
8
8
 
9
- It's based on [eventmachine][1] and [beanstalkd][2] so it's fast and
10
- thread safe.
9
+ It's based on [eventmachine][1] and the default implementation uses
10
+ [beanstalkd][2] so it's fast and thread safe.
11
11
 
12
12
  ### Protocol
13
13
 
14
- It utilizes [JSON-RPC][3] protocol in versions both [1.1][4] and [2.0][5].
15
- Adds special data member `qrpc` with few options appropriate for queue
16
- processing. Typicall request looks in Ruby hash notation like:
14
+ It utilizes [JSON-RPC][3] protocol by default in versions both [1.1][4]
15
+ and [2.0][5] altthough different protocols can be implemented. Adds special
16
+ data member `qrpc` with few options appropriate for queue processing.
17
+ Typicall request looks in Ruby hash notation like:
17
18
 
18
19
  {
19
20
  "jsonrpc" => "2.0",
@@ -54,7 +55,7 @@ And in case of exception:
54
55
  "message" => <exception message>,
55
56
  "backtrace" => <array of Base64 encoded strings>,
56
57
  "dump" => {
57
- "raw" => <Base 54 encoded marshaled exception object>,
58
+ "raw" => <Base64 encoded marshaled exception object>,
58
59
  "format" => "ruby"
59
60
  }
60
61
  }
@@ -68,13 +69,61 @@ And in case of exception:
68
69
 
69
70
  Both `backtrace` and `dump` members are optional.
70
71
 
72
+ ### Variety of Platforms
73
+
74
+ #### Transfer Agents (“Queues”)
75
+
76
+ QRPC uses the [Unified Queues][10] interface which ensures connecting
77
+ to different queue interfaces using an unified API. It can be used on all
78
+ platforms which have unified queues driver available by this way. By default,
79
+ two of them are available:
80
+
81
+ * [beanstalkd][2] queue protocol,
82
+ * 8 different queues-like in-memory objects (in fact, all priority queue
83
+ implementations available for Ruby to date).
84
+
85
+ See the [Unified Queues][10] documentation.
86
+
87
+ #### Communication Protocols (“Protocols”)
88
+
89
+ Different protocols can be implemented provided that it will provide the
90
+ required API. By default, two of them are available:
91
+
92
+ * [JSON-RPC][3] protocol (default, see description above),
93
+ * object protocol (in fact, the pure Ruby objects for in-memory communication)
94
+
95
+ #### Identification Generators (“Generators”)
96
+
97
+ The request identificators can be generated by various ways. It's possible
98
+ to implement an own generator so have benefits for logging or in corporate
99
+ use. By default two generators are available:
100
+
101
+ * [UUID][11] generator (default),
102
+ * [Ruby object ID][12] generator (fast, intended for in-memory communication in
103
+ single Ruby instance).
104
+
105
+ #### Encoding Agents (“Serializers”)
106
+
107
+ The JSON-RPC protocol is intended for use with the [JSON][13] encoding, but can
108
+ be encoded by various other methods. Various serializers support is part of the
109
+ [JSON-RPC Objects][13] gem. See its documentation. The following protocols are
110
+ supported for example, to date:
111
+
112
+ * [JSON][14]
113
+ * [BSON][15]
114
+ * [YAML][16]
115
+ * [MessagePack][17]
116
+
71
117
 
72
118
  ### Server Usage
73
119
 
74
- Usage is simple. Look example:
120
+ Usage is simple. Look example of *Beanstalked* *JSON-RPC* service encoded
121
+ by the *MsgPack* format working *synchronously*:
75
122
 
76
- require "qrpc/server"
77
- require "qrpc/locator"
123
+ require "qrpc/server" # server
124
+ require "qrpc/locator/em-jack" # queue transfer agent
125
+ require "qrpc/protocol/json-rpc" # RPC protocol
126
+ require "json-rpc-objects/serializer/msgpack" # serializer
78
127
 
79
128
  class Foo
80
129
  def subtract(x, y)
@@ -82,8 +131,12 @@ Usage is simple. Look example:
82
131
  end
83
132
  end
84
133
 
85
- server = QRPC::Server::new Foo::new
86
- server.listen! QRPC::Locator::new "test"
134
+ serializer = JsonRpcObjects::Serializer::MsgPack::new
135
+ protocol = QRPC::Protocol::JsonRpc::new(:serializer => serializer)
136
+ locator = QRPC::Locator::EMJackLocator::new("test")
137
+
138
+ server = QRPC::Server::new(Foo::new, :synchronous, protocol)
139
+ server.listen! locator
87
140
 
88
141
  This creates an instance of `Foo` which will serve as API, creates
89
142
  locator of the queue *test* at default server *localhost:11300*. Queue
@@ -93,27 +146,33 @@ you want to run it inside already run eventmachine, simply call
93
146
  `#start_listening` with the same parameters.
94
147
 
95
148
  Calls processing is thread safe because of eventmachine concept
96
- similar to fibers. Default number at one time processed jobs is 20,
97
- but it can be changed by setting `:max_jobs => <number>` to `#listen!`
98
- or `#start_listening`.
149
+ similar to fibers. Reponse will be put to the same queue server,
150
+ to queue named `qrpc-<client identifier>-output`, with structure
151
+ described above.
99
152
 
100
- The `#precall` and `#postcall` handlers are supported on the API class
101
- called if API responds to them. Currently, they don't receive any
102
- parameters and are intended for simple call initialization only.
153
+ Server can work by synchronous or asynchronous way. In the first case,
154
+ sends the returned values as result, in the other case yielded.
103
155
 
104
- Reponse will be put to the same queue server, to queue named
105
- `qrpc-<client identifier>-output`, with structure described above.
106
156
 
107
157
  ### Client Usage
108
158
 
109
- Client usage is simple too. Look example:
159
+ Client usage is simple too. Look example complement the example above:
110
160
 
111
161
  require "eventmachine"
112
- require "qrpc/client"
113
- require "qrpc/locator"
162
+
163
+ require "qrpc/client" # client
164
+ require "qrpc/generator/uuid" # ID generator
165
+ require "qrpc/locator/em-jack" # queue transfer agent
166
+ require "qrpc/protocol/json-rpc" # RPC protocol
167
+ require "json-rpc-objects/serializer/msgpack" # serializer
114
168
 
115
169
  EM::run do
116
- client = QRPC::Client::new QRPC::Locator::new "test"
170
+ generator = QRPC::Generator::ObjectID::new
171
+ locator = QRPC::Locator::EMJackLocator::new(:test)
172
+ serializer = JsonRpcObjects::Serializer::JSON::new
173
+ protocol = QRPC::Protocol::JsonRpc::new(:serializer => serializer)
174
+
175
+ client = QRPC::Client::new(locator, generator, protocol)
117
176
  client.subtract(2, 3) { |result| puts result } # prints out -1
118
177
  end
119
178
 
@@ -126,7 +185,7 @@ its principle.
126
185
 
127
186
  Client is implemented as [evented][1] too, but in case of need you can
128
187
  implement another one with non-evented interface using whatever
129
- [beanstalkd][2] client you like of sure.
188
+ [beanstalkd][2] client you like of sure or any other transfer agent.
130
189
 
131
190
  Contributing
132
191
  ------------
@@ -142,7 +201,7 @@ Contributing
142
201
  Copyright
143
202
  ---------
144
203
 
145
- Copyright &copy; 2011 [Martin Kozák][7]. See `LICENSE.txt` for
204
+ Copyright &copy; 2011-2012 [Martin Kozák][7]. See `LICENSE.txt` for
146
205
  further details.
147
206
 
148
207
  [1]: http://rubyeventmachine.com/
@@ -152,3 +211,11 @@ further details.
152
211
  [5]: http://groups.google.com/group/json-rpc/web/json-rpc-2-0
153
212
  [6]: http://github.com/martinkozak/qrpc/issues
154
213
  [7]: http://www.martinkozak.net/
214
+ [10]: http://github.com/martinkozak/unified-queues
215
+ [11]: http://en.wikipedia.org/wiki/Universally_unique_identifier
216
+ [12]: http://ruby-doc.org/core-1.9.3/Object.html#method-i-object_id
217
+ [13]: http://github.com/martinkozak/json-rpc-objects
218
+ [14]: http://www.json.org/
219
+ [15]: http://bsonspec.org/
220
+ [16]: http://yaml.org/
221
+ [17]: http://msgpack.org/
data/Rakefile CHANGED
@@ -18,7 +18,8 @@ Jeweler::Tasks.new do |gem|
18
18
  gem.name = "qrpc"
19
19
  gem.homepage = "http://github.com/martinkozak/qrpc"
20
20
  gem.license = "MIT"
21
- gem.summary = 'Queued JSON-RPC client and server. Works as normal RPC server, but through queue interface, so allows highly scalable, distributed and asynchronous remote API implementation and fast data processing. It\'s based on eventmachine and beanstalkd, so it\'s fast and thread safe.'
21
+ gem.summary = 'Queued RPC client and server. Works as normal RPC server, but through queue interface, so allows highly scalable, distributed and asynchronous remote API implementation and fast data processing. It\'s based on EventMachine and typically on Beanstalk, so it\'s fast and thread safe.'
22
+ gem.post_install_message = "\nQRPC: API of the 0.9.x version (and 1.0 in future) is partialy incompatible with the older versions. Modifications of your current applications may be necessary for upgrading them to the latest version. \n\n"
22
23
  gem.email = "martinkozak@martinkozak.net"
23
24
  gem.authors = ["Martin Kozák"]
24
25
  # Include your dependencies below. Runtime dependencies are required when using your gem,
data/TODO.md CHANGED
@@ -1,3 +1 @@
1
- * general queue interface for ability to use more queue servers (starling, sparrow, kestrel, stomp, AMQP...)
2
- * copyright headers to all files
3
- * think about Protocol Buffers or an binary format (BSON!) in general
1
+ * plugins for more queue servers (starling, sparrow, kestrel, stomp, AMQP...)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.9.0
data/lib/qrpc/client.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  # encoding: utf-8
2
+ # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
+
2
4
  require "qrpc/client/dispatcher"
5
+ require "qrpc/generator/uuid"
6
+ require "qrpc/general"
3
7
 
4
8
  ##
5
9
  # General QRPC module.
@@ -30,22 +34,26 @@ module QRPC
30
34
 
31
35
  ##
32
36
  # Constructor.
33
- # @param [QRPC::Locator] locator of the output queue
37
+ #
38
+ # @param [QRPC::Locator] locator of the queues
39
+ # @param [QRPC::Generator] ID generator
40
+ # @param [QRPC::Protocol::Abstract] protocol protocol of the session
34
41
  #
35
42
 
36
- def initialize(locator)
37
- @dispatcher = QRPC::Client::Dispatcher::new(locator)
43
+ def initialize(locator, generator = QRPC::default_generator, protocol = QRPC::default_protocol)
44
+ @dispatcher = QRPC::Client::Dispatcher::new(locator, generator, protocol)
38
45
  end
39
46
 
40
47
  ##
41
48
  # Handles call to RPC. (*********)
42
49
  #
43
50
  # Be warn, arguments will be serialized to JSON, so they should
44
- # be serializable nativelly or implement +#to_json+ method.
51
+ # be serializable nativelly or implement +#to_s+ or +#to_json+
52
+ # method.
45
53
  #
46
54
  # @param [Symbol] name name of the called methods
47
55
  # @param [Array] args arguments of the called methods
48
- # @param [Proc] block callback for returning result
56
+ # @param [Proc] block callback for returning
49
57
  #
50
58
 
51
59
  def method_missing(name, *args, &block)
@@ -1,8 +1,11 @@
1
1
  # encoding: utf-8
2
+ # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
+
2
4
  require "em-jack"
3
- require "uuid"
5
+ require "em-batch"
4
6
  require "qrpc/general"
5
7
  require "qrpc/client/job"
8
+ require "hash-utils/object" # >= 1.1.0
6
9
  require "json-rpc-objects/response"
7
10
 
8
11
  ##
@@ -23,18 +26,30 @@ module QRPC
23
26
  class Client
24
27
 
25
28
  ##
26
- # Queue RPC client dispatcher (worker).
29
+ # Queue RPC client dispaxtcher (worker).
27
30
  # @since 0.3.0
28
31
  #
29
32
 
30
33
  class Dispatcher
34
+
35
+ ##
36
+ # Holds current protocol object.
37
+ #
38
+
39
+ @protocol
31
40
 
32
41
  ##
33
42
  # Holds locator of the target queue.
34
43
  #
35
44
 
36
45
  @locator
46
+
47
+ ##
48
+ # Holds generator of IDs.
49
+ #
37
50
 
51
+ @generator
52
+
38
53
  ##
39
54
  # Holds client session ID.
40
55
  #
@@ -77,17 +92,21 @@ module QRPC
77
92
 
78
93
  @@clients = { }
79
94
 
80
-
81
95
  ##
82
96
  # Constructor.
97
+ #
83
98
  # @param [QRPC::Locator] locator of the output queue
99
+ # @param [QRPC::Generator] ID generator
100
+ # @param [QRPC::Protocol::Abstract] protocol protocol of the session
84
101
  #
85
102
 
86
- def initialize(locator)
103
+ def initialize(locator, generator = QRPC::default_generator, protocol = QRPC::default_protocol)
104
+ @protocol = protocol
87
105
  @locator = locator
106
+ @generator = generator
88
107
  @pooling = false
89
108
  @jobs = { }
90
-
109
+
91
110
  # Destructor
92
111
  ObjectSpace.define_finalizer(self, self.class.method(:finalize).to_proc)
93
112
  @@clients[self.object_id] = self
@@ -110,16 +129,16 @@ module QRPC
110
129
 
111
130
  def finalize!
112
131
  if not @input_queue.nil?
113
- @input_queue.watch("default") do
114
- @input_queue.ignore(@input_name.to_s) do
115
- @input_queue.close
132
+ @input_queue.subscribe("default") do
133
+ @input_queue.unsubscribe(@input_name.to_s) do
134
+ @input_queue.close!
116
135
  end
117
136
  end
118
137
  end
119
138
 
120
139
  if not @output_queue.nil?
121
140
  @output_queue.use("default") do
122
- @output_queue.close
141
+ @output_queue.close!
123
142
  end
124
143
  end
125
144
  end
@@ -135,7 +154,7 @@ module QRPC
135
154
  #
136
155
 
137
156
  def create_job(name, args, priority = QRPC::DEFAULT_PRIORITY, &block)
138
- Client::Job::new(self.id, name, args, priority, &block)
157
+ Client::Job::new(self.id, name, args, priority, @generator, @protocol, &block)
139
158
  end
140
159
 
141
160
  ##
@@ -144,16 +163,19 @@ module QRPC
144
163
 
145
164
  def put(job)
146
165
  if not job.notification?
147
- @jobs[job.id] = job
148
- end
149
-
150
- self.output_queue do |queue|
151
- queue.put(job.to_json)
166
+ id = job.id
167
+ id = id.to_sym if not id.kind_of? Integer
168
+
169
+ @jobs[id] = job
152
170
  end
153
171
 
154
172
  if (not @pooling) and (@jobs.length > 0)
155
173
  self.pool!
156
174
  end
175
+
176
+ self.output_queue do |queue|
177
+ queue.push(job.serialize)
178
+ end
157
179
  end
158
180
 
159
181
  ##
@@ -164,28 +186,26 @@ module QRPC
164
186
 
165
187
  # Results processing logic
166
188
  processor = Proc::new do |job|
167
- response = JsonRpcObjects::Response::parse(job.body)
168
- job.delete()
189
+ response = @protocol.response::parse(job)
169
190
 
170
191
  if not response.id.nil?
171
- id = response.id.to_sym
192
+ id = response.id
193
+ id = id.to_sym if not id.kind_of? Integer
194
+
172
195
  if @jobs.include? id
173
196
  @jobs[id].assign_result(response)
197
+ @jobs.delete(id)
174
198
  end
175
199
  end
176
-
177
- @jobs.delete(id)
178
200
  end
179
201
 
180
- # Runs processor for each job
181
- parent = self
182
- worker = EM.spawn do
183
- parent.input_queue { |q| q.each_job(&processor) }
202
+ # Runs processor for each job (expects recurring #pop)
203
+ self.input_queue do |queue|
204
+ queue.pop(true, &processor)
184
205
  end
185
206
 
186
207
  ##
187
208
 
188
- worker.run
189
209
  @pooling = true
190
210
 
191
211
  end
@@ -197,10 +217,10 @@ module QRPC
197
217
 
198
218
  def input_name
199
219
  if @input_name.nil?
200
- @input_name = (QRPC::QUEUE_PREFIX.dup << "-" << self.id.to_s << "-" << QRPC::QUEUE_POSTFIX_OUTPUT).to_sym
220
+ @input_name = (QRPC::QUEUE_PREFIX + "-" + self.id.to_s + "-" + QRPC::QUEUE_POSTFIX_OUTPUT).to_sym
221
+ else
222
+ @input_name
201
223
  end
202
-
203
- return @input_name
204
224
  end
205
225
 
206
226
  ##
@@ -210,22 +230,16 @@ module QRPC
210
230
 
211
231
  def input_queue(&block)
212
232
  if @input_queue.nil?
213
- @input_queue = EMJack::Connection::new(:host => @locator.host, :port => @locator.port)
214
- @input_queue.watch(self.input_name.to_s) do
215
- @input_queue.ignore("default") do
216
-
217
- # Results pooler error handler
218
- @input_queue.on_error do |error|
219
- raise ::Exception::new("Beanstalk error: " << error.to_s)
220
- end
221
-
222
- # Returns
223
- block.call(@input_queue)
224
-
233
+ @input_queue = @locator.input_queue
234
+ @input_queue.subscribe(self.input_name.to_s) do
235
+ @input_queue.unsubscribe("default") do
236
+ yield @input_queue
225
237
  end
226
238
  end
227
239
  else
228
- block.call(@input_queue)
240
+ @input_queue.subscribe(self.input_name.to_s) do
241
+ yield @input_queue
242
+ end
229
243
  end
230
244
  end
231
245
 
@@ -236,10 +250,10 @@ module QRPC
236
250
 
237
251
  def output_name
238
252
  if @output_name.nil?
239
- @output_name = (QRPC::QUEUE_PREFIX.dup << "-" << @locator.queue << "-" << QRPC::QUEUE_POSTFIX_INPUT).to_sym
253
+ @output_name = (QRPC::QUEUE_PREFIX + "-" + @locator.queue_name + "-" + QRPC::QUEUE_POSTFIX_INPUT).to_sym
254
+ else
255
+ @output_name
240
256
  end
241
-
242
- return @output_name
243
257
  end
244
258
 
245
259
  ##
@@ -249,12 +263,14 @@ module QRPC
249
263
 
250
264
  def output_queue(&block)
251
265
  if @output_queue.nil?
252
- @output_queue = EMJack::Connection::new(:host => @locator.host, :port => @locator.port)
266
+ @output_queue = @locator.output_queue
253
267
  @output_queue.use(self.output_name.to_s) do
254
- block.call(@output_queue)
268
+ yield @output_queue
255
269
  end
256
270
  else
257
- block.call(@output_queue)
271
+ @output_queue.use(self.output_name.to_s) do
272
+ yield @output_queue
273
+ end
258
274
  end
259
275
  end
260
276
 
@@ -265,10 +281,10 @@ module QRPC
265
281
 
266
282
  def id
267
283
  if @id.nil?
268
- @id = UUID.generate(:compact).to_sym
284
+ @id = @generator.generate(self)
285
+ else
286
+ @id
269
287
  end
270
-
271
- return @id
272
288
  end
273
289
 
274
290
  end