rjr 0.12.2 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +49 -36
- data/Rakefile +2 -0
- data/bin/rjr-client +11 -9
- data/bin/rjr-server +12 -10
- data/examples/amqp.rb +29 -0
- data/examples/client.rb +32 -0
- data/examples/complete.rb +36 -0
- data/examples/local.rb +29 -0
- data/examples/server.rb +26 -0
- data/examples/tcp.rb +29 -0
- data/examples/web.rb +22 -0
- data/examples/ws.rb +29 -0
- data/lib/rjr/common.rb +7 -12
- data/lib/rjr/dispatcher.rb +171 -239
- data/lib/rjr/em_adapter.rb +33 -66
- data/lib/rjr/message.rb +43 -12
- data/lib/rjr/node.rb +197 -103
- data/lib/rjr/nodes/amqp.rb +216 -0
- data/lib/rjr/nodes/easy.rb +159 -0
- data/lib/rjr/nodes/local.rb +118 -0
- data/lib/rjr/{missing_node.rb → nodes/missing.rb} +4 -2
- data/lib/rjr/nodes/multi.rb +79 -0
- data/lib/rjr/nodes/tcp.rb +211 -0
- data/lib/rjr/nodes/web.rb +197 -0
- data/lib/rjr/nodes/ws.rb +187 -0
- data/lib/rjr/stats.rb +70 -0
- data/lib/rjr/thread_pool.rb +178 -123
- data/site/index.html +45 -0
- data/site/jquery-latest.js +9404 -0
- data/site/jrw.js +297 -0
- data/site/json.js +199 -0
- data/specs/dispatcher_spec.rb +244 -198
- data/specs/em_adapter_spec.rb +52 -80
- data/specs/message_spec.rb +223 -197
- data/specs/node_spec.rb +67 -163
- data/specs/nodes/amqp_spec.rb +82 -0
- data/specs/nodes/easy_spec.rb +13 -0
- data/specs/nodes/local_spec.rb +72 -0
- data/specs/nodes/multi_spec.rb +65 -0
- data/specs/nodes/tcp_spec.rb +75 -0
- data/specs/nodes/web_spec.rb +77 -0
- data/specs/nodes/ws_spec.rb +78 -0
- data/specs/stats_spec.rb +59 -0
- data/specs/thread_pool_spec.rb +44 -35
- metadata +40 -30
- data/lib/rjr/amqp_node.rb +0 -330
- data/lib/rjr/inspect.rb +0 -65
- data/lib/rjr/local_node.rb +0 -150
- data/lib/rjr/multi_node.rb +0 -65
- data/lib/rjr/tcp_node.rb +0 -323
- data/lib/rjr/thread_pool2.rb +0 -272
- data/lib/rjr/util.rb +0 -104
- data/lib/rjr/web_node.rb +0 -266
- data/lib/rjr/ws_node.rb +0 -289
- data/lib/rjr.rb +0 -16
- data/specs/amqp_node_spec.rb +0 -31
- data/specs/inspect_spec.rb +0 -60
- data/specs/local_node_spec.rb +0 -43
- data/specs/multi_node_spec.rb +0 -45
- data/specs/tcp_node_spec.rb +0 -33
- data/specs/util_spec.rb +0 -46
- data/specs/web_node_spec.rb +0 -32
- data/specs/ws_node_spec.rb +0 -32
- /data/lib/rjr/{tcp_node2.rb → nodes/tcp2.rb} +0 -0
- /data/lib/rjr/{udp_node.rb → nodes/udp.rb} +0 -0
data/specs/inspect_spec.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'rjr/inspect'
|
2
|
-
|
3
|
-
describe 'rjr/inspect.rb' do
|
4
|
-
describe "select_stats" do
|
5
|
-
before(:each) do
|
6
|
-
RJR::DispatcherStat.reset
|
7
|
-
|
8
|
-
req1 = RJR::Request.new :rjr_node_type => :local, :method => 'foobar'
|
9
|
-
req2 = RJR::Request.new :rjr_node_type => :tcp, :method => 'barfoo'
|
10
|
-
req3 = RJR::Request.new :rjr_node_type => :amqp, :method => 'foobar'
|
11
|
-
res1 = RJR::Result.new :result => true
|
12
|
-
res2 = RJR::Result.new :error_code => 123
|
13
|
-
res3 = RJR::Result.new :error_code => 123
|
14
|
-
|
15
|
-
@stat1 = RJR::DispatcherStat.new req1, res1
|
16
|
-
@stat2 = RJR::DispatcherStat.new req2, res2
|
17
|
-
@stat3 = RJR::DispatcherStat.new req3, res3
|
18
|
-
RJR::DispatcherStat << @stat1 << @stat2 << @stat3
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should get all dispatcherstats" do
|
22
|
-
stats = select_stats
|
23
|
-
stats.size.should == 3
|
24
|
-
stats.first.should == @stat1
|
25
|
-
stats[1].should == @stat2
|
26
|
-
stats.last.should == @stat3
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should get all dispatcherstats for a node" do
|
30
|
-
stats = select_stats 'on_node', 'local'
|
31
|
-
stats.size.should == 1
|
32
|
-
stats.first.should == @stat1
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should get all dispatcherstats for a method" do
|
36
|
-
stats = select_stats 'for_method', 'foobar'
|
37
|
-
stats.size.should == 2
|
38
|
-
stats.first.should == @stat1
|
39
|
-
stats.last.should == @stat3
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should get all successfull/failed dispatcherstats" do
|
43
|
-
stats = select_stats 'successful'
|
44
|
-
stats.size.should == 1
|
45
|
-
stats.first.should == @stat1
|
46
|
-
|
47
|
-
stats = select_stats 'failed'
|
48
|
-
stats.size.should == 2
|
49
|
-
stats.first.should == @stat2
|
50
|
-
stats.last.should == @stat3
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should get dispatcher stats meeting multiple criteria" do
|
54
|
-
stats = select_stats 'for_method', 'foobar', 'successful'
|
55
|
-
stats.size.should == 1
|
56
|
-
stats.first.should == @stat1
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
data/specs/local_node_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'rjr/local_node'
|
2
|
-
require 'rjr/dispatcher'
|
3
|
-
|
4
|
-
describe RJR::LocalNode do
|
5
|
-
it "should invoke requests against local handler" do
|
6
|
-
node = RJR::LocalNode.new :node_id => 'aaa'
|
7
|
-
foobar_invoked = false
|
8
|
-
RJR::Dispatcher.init_handlers
|
9
|
-
RJR::Dispatcher.add_handler('foobar') { |param|
|
10
|
-
@rjr_node.should == node
|
11
|
-
@rjr_node_id.should == 'aaa'
|
12
|
-
@rjr_node_type.should == :local
|
13
|
-
param.should == 'myparam'
|
14
|
-
foobar_invoked = true
|
15
|
-
'retval'
|
16
|
-
}
|
17
|
-
|
18
|
-
res = node.invoke_request 'foobar', 'myparam'
|
19
|
-
foobar_invoked.should == true
|
20
|
-
res.should == 'retval'
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should invoke callbacks against local handlers" do
|
24
|
-
foobar_invoked = false
|
25
|
-
callback_invoked = false
|
26
|
-
RJR::Dispatcher.init_handlers
|
27
|
-
RJR::Dispatcher.add_handler('foobar') {
|
28
|
-
foobar_invoked = true
|
29
|
-
@rjr_callback.invoke('callback', 'cp')
|
30
|
-
}
|
31
|
-
RJR::Dispatcher.add_handler('callback') { |*params|
|
32
|
-
params.length.should == 1
|
33
|
-
params[0].should == 'cp'
|
34
|
-
callback_invoked = true
|
35
|
-
}
|
36
|
-
|
37
|
-
node = RJR::LocalNode.new
|
38
|
-
node.invoke_request 'foobar', 'myparam'
|
39
|
-
end
|
40
|
-
|
41
|
-
# TODO make sure object attributes not serialized to json
|
42
|
-
# are not available on remote end of local node invocation/response
|
43
|
-
end
|
data/specs/multi_node_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'rjr/multi_node'
|
2
|
-
require 'rjr/amqp_node'
|
3
|
-
require 'rjr/web_node'
|
4
|
-
require 'rjr/dispatcher'
|
5
|
-
|
6
|
-
describe RJR::MultiNode do
|
7
|
-
it "should invoke and satisfy requests over multiple protocols" do
|
8
|
-
foolbar_invoked = false
|
9
|
-
barfoo_invoked = false
|
10
|
-
RJR::Dispatcher.init_handlers
|
11
|
-
RJR::Dispatcher.add_handler('foolbar') { |param|
|
12
|
-
@rjr_node_id.should == 'amqp'
|
13
|
-
@rjr_node_type.should == :amqp
|
14
|
-
param.should == 'myparam1'
|
15
|
-
foolbar_invoked = true
|
16
|
-
'retval1'
|
17
|
-
}
|
18
|
-
RJR::Dispatcher.add_handler('barfoo') { |param|
|
19
|
-
@rjr_node_id.should == 'web'
|
20
|
-
@rjr_node_type.should == :web
|
21
|
-
param.should == 'myparam2'
|
22
|
-
barfoo_invoked = true
|
23
|
-
'retval2'
|
24
|
-
}
|
25
|
-
|
26
|
-
amqp = RJR::AMQPNode.new :node_id => 'amqp', :broker => 'localhost'
|
27
|
-
web = RJR::WebNode.new :node_id => 'web', :host => 'localhost', :port => 9876
|
28
|
-
multi = RJR::MultiNode.new :node_id => 'multi', :nodes => [amqp, web], :keep_alive => true
|
29
|
-
|
30
|
-
multi.listen
|
31
|
-
|
32
|
-
amqp_client = RJR::AMQPNode.new :node_id => 'client', :broker => 'localhost', :keep_alive => true # see comment about keepalive in amqp_node_spec
|
33
|
-
res = amqp_client.invoke_request 'amqp-queue', 'foolbar', 'myparam1'
|
34
|
-
res.should == 'retval1'
|
35
|
-
|
36
|
-
web_client = RJR::WebNode.new
|
37
|
-
res = web_client.invoke_request 'http://localhost:9876', 'barfoo', 'myparam2'
|
38
|
-
res.should == 'retval2'
|
39
|
-
|
40
|
-
multi.halt
|
41
|
-
multi.join
|
42
|
-
foolbar_invoked.should == true
|
43
|
-
barfoo_invoked.should == true
|
44
|
-
end
|
45
|
-
end
|
data/specs/tcp_node_spec.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'rjr/tcp_node'
|
2
|
-
require 'rjr/dispatcher'
|
3
|
-
|
4
|
-
describe RJR::TCPNode do
|
5
|
-
it "should invoke and satisfy tcp requests" do
|
6
|
-
server = RJR::TCPNode.new :node_id => 'tcp', :host => 'localhost', :port => 9987
|
7
|
-
client = RJR::TCPNode.new
|
8
|
-
|
9
|
-
foobar_invoked = false
|
10
|
-
RJR::Dispatcher.init_handlers
|
11
|
-
RJR::Dispatcher.add_handler('foobar') { |param|
|
12
|
-
@client_ip.should == "127.0.0.1"
|
13
|
-
#@client_port.should == 9987
|
14
|
-
@rjr_node.should == server
|
15
|
-
@rjr_node_id.should == 'tcp'
|
16
|
-
@rjr_node_type.should == :tcp
|
17
|
-
param.should == 'myparam'
|
18
|
-
foobar_invoked = true
|
19
|
-
'retval'
|
20
|
-
}
|
21
|
-
|
22
|
-
server.listen
|
23
|
-
sleep 1
|
24
|
-
res = client.invoke_request 'jsonrpc://localhost:9987', 'foobar', 'myparam'
|
25
|
-
res.should == 'retval'
|
26
|
-
server.halt
|
27
|
-
server.join
|
28
|
-
foobar_invoked.should == true
|
29
|
-
end
|
30
|
-
|
31
|
-
# TODO ensure closed / error event handlers are invoked
|
32
|
-
# TODO ensure callbacks can be invoked over established connection w/ json-rpc notifications
|
33
|
-
end
|
data/specs/util_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'rjr/dispatcher'
|
2
|
-
require 'rjr/util'
|
3
|
-
|
4
|
-
describe RJR::Definitions do
|
5
|
-
include RJR::Definitions
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
RJR::Dispatcher.init_handlers
|
9
|
-
RJR::Definitions.reset
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should define methods" do
|
13
|
-
foobar = lambda {}
|
14
|
-
barfoo = lambda {}
|
15
|
-
rjr_method :foobar => foobar, :barfoo => barfoo
|
16
|
-
RJR::Dispatcher.handler_for('foobar').handler_proc.should == foobar
|
17
|
-
RJR::Dispatcher.handler_for('barfoo').handler_proc.should == barfoo
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should track messages" do
|
21
|
-
rjr_message :foobar => { :foo => :bar }
|
22
|
-
rjr_message('foobar').should == {:foo => :bar}
|
23
|
-
|
24
|
-
rjr_message :foobar => { :bar => :foo }
|
25
|
-
rjr_message('foobar').should == {:bar => :foo}
|
26
|
-
|
27
|
-
rjr_message('money').should be_nil
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should generate random message" do
|
31
|
-
rjr_message :foobar => { :foo => :bar, :transports => [:local, :amqp] }
|
32
|
-
rjr_message :barfoo => { :bar => :foo, :transports => [:local] }
|
33
|
-
rjr_message :forzzy => { :for => :zzy, :transports => [:amqp] }
|
34
|
-
rjr_message :moneyy => { :mon => :eyy }
|
35
|
-
|
36
|
-
[:foo, :bar, :for, :mon].should include(RJR::Definitions::rand_msg.first.first)
|
37
|
-
[:foo, :bar, :mon].should include(RJR::Definitions::rand_msg(:local).first.first)
|
38
|
-
[:foo, :for, :mon].should include(RJR::Definitions::rand_msg(:amqp).first.first)
|
39
|
-
RJR::Definitions::rand_msg(:tcp).first.first.should == :mon
|
40
|
-
|
41
|
-
RJR::Definitions.reset
|
42
|
-
rjr_message :foobar => { :foo => :bar, :transports => [:local, :amqp] }
|
43
|
-
|
44
|
-
RJR::Definitions::rand_msg(:tcp).should == nil
|
45
|
-
end
|
46
|
-
end
|
data/specs/web_node_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'rjr/web_node'
|
2
|
-
require 'rjr/dispatcher'
|
3
|
-
|
4
|
-
describe RJR::WebNode do
|
5
|
-
it "should invoke and satisfy http requests" do
|
6
|
-
server = RJR::WebNode.new :node_id => 'www', :host => 'localhost', :port => 9678
|
7
|
-
client = RJR::WebNode.new
|
8
|
-
|
9
|
-
foobar_invoked = false
|
10
|
-
RJR::Dispatcher.init_handlers
|
11
|
-
RJR::Dispatcher.add_handler('foobar') { |param|
|
12
|
-
@client_ip.should == "127.0.0.1"
|
13
|
-
#@client_port.should == 9678
|
14
|
-
@rjr_node.should == server
|
15
|
-
@rjr_node_id.should == 'www'
|
16
|
-
@rjr_node_type.should == :web
|
17
|
-
param.should == 'myparam'
|
18
|
-
foobar_invoked = true
|
19
|
-
'retval'
|
20
|
-
}
|
21
|
-
|
22
|
-
server.listen
|
23
|
-
sleep 1
|
24
|
-
|
25
|
-
res = client.invoke_request 'http://localhost:9678', 'foobar', 'myparam'
|
26
|
-
res.should == 'retval'
|
27
|
-
server.halt
|
28
|
-
|
29
|
-
server.join
|
30
|
-
foobar_invoked.should == true
|
31
|
-
end
|
32
|
-
end
|
data/specs/ws_node_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'rjr/ws_node'
|
2
|
-
require 'rjr/dispatcher'
|
3
|
-
|
4
|
-
describe RJR::WSNode do
|
5
|
-
it "should invoke and satisfy websocket requests" do
|
6
|
-
server = RJR::WSNode.new :node_id => 'ws', :host => 'localhost', :port => 9876
|
7
|
-
client = RJR::WSNode.new
|
8
|
-
|
9
|
-
foobar_invoked = false
|
10
|
-
RJR::Dispatcher.init_handlers
|
11
|
-
RJR::Dispatcher.add_handler('foobar') { |param|
|
12
|
-
@client_ip.should == "127.0.0.1"
|
13
|
-
#@client_port.should == 9678
|
14
|
-
@rjr_node.should == server
|
15
|
-
@rjr_node_id.should == 'ws'
|
16
|
-
@rjr_node_type.should == :ws
|
17
|
-
param.should == 'myparam'
|
18
|
-
foobar_invoked = true
|
19
|
-
'retval'
|
20
|
-
}
|
21
|
-
|
22
|
-
server.listen
|
23
|
-
sleep 1
|
24
|
-
res = client.invoke_request 'ws://localhost:9876', 'foobar', 'myparam'
|
25
|
-
res.should == 'retval'
|
26
|
-
server.halt
|
27
|
-
server.join
|
28
|
-
foobar_invoked.should == true
|
29
|
-
end
|
30
|
-
|
31
|
-
# TODO ensure closed / error event handlers are invoked
|
32
|
-
end
|
File without changes
|
File without changes
|