rubarb 0.2.0 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +89 -0
- data/examples/client.rb +3 -1
- data/examples/server.rb +1 -1
- data/lib/rubarb/connection.rb +61 -24
- data/lib/rubarb/incoming_connection.rb +9 -1
- data/lib/rubarb/outgoing_connection.rb +15 -0
- data/lib/rubarb/server.rb +21 -4
- data/spec/rubarb/connection_failure_spec.rb +0 -8
- data/spec/rubarb/connection_spec.rb +15 -10
- data/spec/rubarb/incoming_connection_spec.rb +6 -0
- data/spec/rubarb/integration_spec.rb +67 -8
- data/spec/rubarb/outgoing_connection_spec.rb +4 -0
- data/spec/rubarb/server_failure_spec.rb +124 -122
- data/spec/rubarb/server_spec.rb +4 -10
- data/spec/spec_helper.rb +28 -7
- metadata +79 -102
- data/.gitignore +0 -7
- data/README +0 -77
- data/Rakefile +0 -51
- data/VERSION +0 -1
data/spec/rubarb/server_spec.rb
CHANGED
@@ -62,12 +62,8 @@ end
|
|
62
62
|
|
63
63
|
describe Rubarb::Server do
|
64
64
|
|
65
|
-
before(:each) do
|
66
|
-
@reactor_thread = nil
|
67
|
-
end
|
68
|
-
|
69
65
|
after(:each) do
|
70
|
-
|
66
|
+
sync_stop(@server)
|
71
67
|
end
|
72
68
|
|
73
69
|
it "has an instance of Rubarb::Id" do
|
@@ -96,15 +92,15 @@ describe Rubarb::Server do
|
|
96
92
|
end
|
97
93
|
|
98
94
|
def connect
|
99
|
-
@reactor_thread = start_reactor
|
100
95
|
connected = false
|
101
96
|
@server = Rubarb::Server.new("127.0.0.1", 9441, mock("server"))
|
102
97
|
@connection = Rubarb::Connection.new("127.0.0.1", 9441, mock("client"))
|
103
98
|
EM.schedule do
|
104
99
|
@server.start { |client| @client = client }
|
105
|
-
@connection.start { connected = true }
|
100
|
+
EM.next_tick {@connection.start { connected = true } }
|
106
101
|
end
|
107
|
-
wait_for { connected }
|
102
|
+
wait_for { connected && @client}
|
103
|
+
connected.should == true
|
108
104
|
end
|
109
105
|
|
110
106
|
it "sets instance of Rubarb::Id to each connection for connection ids" do
|
@@ -137,7 +133,6 @@ describe Rubarb::Server do
|
|
137
133
|
end
|
138
134
|
|
139
135
|
it "makes two overlapping calls" do
|
140
|
-
@reactor_thread = start_reactor
|
141
136
|
connected = false
|
142
137
|
|
143
138
|
@server = Rubarb::Server.new("127.0.0.1", 9441, TestApi.new)
|
@@ -173,7 +168,6 @@ describe Rubarb::Server do
|
|
173
168
|
it "should catch exceptions in starting server" do
|
174
169
|
EventMachine.stub!(:start_server).and_raise("EMReactor Exception")
|
175
170
|
|
176
|
-
@reactor_thread = start_reactor
|
177
171
|
done = false
|
178
172
|
|
179
173
|
@server = Rubarb::Server.new("127.0.0.1", 9441, TestApi.new)
|
data/spec/spec_helper.rb
CHANGED
@@ -5,21 +5,28 @@ require 'timeout'
|
|
5
5
|
require 'eventmachine'
|
6
6
|
|
7
7
|
def start_reactor
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
main_thread = Thread.current
|
9
|
+
em_thread = Thread.new do
|
10
|
+
EventMachine::run do
|
11
|
+
main_thread.wakeup
|
12
12
|
end
|
13
13
|
end
|
14
|
-
sleep
|
15
|
-
|
14
|
+
while !(em_thread.alive? && em_thread.status != "sleep")
|
15
|
+
sleep(0.2)
|
16
|
+
end
|
17
|
+
return em_thread
|
16
18
|
end
|
17
19
|
|
20
|
+
|
18
21
|
def stop_reactor(reactor)
|
19
|
-
EM::
|
22
|
+
return unless EM::reactor_running?
|
23
|
+
EM.stop
|
20
24
|
reactor.join
|
25
|
+
rescue Exception => e
|
26
|
+
|
21
27
|
end
|
22
28
|
|
29
|
+
|
23
30
|
def wait_for
|
24
31
|
Timeout::timeout(5) do
|
25
32
|
while !yield
|
@@ -29,4 +36,18 @@ def wait_for
|
|
29
36
|
rescue Timeout::Error => e
|
30
37
|
end
|
31
38
|
|
39
|
+
def sync_stop(server)
|
40
|
+
return unless server
|
41
|
+
stopped = false
|
42
|
+
server.stop { stopped = true }
|
43
|
+
wait_for { stopped }
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
Spec::Runner.configure do |config|
|
48
|
+
config.before(:suite) {$reactor_thread = start_reactor}
|
49
|
+
config.after(:suite) {stop_reactor($reactor_thread)}
|
50
|
+
end
|
51
|
+
|
52
|
+
|
32
53
|
#$DEBUG = true
|
metadata
CHANGED
@@ -1,55 +1,52 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubarb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
version: 0.2.
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 11
|
9
|
+
version: 0.2.11
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
|
-
- doug bradbury
|
12
|
+
- doug bradbury
|
14
13
|
autorequire:
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-02-09 00:00:00 -06:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
type: :runtime
|
52
|
-
version_requirements: *id002
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
version: 1.3.0
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: eventmachine
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 0
|
44
|
+
- 0
|
45
|
+
- beta
|
46
|
+
- 2
|
47
|
+
version: 1.0.0.beta.2
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
53
50
|
description: |-
|
54
51
|
This library uses two socket connections between a client and a server. One is used for request / replies from the
|
55
52
|
client to the server. The other is used for remote calls made from the server to the client.
|
@@ -63,84 +60,64 @@ executables: []
|
|
63
60
|
extensions: []
|
64
61
|
|
65
62
|
extra_rdoc_files:
|
66
|
-
- README
|
63
|
+
- README.md
|
67
64
|
files:
|
68
|
-
- .
|
69
|
-
-
|
70
|
-
-
|
71
|
-
-
|
72
|
-
-
|
73
|
-
-
|
74
|
-
- lib/
|
75
|
-
- lib/rubarb.rb
|
76
|
-
- lib/rubarb/
|
77
|
-
- lib/rubarb/
|
78
|
-
- lib/rubarb/
|
79
|
-
- lib/rubarb/
|
80
|
-
- lib/rubarb/
|
81
|
-
- lib/rubarb/
|
82
|
-
-
|
83
|
-
- lib/rubarb/insecure_method_call_error.rb
|
84
|
-
- lib/rubarb/outgoing_connection.rb
|
85
|
-
- lib/rubarb/remote_call.rb
|
86
|
-
- lib/rubarb/responder.rb
|
87
|
-
- lib/rubarb/server.rb
|
88
|
-
- spec/rubarb/connection_failure_spec.rb
|
89
|
-
- spec/rubarb/connection_spec.rb
|
90
|
-
- spec/rubarb/id_spec.rb
|
91
|
-
- spec/rubarb/incoming_connection_spec.rb
|
92
|
-
- spec/rubarb/integration_spec.rb
|
93
|
-
- spec/rubarb/outgoing_connection_spec.rb
|
94
|
-
- spec/rubarb/remote_call_spec.rb
|
95
|
-
- spec/rubarb/responder_spec.rb
|
96
|
-
- spec/rubarb/server_failure_spec.rb
|
97
|
-
- spec/rubarb/server_spec.rb
|
98
|
-
- spec/spec_helper.rb
|
65
|
+
- lib/dkbrpc.rb
|
66
|
+
- lib/rubarb.rb
|
67
|
+
- lib/rubarb/connection.rb
|
68
|
+
- lib/rubarb/connection_error.rb
|
69
|
+
- lib/rubarb/connection_id.rb
|
70
|
+
- lib/rubarb/default.rb
|
71
|
+
- lib/rubarb/fast_message_protocol.rb
|
72
|
+
- lib/rubarb/id.rb
|
73
|
+
- lib/rubarb/incoming_connection.rb
|
74
|
+
- lib/rubarb/insecure_method_call_error.rb
|
75
|
+
- lib/rubarb/outgoing_connection.rb
|
76
|
+
- lib/rubarb/remote_call.rb
|
77
|
+
- lib/rubarb/responder.rb
|
78
|
+
- lib/rubarb/server.rb
|
79
|
+
- README.md
|
99
80
|
has_rdoc: true
|
100
81
|
homepage: http://github.com/dougbradbury/rubarb
|
101
82
|
licenses: []
|
102
83
|
|
103
84
|
post_install_message:
|
104
|
-
rdoc_options:
|
105
|
-
|
85
|
+
rdoc_options: []
|
86
|
+
|
106
87
|
require_paths:
|
107
|
-
- lib
|
88
|
+
- lib
|
108
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
90
|
requirements:
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
version: "0"
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
117
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
-
none: false
|
119
97
|
requirements:
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
version: "0"
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
126
103
|
requirements: []
|
127
104
|
|
128
105
|
rubyforge_project:
|
129
|
-
rubygems_version: 1.3.
|
106
|
+
rubygems_version: 1.3.6
|
130
107
|
signing_key:
|
131
108
|
specification_version: 3
|
132
109
|
summary: A Bidirectional Event Machine Based Remote Procedure Call Library for Ruby
|
133
110
|
test_files:
|
134
|
-
-
|
135
|
-
-
|
136
|
-
- spec/rubarb/
|
137
|
-
- spec/rubarb/
|
138
|
-
- spec/rubarb/
|
139
|
-
- spec/rubarb/
|
140
|
-
- spec/rubarb/
|
141
|
-
- spec/rubarb/
|
142
|
-
- spec/rubarb/
|
143
|
-
- spec/rubarb/
|
144
|
-
- spec/
|
145
|
-
-
|
146
|
-
-
|
111
|
+
- examples/client.rb
|
112
|
+
- examples/server.rb
|
113
|
+
- spec/rubarb/connection_failure_spec.rb
|
114
|
+
- spec/rubarb/connection_spec.rb
|
115
|
+
- spec/rubarb/id_spec.rb
|
116
|
+
- spec/rubarb/incoming_connection_spec.rb
|
117
|
+
- spec/rubarb/integration_spec.rb
|
118
|
+
- spec/rubarb/outgoing_connection_spec.rb
|
119
|
+
- spec/rubarb/remote_call_spec.rb
|
120
|
+
- spec/rubarb/responder_spec.rb
|
121
|
+
- spec/rubarb/server_failure_spec.rb
|
122
|
+
- spec/rubarb/server_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
data/.gitignore
DELETED
data/README
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
rubaRb
|
2
|
-
A Bidirectional Event Machine Based Remote Procedure Call Library for Ruby
|
3
|
-
|
4
|
-
This library uses two socket connections between a client and a server.
|
5
|
-
One is used for request / replies from the client to the server.
|
6
|
-
The other is used for remote calls made from the server to the client.
|
7
|
-
|
8
|
-
Each end publishes a single object on which methods can be called by the remote end.
|
9
|
-
All calls to the remote objects are asyncronous. Do not make any blocking calls in
|
10
|
-
the published object. Responses are return by calling the "reply method on the responder object.
|
11
|
-
|
12
|
-
Server and Connection object may be created and started outside of EM::run,
|
13
|
-
but the Eventmachine reactor must be started somewhere in your application
|
14
|
-
|
15
|
-
################################# Server Example #####################################################################
|
16
|
-
|
17
|
-
class ServerApi
|
18
|
-
def time(responder)
|
19
|
-
puts "Server received time request"
|
20
|
-
responder.reply(Time.now)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
EM.run do
|
25
|
-
server = Rubarb::Server.new("127.0.0.1", 9441, ServerApi.new)
|
26
|
-
|
27
|
-
connections = {}
|
28
|
-
|
29
|
-
server.start do |client|
|
30
|
-
puts "Connection Made: #{client}"
|
31
|
-
client.name do |name|
|
32
|
-
connections[name] = client
|
33
|
-
client.errback do
|
34
|
-
puts "Connection Lost: #{name}"
|
35
|
-
connections.delete(name)
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
EventMachine.add_periodic_timer(1) { puts "Connections: #{connections.keys.inspect}" }
|
43
|
-
|
44
|
-
end
|
45
|
-
######################################################################################################################
|
46
|
-
|
47
|
-
|
48
|
-
################################# Client Example #####################################################################
|
49
|
-
class ClientApi
|
50
|
-
def initialize(name)
|
51
|
-
@name = name
|
52
|
-
end
|
53
|
-
def name(responder)
|
54
|
-
responder.reply(@name)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
EM::run do
|
59
|
-
connection = Rubarb::Connection.new("127.0.0.1", 9441, ClientApi.new(ARGV[0]))
|
60
|
-
connection.errback do |error|
|
61
|
-
puts ("Connection Error: #{error}")
|
62
|
-
end
|
63
|
-
|
64
|
-
connection.start do
|
65
|
-
connection.time do |response|
|
66
|
-
puts "Server Said it is: #{response.strftime("%D")}"
|
67
|
-
end
|
68
|
-
|
69
|
-
EventMachine.add_timer(20) do
|
70
|
-
puts "stopping"
|
71
|
-
connection.stop
|
72
|
-
EM::stop
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
######################################################################################################################
|
data/Rakefile
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "rubarb"
|
8
|
-
gem.summary = %Q{A Bidirectional Event Machine Based Remote Procedure Call Library for Ruby}
|
9
|
-
gem.description = %Q{This library uses two socket connections between a client and a server. One is used for request / replies from the
|
10
|
-
client to the server. The other is used for remote calls made from the server to the client.
|
11
|
-
|
12
|
-
Each end publishes a single object on which
|
13
|
-
methods can be called by the remote end. All calls to the remote objects are asyncronous. Do not make any blocking
|
14
|
-
calls in the published object. Responses are return by calling the "reply method on the responder object.}
|
15
|
-
|
16
|
-
gem.email = "doug@8thlight.com"
|
17
|
-
gem.homepage = "http://github.com/dougbradbury/rubarb"
|
18
|
-
gem.authors = ["doug bradbury"]
|
19
|
-
gem.add_development_dependency "rspec", ">= 1.3.0"
|
20
|
-
gem.add_dependency "eventmachine", ">= 0.12.11"
|
21
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
22
|
-
end
|
23
|
-
rescue LoadError
|
24
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
25
|
-
end
|
26
|
-
|
27
|
-
require 'spec/rake/spectask'
|
28
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
29
|
-
spec.libs << 'lib' << 'spec'
|
30
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
31
|
-
end
|
32
|
-
|
33
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
34
|
-
spec.libs << 'lib' << 'spec'
|
35
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
-
spec.rcov = true
|
37
|
-
end
|
38
|
-
|
39
|
-
task :spec => :check_dependencies
|
40
|
-
|
41
|
-
task :default => :spec
|
42
|
-
|
43
|
-
require 'rake/rdoctask'
|
44
|
-
Rake::RDocTask.new do |rdoc|
|
45
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
-
|
47
|
-
rdoc.rdoc_dir = 'rdoc'
|
48
|
-
rdoc.title = "rubarb-gem #{version}"
|
49
|
-
rdoc.rdoc_files.include('README*')
|
50
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
-
end
|