archipelago 0.2.6 → 0.2.7
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 +1 -1
- data/lib/archipelago/client.rb +7 -7
- data/lib/archipelago/current.rb +35 -0
- data/lib/archipelago/disco.rb +10 -12
- data/lib/archipelago/hashish.rb +1 -1
- data/tests/current_test.rb +35 -0
- metadata +21 -4
data/README
CHANGED
@@ -4,7 +4,7 @@ It consists of several different parts, that can be used standalone or in conjun
|
|
4
4
|
|
5
5
|
== Dependencies:
|
6
6
|
Archipelago::Hashish::BerkeleyHashishProvider:: ruby bdb: http://moulon.inra.fr/ruby/bdb.html
|
7
|
-
Archipelago::Client::Base::
|
7
|
+
Archipelago::Client::Base:: archipelago_rbtree, a patched and gemified version of the original at http://www.geocities.co.jp/SiliconValley-PaloAlto/3388/rbtree/README.html
|
8
8
|
|
9
9
|
== Sub packages:
|
10
10
|
Archipelago::Disco:: A UDP multicast discovery service useful to find services in your network with a minimum of configuration.
|
data/lib/archipelago/client.rb
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
17
|
|
18
18
|
require 'archipelago/disco'
|
19
|
-
require '
|
19
|
+
require 'archipelago_rbtree'
|
20
20
|
|
21
21
|
module Archipelago
|
22
22
|
|
@@ -57,9 +57,8 @@ module Archipelago
|
|
57
57
|
@initial_lookup_timeout = options[:initial_lookup_timeout] || INITIAL_LOOKUP_TIMEOUT
|
58
58
|
@services = {}
|
59
59
|
@service_descriptions.each do |name, description|
|
60
|
-
|
61
|
-
|
62
|
-
@services[name] = t
|
60
|
+
@services[name] = Archipelago::Disco::ServiceLocker.new
|
61
|
+
@services[name].convert_to_tree!
|
63
62
|
end
|
64
63
|
|
65
64
|
start_service_updater
|
@@ -118,9 +117,10 @@ module Archipelago
|
|
118
117
|
# more than on average once every MAXIMUM_SERVICE_UPDATE_INTERVAL, so that MAY make it worthwhile to do
|
119
118
|
# the RBTree song and dance in here. Hopefully.
|
120
119
|
#
|
121
|
-
|
122
|
-
|
123
|
-
|
120
|
+
new_services = @jockey.lookup(Archipelago::Disco::Query.new(description), timeout)
|
121
|
+
new_services.convert_to_tree!
|
122
|
+
new_services.validate! if validate
|
123
|
+
@services[name] = new_services
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
data/lib/archipelago/current.rb
CHANGED
@@ -33,6 +33,41 @@ module Archipelago
|
|
33
33
|
|
34
34
|
module Current
|
35
35
|
|
36
|
+
class Queue
|
37
|
+
def initialize
|
38
|
+
@lock = Monitor.new
|
39
|
+
@flag = MonitorMixin::ConditionVariable.new(@lock)
|
40
|
+
@ary = []
|
41
|
+
end
|
42
|
+
def <<(e)
|
43
|
+
@lock.synchronize do
|
44
|
+
@ary << e
|
45
|
+
@flag.broadcast
|
46
|
+
end
|
47
|
+
end
|
48
|
+
def empty?(wait = false)
|
49
|
+
@lock.synchronize do
|
50
|
+
if wait
|
51
|
+
@flag.wait_until do
|
52
|
+
@ary.empty?
|
53
|
+
end unless @ary.empty?
|
54
|
+
return @ary.empty?
|
55
|
+
else
|
56
|
+
return @ary.empty?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
def shift
|
61
|
+
@lock.synchronize do
|
62
|
+
@flag.wait_while do
|
63
|
+
@ary.empty?
|
64
|
+
end if @ary.empty?
|
65
|
+
@flag.broadcast
|
66
|
+
return @ary.shift
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
36
71
|
#
|
37
72
|
# Adds a few threaded methods to the normal ruby collections.
|
38
73
|
#
|
data/lib/archipelago/disco.rb
CHANGED
@@ -25,6 +25,7 @@ require 'drb'
|
|
25
25
|
require 'set'
|
26
26
|
require 'digest/sha1'
|
27
27
|
require 'forwardable'
|
28
|
+
require 'archipelago_rbtree'
|
28
29
|
|
29
30
|
module Archipelago
|
30
31
|
|
@@ -485,8 +486,8 @@ module Archipelago
|
|
485
486
|
@local_services = ServiceLocker.new(:jockey => self)
|
486
487
|
@subscribed_services = Set.new
|
487
488
|
|
488
|
-
@incoming = Queue.new
|
489
|
-
@outgoing = Queue.new
|
489
|
+
@incoming = Archipelago::Current::Queue.new
|
490
|
+
@outgoing = Archipelago::Current::Queue.new
|
490
491
|
|
491
492
|
@new_service_semaphore = MonitorMixin::ConditionVariable.new(Archipelago::Current::Lock.new)
|
492
493
|
@service_change_subscribers_by_event_type = {:found => {}, :lost => {}}
|
@@ -575,7 +576,7 @@ module Archipelago
|
|
575
576
|
end
|
576
577
|
|
577
578
|
#
|
578
|
-
# Stops all the threads and
|
579
|
+
# Stops all the threads and closes all sockets in this instance.
|
579
580
|
#
|
580
581
|
def stop!
|
581
582
|
if @valid
|
@@ -586,16 +587,13 @@ module Archipelago
|
|
586
587
|
|
587
588
|
@listener_thread.kill
|
588
589
|
@unilistener_thread.kill
|
589
|
-
|
590
|
-
|
591
|
-
|
590
|
+
|
591
|
+
@incoming.empty?(true)
|
592
|
+
@picker_thread.kill
|
592
593
|
@listener.close
|
593
594
|
@unilistener.close
|
594
|
-
@picker_thread.kill
|
595
595
|
|
596
|
-
|
597
|
-
sleep(0.01)
|
598
|
-
end
|
596
|
+
@outgoing.empty?(true)
|
599
597
|
@shouter_thread.kill
|
600
598
|
@sender.close
|
601
599
|
@unisender.close
|
@@ -725,7 +723,7 @@ module Archipelago
|
|
725
723
|
@shouter_thread = Thread.new do
|
726
724
|
loop do
|
727
725
|
begin
|
728
|
-
recipient, data = @outgoing.
|
726
|
+
recipient, data = @outgoing.shift
|
729
727
|
if recipient
|
730
728
|
address, port = recipient.split(/:/)
|
731
729
|
@unisender.send(Marshal.dump(data), 0, address, port.to_i)
|
@@ -788,7 +786,7 @@ module Archipelago
|
|
788
786
|
@picker_thread = Thread.new do
|
789
787
|
loop do
|
790
788
|
begin
|
791
|
-
data = @incoming.
|
789
|
+
data = @incoming.shift
|
792
790
|
if Archipelago::Disco::Query === data
|
793
791
|
@local_services.get_services(data).each do |service_id, service_data|
|
794
792
|
if @thrifty_replying
|
data/lib/archipelago/hashish.rb
CHANGED
data/tests/current_test.rb
CHANGED
@@ -19,6 +19,41 @@ end
|
|
19
19
|
|
20
20
|
class CurrentTest < Test::Unit::TestCase
|
21
21
|
|
22
|
+
def test_queue
|
23
|
+
q = Archipelago::Current::Queue.new
|
24
|
+
assert(q.empty?)
|
25
|
+
t = true
|
26
|
+
Thread.new do
|
27
|
+
e = q.shift
|
28
|
+
t = false
|
29
|
+
end
|
30
|
+
Thread.pass
|
31
|
+
assert(t)
|
32
|
+
q << "blar"
|
33
|
+
Thread.pass
|
34
|
+
sleep(0.1)
|
35
|
+
assert(!t)
|
36
|
+
|
37
|
+
q << "bunke"
|
38
|
+
assert(!q.empty?)
|
39
|
+
q.shift
|
40
|
+
assert(q.empty?)
|
41
|
+
|
42
|
+
assert(q.empty?)
|
43
|
+
q << "hehu"
|
44
|
+
assert(!q.empty?)
|
45
|
+
Thread.new do
|
46
|
+
q.empty?(true)
|
47
|
+
t = true
|
48
|
+
end
|
49
|
+
Thread.pass
|
50
|
+
assert(!t)
|
51
|
+
q.shift
|
52
|
+
Thread.pass
|
53
|
+
assert(t)
|
54
|
+
assert(q.empty?)
|
55
|
+
end
|
56
|
+
|
22
57
|
def test_synchronized
|
23
58
|
t = true
|
24
59
|
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: archipelago
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
6
|
+
version: 0.2.7
|
7
7
|
date: 2007-05-14 00:00:00 +02:00
|
8
8
|
summary: A set of tools for distributed computing in ruby.
|
9
9
|
require_paths:
|
@@ -29,7 +29,6 @@ post_install_message:
|
|
29
29
|
authors:
|
30
30
|
- Martin Kihlgren
|
31
31
|
files:
|
32
|
-
- lib/archipelago.rb
|
33
32
|
- lib/archipelago/client.rb
|
34
33
|
- lib/archipelago/current.rb
|
35
34
|
- lib/archipelago/disco.rb
|
@@ -39,6 +38,7 @@ files:
|
|
39
38
|
- lib/archipelago/sanitation.rb
|
40
39
|
- lib/archipelago/tranny.rb
|
41
40
|
- lib/archipelago/treasure.rb
|
41
|
+
- lib/archipelago.rb
|
42
42
|
- tests/current_benchmark.rb
|
43
43
|
- tests/current_test.rb
|
44
44
|
- tests/disco_benchmark.rb
|
@@ -81,5 +81,22 @@ extensions: []
|
|
81
81
|
|
82
82
|
requirements: []
|
83
83
|
|
84
|
-
dependencies:
|
85
|
-
|
84
|
+
dependencies:
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: oneliner
|
87
|
+
version_requirement:
|
88
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 0.2.7
|
93
|
+
version:
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: archipelago_rbtree
|
96
|
+
version_requirement:
|
97
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.2.7
|
102
|
+
version:
|