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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5a404d0bde0749357c01f0e57696e73ff39ea6d
4
- data.tar.gz: 0c5394cf7df7774def9553b772c1cb92c53504de
3
+ metadata.gz: 4d55a14977509a3c88cdd498f075666cb3e3bac3
4
+ data.tar.gz: d41f1a19c4750ec55392b1530499ddfea7832dbc
5
5
  SHA512:
6
- metadata.gz: cf24b7e0fc705957af5ffe74879ab053a78393f33b28070cde205cb04a3879282d492dec85efd29938a6f51c27bee5a1ec3b6b6294e683d6bed7ed1cc0dfb1bb
7
- data.tar.gz: ed2bf6a3203387e00aeb5c84f0d836c50833ddd4901c581085ae66c8b286cddbba356ea0023bf8cbd6221c5b693a5508675ad9697f70023cdc319dd6f1f58335
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
@@ -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
- @connection_event_handlers = {:closed => [], :error => []}
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
@@ -51,6 +51,7 @@ module Nodes
51
51
  #
52
52
  class AMQP < RJR::Node
53
53
  RJR_NODE_TYPE = :amqp
54
+ PERSISTENT_NODE = true
54
55
 
55
56
  private
56
57
 
@@ -37,6 +37,7 @@ module Nodes
37
37
  #
38
38
  class Local < RJR::Node
39
39
  RJR_NODE_TYPE = :local
40
+ PERSISTENT_NODE = true
40
41
 
41
42
  # allows clients to override the node type for the local node
42
43
  attr_accessor :node_type
data/lib/rjr/nodes/tcp.rb CHANGED
@@ -79,6 +79,7 @@ end
79
79
  #
80
80
  class TCP < RJR::Node
81
81
  RJR_NODE_TYPE = :tcp
82
+ PERSISTENT_NODE = true
82
83
 
83
84
  attr_accessor :connections
84
85
 
@@ -64,6 +64,7 @@ end
64
64
  #
65
65
  class Unix < RJR::Node
66
66
  RJR_NODE_TYPE = :unix
67
+ PERSISTENT_NODE = true
67
68
 
68
69
  attr_accessor :connections
69
70
 
data/lib/rjr/nodes/web.rb CHANGED
@@ -93,6 +93,7 @@ end
93
93
  class Web < RJR::Node
94
94
 
95
95
  RJR_NODE_TYPE = :web
96
+ PERSISTENT_NODE = false
96
97
 
97
98
  public
98
99
 
data/lib/rjr/nodes/ws.rb CHANGED
@@ -54,6 +54,7 @@ module Nodes
54
54
  #
55
55
  class WS < RJR::Node
56
56
  RJR_NODE_TYPE = :ws
57
+ PERSISTENT_NODE = true
57
58
 
58
59
  private
59
60
 
data/lib/rjr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RJR
2
- VERSION = '0.18.1'
2
+ VERSION = '0.18.2'
3
3
  end
@@ -221,33 +221,47 @@ module RJR
221
221
  r.error_class.should == ArgumentError
222
222
  end
223
223
 
224
- it "should register request" do
225
- d = Dispatcher.new
226
- h = proc {}
227
- d.handle('foobar', &h)
228
-
229
- d.requests.size.should == 0
230
- d.dispatch :rjr_method => 'foobar'
231
- d.requests.size.should == 1
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
- it "should set params on request" do
236
- d = Dispatcher.new
237
- h = proc { |p| }
238
- d.handle('foobar', &h)
239
-
240
- d.dispatch(:rjr_method => 'foobar', :rjr_method_args => [42])
241
- d.requests.first.rjr_method_args.should == [42]
242
- end
243
-
244
- it "should set result on request" do
245
- d = Dispatcher.new
246
- h = proc { 42 }
247
- d.handle('foobar', &h)
248
-
249
- d.dispatch :rjr_method => 'foobar'
250
- d.requests.first.result.result.should == 42
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.1
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: 2013-12-31 00:00:00.000000000 Z
11
+ date: 2014-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec