romp-rpc 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -0
- data/ext/extconf.rb +3 -0
- data/ext/romp_helper.c +822 -0
- data/lib/romp-rpc.rb +548 -0
- data/sample/client.rb +115 -0
- data/sample/server.rb +67 -0
- metadata +74 -0
data/sample/client.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# require 'profile'
|
2
|
+
require 'romp-rpc'
|
3
|
+
|
4
|
+
if ARGV.size > 1 or ARGV[0] == "-h" or ARGV[0] == '-H' then
|
5
|
+
puts <<END
|
6
|
+
Usage: #{$0} <url>
|
7
|
+
Example urls:
|
8
|
+
tcpromp://localhost:4242
|
9
|
+
udpromp://localhost:4242
|
10
|
+
unixromp:///tmp/foo
|
11
|
+
END
|
12
|
+
end
|
13
|
+
|
14
|
+
url = ARGV[0] || "tcpromp://localhost:4242"
|
15
|
+
client = ROMP::Client.new(url, false)
|
16
|
+
obj = client.resolve("foo")
|
17
|
+
|
18
|
+
N = 10
|
19
|
+
|
20
|
+
# --- Test normal functions ---
|
21
|
+
puts "Normal functions, no synchronization"
|
22
|
+
GC.start
|
23
|
+
start_time = Time.now
|
24
|
+
for i in 1..N do
|
25
|
+
obj.foo(i)
|
26
|
+
end
|
27
|
+
obj.sync()
|
28
|
+
total_time = Time.now - start_time
|
29
|
+
puts " Total time: #{total_time}"
|
30
|
+
puts " Messages per second: #{N/total_time}"
|
31
|
+
|
32
|
+
sleep(1)
|
33
|
+
|
34
|
+
# --- Test oneway functions ---
|
35
|
+
puts "Oneway functions, with synchronization"
|
36
|
+
GC.start
|
37
|
+
start_time = Time.now
|
38
|
+
for i in 1..N do
|
39
|
+
obj.oneway_sync(:foo, i)
|
40
|
+
# if (i % 1000) == 0 then
|
41
|
+
# obj.sync
|
42
|
+
# end
|
43
|
+
end
|
44
|
+
obj.sync()
|
45
|
+
total_time = Time.now - start_time
|
46
|
+
puts " Total time: #{total_time}"
|
47
|
+
puts " Messages per second: #{N/total_time}"
|
48
|
+
|
49
|
+
puts "You should see the number #{N}:"
|
50
|
+
puts obj.i()
|
51
|
+
|
52
|
+
# -- Test oneway functions without sync ---
|
53
|
+
puts "Oneway functions, no synchronization"
|
54
|
+
puts "(if this is slow, it is because the TCP buffers are being filled too fast)"
|
55
|
+
GC.start
|
56
|
+
start_time = Time.now
|
57
|
+
for i in 1..N do
|
58
|
+
obj.oneway(:foo, i)
|
59
|
+
# if (i % 1000) == 0 then
|
60
|
+
# obj.sync
|
61
|
+
# end
|
62
|
+
end
|
63
|
+
obj.sync()
|
64
|
+
total_time = Time.now - start_time
|
65
|
+
puts " Total time: #{total_time}"
|
66
|
+
puts " Messages per second: #{N/total_time}"
|
67
|
+
|
68
|
+
puts "You should see the number #{N}:"
|
69
|
+
puts obj.i()
|
70
|
+
# --- Test object inspection ---
|
71
|
+
puts "You should see an object Foo with an element @i=#{N}"
|
72
|
+
puts obj.inspect()
|
73
|
+
|
74
|
+
# --- Test dup ---
|
75
|
+
foo = obj.methods()
|
76
|
+
if foo.index("dup") then
|
77
|
+
puts "uh oh, shouldn't have found dup"
|
78
|
+
end
|
79
|
+
|
80
|
+
# --- Test resopnd_to for clone ---
|
81
|
+
if obj.respond_to?("clone") then
|
82
|
+
puts "uh oh, obj should not respond to clone"
|
83
|
+
end
|
84
|
+
|
85
|
+
# --- Test clone ---
|
86
|
+
except = false
|
87
|
+
begin
|
88
|
+
obj.clone()
|
89
|
+
rescue NameError
|
90
|
+
except = true
|
91
|
+
end
|
92
|
+
if !except then
|
93
|
+
puts "uh oh, I was able to clone obj"
|
94
|
+
end
|
95
|
+
|
96
|
+
# -- Test respond_to for foo ---
|
97
|
+
if !obj.respond_to?("foo") then
|
98
|
+
puts "uh oh, obj should respond to foo!"
|
99
|
+
end
|
100
|
+
|
101
|
+
# --- Test iterators ---
|
102
|
+
puts "You should see the numbers 1, 2, and 3 on separate lines:"
|
103
|
+
obj.each do |i|
|
104
|
+
puts i
|
105
|
+
end
|
106
|
+
|
107
|
+
# --- Test object references ---
|
108
|
+
puts "You should see the number #{obj.i + 1}:"
|
109
|
+
b = obj.bar
|
110
|
+
puts b.i
|
111
|
+
b.release
|
112
|
+
|
113
|
+
# --- Test exceptions
|
114
|
+
puts "You should now see a RuntimeError get thrown:"
|
115
|
+
obj.throw_exception()
|
data/sample/server.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'romp-rpc'
|
2
|
+
|
3
|
+
class Bar
|
4
|
+
attr_reader :i
|
5
|
+
|
6
|
+
def initialize(i, romp)
|
7
|
+
@i = i
|
8
|
+
@romp = romp
|
9
|
+
end
|
10
|
+
|
11
|
+
def release()
|
12
|
+
@romp.delete_reference(self)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Foo < Bar
|
17
|
+
# Initialize @i to 0
|
18
|
+
def initialize(romp)
|
19
|
+
super(0, romp)
|
20
|
+
@romp = romp
|
21
|
+
end
|
22
|
+
|
23
|
+
# Set @i
|
24
|
+
def foo(i)
|
25
|
+
@i = i
|
26
|
+
end
|
27
|
+
|
28
|
+
# Return a reference to a new Bar object with Bar.i = @i + 1
|
29
|
+
def bar()
|
30
|
+
b = Bar.new(@i + 1, @romp)
|
31
|
+
obj = @romp.create_reference(b)
|
32
|
+
return obj
|
33
|
+
end
|
34
|
+
|
35
|
+
# Test iteration
|
36
|
+
def each()
|
37
|
+
yield 1
|
38
|
+
yield 2
|
39
|
+
yield 3
|
40
|
+
end
|
41
|
+
|
42
|
+
def throw_exception2()
|
43
|
+
raise RuntimeError
|
44
|
+
end
|
45
|
+
|
46
|
+
# Test exception
|
47
|
+
def throw_exception()
|
48
|
+
throw_exception2()
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if ARGV.size > 1 or ARGV[0] == "-h" or ARGV[0] == '-H' then
|
53
|
+
puts <<END
|
54
|
+
Usage: #{$0} <url>
|
55
|
+
Example urls:
|
56
|
+
tcpromp://localhost:4242
|
57
|
+
udpromp://localhost:4242
|
58
|
+
unixromp:///tmp/foo
|
59
|
+
END
|
60
|
+
end
|
61
|
+
|
62
|
+
url = ARGV[0] || "tcpromp://localhost:4242"
|
63
|
+
server = ROMP::Server.new(url, false)
|
64
|
+
|
65
|
+
f = Foo.new(server)
|
66
|
+
server.bind(f, "foo")
|
67
|
+
server.thread.join
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: romp-rpc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Paul Brannan
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-06-11 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: |
|
22
|
+
ROMP is the Ruby Object Message Proxy. It is sort of like drb
|
23
|
+
(distributed Ruby) in that it allows a Ruby client program to
|
24
|
+
transparently talk to an object that is sitting on a server.
|
25
|
+
|
26
|
+
email: curlypaul924@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions:
|
30
|
+
- ext/extconf.rb
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.md
|
33
|
+
files:
|
34
|
+
- lib/romp-rpc.rb
|
35
|
+
- ext/romp_helper.c
|
36
|
+
- ext/extconf.rb
|
37
|
+
- sample/client.rb
|
38
|
+
- sample/server.rb
|
39
|
+
- README.md
|
40
|
+
homepage: http://github.com/cout/romp/
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.24
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Ruby Object Message Proxy
|
73
|
+
test_files: []
|
74
|
+
|