RingyDingy 1.4 → 1.5
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +5 -0
- data/Manifest.txt +4 -0
- data/Rakefile +1 -0
- data/lib/ringy_dingy.rb +13 -36
- data/lib/ringy_dingy/cancelable_renewer.rb +28 -0
- data/lib/ringy_dingy/lookup.rb +128 -0
- data/lib/ringy_dingy/ring_server.rb +6 -4
- data/test/test_ring_server.rb +6 -6
- data/test/test_ringy_dingy.rb +0 -2
- data/test/test_ringy_dingy_cancelable_renewer.rb +38 -0
- data/test/test_ringy_dingy_lookup.rb +57 -0
- metadata +11 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 49a70aaeac4ce0f4d9e3bddb018da38372ca5d0d
|
|
4
|
+
data.tar.gz: 373f70d3c2e3bb548fdf5cfd81e32f77e40aeb32
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 50ce6ae837b4dcde616b9c9d8dcf5376c01527a2a6300c9e6a7b2fa6b58e5787b4bbdf1aaa492fa5eec92d4f8562804b3af098dc7c8ff42d1470df7f323571a8
|
|
7
|
+
data.tar.gz: eaec7dfff951f1b88bcfa18445a5427394d130a3e7a12e314004426cf1c28090602a74016c73fc7473c65ee8ac3d10ce831a0c2ccb19533abfc95660e0aafeb0
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data.tar.gz.sig
CHANGED
|
Binary file
|
data/History.rdoc
CHANGED
data/Manifest.txt
CHANGED
|
@@ -5,6 +5,10 @@ README.rdoc
|
|
|
5
5
|
Rakefile
|
|
6
6
|
bin/ring_server
|
|
7
7
|
lib/ringy_dingy.rb
|
|
8
|
+
lib/ringy_dingy/cancelable_renewer.rb
|
|
9
|
+
lib/ringy_dingy/lookup.rb
|
|
8
10
|
lib/ringy_dingy/ring_server.rb
|
|
9
11
|
test/test_ring_server.rb
|
|
10
12
|
test/test_ringy_dingy.rb
|
|
13
|
+
test/test_ringy_dingy_cancelable_renewer.rb
|
|
14
|
+
test/test_ringy_dingy_lookup.rb
|
data/Rakefile
CHANGED
data/lib/ringy_dingy.rb
CHANGED
|
@@ -2,8 +2,6 @@ require 'English'
|
|
|
2
2
|
require 'drb'
|
|
3
3
|
require 'rinda/ring'
|
|
4
4
|
|
|
5
|
-
$TESTING = false unless defined? $TESTING
|
|
6
|
-
|
|
7
5
|
##
|
|
8
6
|
# RingyDingy registers a DRb service with a Rinda::RingServer and re-registers
|
|
9
7
|
# the service if communication with the Rinda::RingServer is ever lost.
|
|
@@ -24,7 +22,7 @@ class RingyDingy
|
|
|
24
22
|
##
|
|
25
23
|
# The version of RingyDingy you are using
|
|
26
24
|
|
|
27
|
-
VERSION = '1.
|
|
25
|
+
VERSION = '1.5'
|
|
28
26
|
|
|
29
27
|
##
|
|
30
28
|
# Interval to check the RingServer for our registration information.
|
|
@@ -47,10 +45,8 @@ class RingyDingy
|
|
|
47
45
|
|
|
48
46
|
attr_reader :thread
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
attr_writer :ring_server, :thread # :nodoc:
|
|
53
|
-
end
|
|
48
|
+
attr_accessor :ring_finger, :renewer # :nodoc:
|
|
49
|
+
attr_writer :ring_server, :thread # :nodoc:
|
|
54
50
|
|
|
55
51
|
##
|
|
56
52
|
# Lists of hosts to search for ring servers. By default includes the subnet
|
|
@@ -63,32 +59,7 @@ class RingyDingy
|
|
|
63
59
|
# Ring servers are discovered via the +broadcast_list+.
|
|
64
60
|
|
|
65
61
|
def self.find service_name, broadcast_list = BROADCAST_LIST
|
|
66
|
-
|
|
67
|
-
rf = Rinda::RingFinger.new broadcast_list
|
|
68
|
-
|
|
69
|
-
services = {}
|
|
70
|
-
|
|
71
|
-
rf.lookup_ring do |ts|
|
|
72
|
-
services[ts.__drburi] = ts.read_all [:name, nil, DRbObject, nil]
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
services.each do |_, tuples|
|
|
76
|
-
tuples.each do |_, found_service_name, service|
|
|
77
|
-
begin
|
|
78
|
-
next unless found_service_name == service_name
|
|
79
|
-
|
|
80
|
-
service.method_missing :object_id # ping service for liveness
|
|
81
|
-
|
|
82
|
-
return service
|
|
83
|
-
rescue DRb::DRbConnError
|
|
84
|
-
next
|
|
85
|
-
rescue NoMethodError
|
|
86
|
-
next
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
raise "unable to find service #{service_name.inspect}"
|
|
62
|
+
RingyDingy::Lookup.new(broadcast_list).find service_name
|
|
92
63
|
end
|
|
93
64
|
|
|
94
65
|
##
|
|
@@ -116,9 +87,13 @@ class RingyDingy
|
|
|
116
87
|
# Registers this service with the primary Rinda::RingServer.
|
|
117
88
|
|
|
118
89
|
def register
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
90
|
+
reference = DRb::DRbObject.new(@object)
|
|
91
|
+
|
|
92
|
+
tuple = [:name, @service, reference, @identifier]
|
|
93
|
+
|
|
94
|
+
ring_server.write tuple, @renewer
|
|
95
|
+
|
|
96
|
+
nil
|
|
122
97
|
end
|
|
123
98
|
|
|
124
99
|
##
|
|
@@ -202,3 +177,5 @@ class RingyDingy
|
|
|
202
177
|
|
|
203
178
|
end
|
|
204
179
|
|
|
180
|
+
require 'ringy_dingy/cancelable_renewer'
|
|
181
|
+
require 'ringy_dingy/lookup'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
##
|
|
2
|
+
# This renewer can be canceled to shut down a TupleSpace operation.
|
|
3
|
+
|
|
4
|
+
class RingyDingy::CancelableRenewer
|
|
5
|
+
include DRbUndumped
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# Creates a new renewer that will be checked every +sec+ for cancellation by
|
|
9
|
+
# the TupleSpace
|
|
10
|
+
|
|
11
|
+
def initialize seconds = 1
|
|
12
|
+
@renew = true
|
|
13
|
+
@seconds = seconds
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# Cancels the renewer
|
|
18
|
+
|
|
19
|
+
def cancel
|
|
20
|
+
@renew = false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def renew # :nodoc:
|
|
24
|
+
@renew ? @seconds : true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require 'rinda/tuplespace'
|
|
2
|
+
|
|
3
|
+
class RingyDingy::Lookup
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
# The list of addresses where ring servers will be searched-for
|
|
7
|
+
|
|
8
|
+
attr_reader :broadcast_list
|
|
9
|
+
|
|
10
|
+
##
|
|
11
|
+
# The Rinda::RingFinger used to search for ring servers
|
|
12
|
+
|
|
13
|
+
attr_reader :ring_finger
|
|
14
|
+
|
|
15
|
+
##
|
|
16
|
+
# Lists of hosts to search for ring servers. By default includes the subnet
|
|
17
|
+
# broadcast address and localhost.
|
|
18
|
+
|
|
19
|
+
def initialize broadcast_list = RingyDingy::BROADCAST_LIST
|
|
20
|
+
DRb.start_service unless DRb.primary_server
|
|
21
|
+
|
|
22
|
+
@broadcast_list = broadcast_list
|
|
23
|
+
|
|
24
|
+
@ring_finger = Rinda::RingFinger.new @broadcast_list
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
##
|
|
28
|
+
# Yields each tuple space found in the broadcast list
|
|
29
|
+
|
|
30
|
+
def each_tuple_space
|
|
31
|
+
return enum_for __method__ unless block_given?
|
|
32
|
+
|
|
33
|
+
@ring_finger.lookup_ring do |tuple_space|
|
|
34
|
+
yield tuple_space
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
# Continually checks for tuple spaces and yields found tuple spaces.
|
|
40
|
+
#
|
|
41
|
+
# Returns a Thread that must be killed to shut down lookup:
|
|
42
|
+
#
|
|
43
|
+
# def my_method
|
|
44
|
+
# thread = enumerate_tuple_spaces do |tuple_space|
|
|
45
|
+
# # ...
|
|
46
|
+
# end
|
|
47
|
+
# ensure
|
|
48
|
+
# thread.kill
|
|
49
|
+
# end
|
|
50
|
+
|
|
51
|
+
def enumerate_tuple_spaces
|
|
52
|
+
Thread.start do
|
|
53
|
+
spaces = {}
|
|
54
|
+
|
|
55
|
+
loop do
|
|
56
|
+
@ring_finger.lookup_ring do |tuple_space|
|
|
57
|
+
yield tuple_space
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
##
|
|
64
|
+
# Finds the first live service matching +service_name+ on any ring server.
|
|
65
|
+
# Ring servers are discovered via the +broadcast_list+.
|
|
66
|
+
|
|
67
|
+
def find service_name
|
|
68
|
+
found = nil
|
|
69
|
+
|
|
70
|
+
each_tuple_space.any? do |ts|
|
|
71
|
+
tuples = ts.read_all [:name, nil, DRbObject, nil]
|
|
72
|
+
|
|
73
|
+
found = tuples.find do |_, found_service_name, service, _|
|
|
74
|
+
begin
|
|
75
|
+
next unless found_service_name == service_name
|
|
76
|
+
|
|
77
|
+
if DRbObject === service then
|
|
78
|
+
service.method_missing :object_id # ping service for liveness
|
|
79
|
+
else
|
|
80
|
+
service
|
|
81
|
+
end
|
|
82
|
+
rescue DRb::DRbConnError
|
|
83
|
+
next
|
|
84
|
+
rescue NoMethodError
|
|
85
|
+
next
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
raise "unable to find service #{service_name.inspect}" unless found
|
|
91
|
+
|
|
92
|
+
found[2]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
##
|
|
96
|
+
# Waits until +service_name+ appears on any ring server. Returns the first
|
|
97
|
+
# service found with that name.
|
|
98
|
+
#
|
|
99
|
+
# If you launch a service via another process use this to wait until the
|
|
100
|
+
# service comes up.
|
|
101
|
+
|
|
102
|
+
def wait_for service_name
|
|
103
|
+
queue = Queue.new
|
|
104
|
+
renewer = nil
|
|
105
|
+
|
|
106
|
+
thread = enumerate_tuple_spaces do |tuple_space|
|
|
107
|
+
renewer.cancel if renewer
|
|
108
|
+
renewer = RingyDingy::CancelableRenewer.new
|
|
109
|
+
|
|
110
|
+
Thread.new do
|
|
111
|
+
template = [:name, service_name, DRbObject, nil]
|
|
112
|
+
begin
|
|
113
|
+
tuple = tuple_space.read template, renewer
|
|
114
|
+
|
|
115
|
+
queue.push tuple[2]
|
|
116
|
+
rescue DRb::DRbConnError => e
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
queue.pop
|
|
122
|
+
ensure
|
|
123
|
+
renewer.cancel
|
|
124
|
+
thread.kill if thread
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
end
|
|
128
|
+
|
|
@@ -93,11 +93,13 @@ class RingyDingy::RingServer
|
|
|
93
93
|
list_services.each do |ring_server, services|
|
|
94
94
|
out << "Services on #{ring_server}"
|
|
95
95
|
|
|
96
|
-
values = services.sort_by
|
|
96
|
+
values = services.sort_by do |_, name, service,|
|
|
97
|
+
[name.to_s, service.__drburi, -service.__drbref]
|
|
98
|
+
end
|
|
97
99
|
|
|
98
|
-
values.each do |
|
|
99
|
-
out << "
|
|
100
|
-
[
|
|
100
|
+
values.each do |_, name, service, description|
|
|
101
|
+
out << " %p, %p\n URI: %s ref: %d" %
|
|
102
|
+
[name, description, service.__drburi, service.__drbref]
|
|
101
103
|
out << nil
|
|
102
104
|
end
|
|
103
105
|
end
|
data/test/test_ring_server.rb
CHANGED
|
@@ -103,15 +103,15 @@ class TestRingServer < MiniTest::Unit::TestCase
|
|
|
103
103
|
|
|
104
104
|
expected = <<-EOF
|
|
105
105
|
Services on druby://localhost:10000
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
:RingyDingy, "localhost_9607_obj0"
|
|
107
|
+
URI: druby://localhost:10001 ref: #{OBJ0.object_id}
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
:RingyDingy, "localhost_9607_obj1"
|
|
110
|
+
URI: druby://localhost:10001 ref: #{OBJ1.object_id}
|
|
111
111
|
|
|
112
112
|
Services on druby://localhost:10002
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
:RingyDingy, "localhost_9607_obj2"
|
|
114
|
+
URI: druby://localhost:10003 ref: #{OBJ2.object_id}
|
|
115
115
|
EOF
|
|
116
116
|
|
|
117
117
|
assert_equal expected, out
|
data/test/test_ringy_dingy.rb
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
|
|
3
|
+
class TestRingyDingyCancelableRenewer < MiniTest::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
super
|
|
7
|
+
|
|
8
|
+
@renewer = RingyDingy::CancelableRenewer.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_cancel
|
|
12
|
+
@renewer.cancel
|
|
13
|
+
|
|
14
|
+
assert_equal true, @renewer.renew
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_marshal_dump
|
|
18
|
+
assert_raises TypeError do
|
|
19
|
+
Marshal.dump @renewer
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_renew
|
|
24
|
+
assert_equal 1, @renewer.renew
|
|
25
|
+
|
|
26
|
+
@renewer.cancel
|
|
27
|
+
|
|
28
|
+
assert_equal true, @renewer.renew
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_renew_seconds
|
|
32
|
+
@renewer = RingyDingy::CancelableRenewer.new 2
|
|
33
|
+
|
|
34
|
+
assert_equal 2, @renewer.renew
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require 'ringy_dingy'
|
|
3
|
+
|
|
4
|
+
class TestRingyDingyLookup < MiniTest::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
super
|
|
8
|
+
|
|
9
|
+
@lookup = RingyDingy::Lookup.new []
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_enumerate_tuple_spaces
|
|
13
|
+
stub_ring_finger
|
|
14
|
+
|
|
15
|
+
items = []
|
|
16
|
+
|
|
17
|
+
thread = @lookup.enumerate_tuple_spaces do |ts|
|
|
18
|
+
items << ts
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Thread.pass while items.empty?
|
|
22
|
+
|
|
23
|
+
refute_empty items
|
|
24
|
+
ensure
|
|
25
|
+
thread.kill if thread
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_find
|
|
29
|
+
stub_ring_finger
|
|
30
|
+
|
|
31
|
+
found = @lookup.find 'service'
|
|
32
|
+
|
|
33
|
+
assert_kind_of Object, found
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_wait_for
|
|
37
|
+
stub_ring_finger
|
|
38
|
+
|
|
39
|
+
found = @lookup.wait_for 'service'
|
|
40
|
+
|
|
41
|
+
assert_kind_of Object, found
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def stub_ring_finger
|
|
45
|
+
def (@lookup.ring_finger).lookup_ring
|
|
46
|
+
ts = Rinda::TupleSpace.new
|
|
47
|
+
yield DRb::DRbObject.new ts
|
|
48
|
+
|
|
49
|
+
ro = DRbObject.new Object.new
|
|
50
|
+
ts = Rinda::TupleSpace.new
|
|
51
|
+
ts.write [:name, 'service', ro, 'the service']
|
|
52
|
+
yield DRb::DRbObject.new ts
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: RingyDingy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.5'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Hodel
|
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
|
30
30
|
KDyY1VIazVgoC8XvR4h/95/iScPiuglzA+DBG1hip1xScAtw05BrXyUNrc9CEMYU
|
|
31
31
|
wgF94UVoHRp6ywo8I7NP3HcwFQDFNEZPNGXsng==
|
|
32
32
|
-----END CERTIFICATE-----
|
|
33
|
-
date: 2013-03
|
|
33
|
+
date: 2013-05-03 00:00:00.000000000 Z
|
|
34
34
|
dependencies:
|
|
35
35
|
- !ruby/object:Gem::Dependency
|
|
36
36
|
name: minitest
|
|
@@ -38,14 +38,14 @@ dependencies:
|
|
|
38
38
|
requirements:
|
|
39
39
|
- - ~>
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '4.
|
|
41
|
+
version: '4.6'
|
|
42
42
|
type: :development
|
|
43
43
|
prerelease: false
|
|
44
44
|
version_requirements: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
|
46
46
|
- - ~>
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: '4.
|
|
48
|
+
version: '4.6'
|
|
49
49
|
- !ruby/object:Gem::Dependency
|
|
50
50
|
name: rdoc
|
|
51
51
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -119,9 +119,13 @@ files:
|
|
|
119
119
|
- Rakefile
|
|
120
120
|
- bin/ring_server
|
|
121
121
|
- lib/ringy_dingy.rb
|
|
122
|
+
- lib/ringy_dingy/cancelable_renewer.rb
|
|
123
|
+
- lib/ringy_dingy/lookup.rb
|
|
122
124
|
- lib/ringy_dingy/ring_server.rb
|
|
123
125
|
- test/test_ring_server.rb
|
|
124
126
|
- test/test_ringy_dingy.rb
|
|
127
|
+
- test/test_ringy_dingy_cancelable_renewer.rb
|
|
128
|
+
- test/test_ringy_dingy_lookup.rb
|
|
125
129
|
- .gemtest
|
|
126
130
|
homepage: https://github.com/drbrain/RingyDingy
|
|
127
131
|
licenses:
|
|
@@ -145,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
145
149
|
version: '0'
|
|
146
150
|
requirements: []
|
|
147
151
|
rubyforge_project: ringydingy
|
|
148
|
-
rubygems_version: 2.0.
|
|
152
|
+
rubygems_version: 2.0.3
|
|
149
153
|
signing_key:
|
|
150
154
|
specification_version: 4
|
|
151
155
|
summary: RingyDingy is a little boat that keeps your DRb service afloat! RingyDingy
|
|
@@ -153,3 +157,5 @@ summary: RingyDingy is a little boat that keeps your DRb service afloat! RingyDi
|
|
|
153
157
|
test_files:
|
|
154
158
|
- test/test_ring_server.rb
|
|
155
159
|
- test/test_ringy_dingy.rb
|
|
160
|
+
- test/test_ringy_dingy_cancelable_renewer.rb
|
|
161
|
+
- test/test_ringy_dingy_lookup.rb
|
metadata.gz.sig
CHANGED
|
Binary file
|