rjr 0.18.1 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rjr/common.rb +10 -0
- data/lib/rjr/dispatcher.rb +7 -2
- data/lib/rjr/inspect.rb +5 -0
- data/lib/rjr/node.rb +18 -1
- data/lib/rjr/nodes/amqp.rb +1 -0
- data/lib/rjr/nodes/local.rb +1 -0
- data/lib/rjr/nodes/tcp.rb +1 -0
- data/lib/rjr/nodes/unix.rb +1 -0
- data/lib/rjr/nodes/web.rb +1 -0
- data/lib/rjr/nodes/ws.rb +1 -0
- data/lib/rjr/version.rb +1 -1
- data/specs/dispatcher_spec.rb +39 -25
- data/specs/node_spec.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d55a14977509a3c88cdd498f075666cb3e3bac3
|
4
|
+
data.tar.gz: d41f1a19c4750ec55392b1530499ddfea7832dbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26d189aa6818b7b2046756be51fb112cabcd183e1a9d67ba7686ff75b99f459d70333c1504f049d995b2d5c518b86042a7b8542a16c16efc1c2e81304927cc86
|
7
|
+
data.tar.gz: 87c4581787d211a26b8e8dc99eb53413183032eb151c02ceb7f1bafb07648b299a7c63b9ef9fd62b55f40d21fc31b3eb54f2366bb69b84556c26e279e7fc3120
|
data/lib/rjr/common.rb
CHANGED
@@ -15,6 +15,16 @@ end
|
|
15
15
|
|
16
16
|
module RJR
|
17
17
|
|
18
|
+
# Return the persistent rjr nodes
|
19
|
+
def self.persistent_nodes
|
20
|
+
# rerun each time (eg don't store in var) incase new nodes were included
|
21
|
+
RJR::Nodes.constants.collect { |n|
|
22
|
+
nc = RJR::Nodes.const_get(n)
|
23
|
+
nc.superclass == RJR::Node && nc.persistent? ?
|
24
|
+
nc : nil
|
25
|
+
}.compact
|
26
|
+
end
|
27
|
+
|
18
28
|
# Logger helper class.
|
19
29
|
#
|
20
30
|
# Encapsulates the standard ruby logger in a thread safe manner. Dispatches
|
data/lib/rjr/dispatcher.rb
CHANGED
@@ -184,11 +184,16 @@ class Dispatcher
|
|
184
184
|
# Registered json-rpc request signatures and environments which to execute handlers in
|
185
185
|
attr_reader :environments
|
186
186
|
|
187
|
+
# Flag toggling whether or not to keep requests (& responses) around.
|
188
|
+
attr_accessor :keep_requests
|
189
|
+
|
187
190
|
# Requests which have been dispatched
|
188
191
|
def requests ; @requests_lock.synchronize { Array.new(@requests) } ; end
|
189
192
|
|
190
193
|
# RJR::Dispatcher intializer
|
191
|
-
def initialize
|
194
|
+
def initialize(args = {})
|
195
|
+
@keep_requests = args[:keep_requests] || false
|
196
|
+
|
192
197
|
clear!
|
193
198
|
@requests_lock = Mutex.new
|
194
199
|
end
|
@@ -306,7 +311,7 @@ class Dispatcher
|
|
306
311
|
|
307
312
|
end
|
308
313
|
|
309
|
-
@requests_lock.synchronize { @requests << request }
|
314
|
+
@requests_lock.synchronize { @requests << request } if @keep_requests
|
310
315
|
return request.result
|
311
316
|
end
|
312
317
|
|
data/lib/rjr/inspect.rb
CHANGED
@@ -5,6 +5,11 @@
|
|
5
5
|
# manually include this module to incorporate these additional rjr method
|
6
6
|
# definitions into your node
|
7
7
|
#
|
8
|
+
# Note by default RJR will _not_ keep persistant copies or requests
|
9
|
+
# and responses. If available these are leveraged here to provide
|
10
|
+
# a detailed analysis of the server. To enabled set the 'keep_requests'
|
11
|
+
# flag on your RJR::Dispatcher instance to true
|
12
|
+
#
|
8
13
|
# Copyright (C) 2013 Mohammed Morsi <mo@morsi.org>
|
9
14
|
# Licensed under the Apache License, Version 2.0
|
10
15
|
|
data/lib/rjr/node.rb
CHANGED
@@ -44,6 +44,19 @@ class Node
|
|
44
44
|
# Dispatcher to use to satisfy requests
|
45
45
|
attr_accessor :dispatcher
|
46
46
|
|
47
|
+
class <<self
|
48
|
+
# Bool indiciting if this node is persistent
|
49
|
+
def persistent?
|
50
|
+
self.const_defined?(:PERSISTENT_NODE) &&
|
51
|
+
self.const_get(:PERSISTENT_NODE)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Bool indicating if this node class is persistent
|
56
|
+
def persistent?
|
57
|
+
self.class.persistent?
|
58
|
+
end
|
59
|
+
|
47
60
|
# alias of RJR_NODE_TYPE
|
48
61
|
def node_type
|
49
62
|
self.class::RJR_NODE_TYPE
|
@@ -60,7 +73,7 @@ class Node
|
|
60
73
|
# @option args [Hash<String,String>] :headers optional headers to set on all json-rpc messages
|
61
74
|
# @option args [Dispatcher] :dispatcher dispatcher to assign to the node
|
62
75
|
def initialize(args = {})
|
63
|
-
|
76
|
+
clear_event_handlers
|
64
77
|
@response_lock = Mutex.new
|
65
78
|
@response_cv = ConditionVariable.new
|
66
79
|
@responses = []
|
@@ -99,6 +112,10 @@ class Node
|
|
99
112
|
end
|
100
113
|
|
101
114
|
##################################################################
|
115
|
+
# Reset connection event handlers
|
116
|
+
def clear_event_handlers
|
117
|
+
@connection_event_handlers = {:closed => [], :error => []}
|
118
|
+
end
|
102
119
|
|
103
120
|
# Register connection event handler
|
104
121
|
# @param [:error, :close] event the event to register the handler for
|
data/lib/rjr/nodes/amqp.rb
CHANGED
data/lib/rjr/nodes/local.rb
CHANGED
data/lib/rjr/nodes/tcp.rb
CHANGED
data/lib/rjr/nodes/unix.rb
CHANGED
data/lib/rjr/nodes/web.rb
CHANGED
data/lib/rjr/nodes/ws.rb
CHANGED
data/lib/rjr/version.rb
CHANGED
data/specs/dispatcher_spec.rb
CHANGED
@@ -221,33 +221,47 @@ module RJR
|
|
221
221
|
r.error_class.should == ArgumentError
|
222
222
|
end
|
223
223
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
d.requests.first.rjr_method.should == 'foobar'
|
224
|
+
context "keep_requests is false (default)" do
|
225
|
+
it "should not store requests" do
|
226
|
+
d = Dispatcher.new
|
227
|
+
d.handle('foobar') {}
|
228
|
+
d.requests.should be_empty
|
229
|
+
d.dispatch :rjr_method => 'foobar'
|
230
|
+
d.requests.should be_empty
|
231
|
+
end
|
233
232
|
end
|
234
233
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
234
|
+
context "keep_requests is true" do
|
235
|
+
it "should store request locally" do
|
236
|
+
d = Dispatcher.new :keep_requests => true
|
237
|
+
h = proc {}
|
238
|
+
d.handle('foobar', &h)
|
239
|
+
|
240
|
+
d.requests.size.should == 0
|
241
|
+
d.dispatch :rjr_method => 'foobar'
|
242
|
+
d.requests.size.should == 1
|
243
|
+
d.requests.first.rjr_method.should == 'foobar'
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should set params on request" do
|
247
|
+
d = Dispatcher.new
|
248
|
+
d.keep_requests = true
|
249
|
+
h = proc { |p| }
|
250
|
+
d.handle('foobar', &h)
|
251
|
+
|
252
|
+
d.dispatch(:rjr_method => 'foobar', :rjr_method_args => [42])
|
253
|
+
d.requests.first.rjr_method_args.should == [42]
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should set result on request" do
|
257
|
+
d = Dispatcher.new
|
258
|
+
d.keep_requests = true
|
259
|
+
h = proc { 42 }
|
260
|
+
d.handle('foobar', &h)
|
261
|
+
|
262
|
+
d.dispatch :rjr_method => 'foobar'
|
263
|
+
d.requests.first.result.result.should == 42
|
264
|
+
end
|
251
265
|
end
|
252
266
|
end
|
253
267
|
end
|
data/specs/node_spec.rb
CHANGED
@@ -10,6 +10,38 @@ module RJR
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
describe "::persistent?" do
|
14
|
+
context "PERSISTENT_NODE is defined and true" do
|
15
|
+
it "returns true" do
|
16
|
+
new_node = Class.new(Node)
|
17
|
+
new_node.const_set(:PERSISTENT_NODE, true)
|
18
|
+
new_node.should be_persistent
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "PERSISTENT_NODE is not defined or returns false" do
|
23
|
+
it "returns false" do
|
24
|
+
Node.should_not be_persistent
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#persistent?" do
|
30
|
+
context "instance of a persistent node" do
|
31
|
+
it "returns true" do
|
32
|
+
new_node = Class.new(Node)
|
33
|
+
new_node.const_set(:PERSISTENT_NODE, true)
|
34
|
+
new_node.new.should be_persistent
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "not an instance of a persistent node" do
|
39
|
+
it "returns false" do
|
40
|
+
Node.new.should_not be_persistent
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
13
45
|
it "should initialize properly from params" do
|
14
46
|
d = Dispatcher.new
|
15
47
|
node = Node.new :node_id => 'foobar',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rjr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.18.
|
4
|
+
version: 0.18.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mo Morsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|