markbates-distribunaut 0.2.2.20090626214209 → 0.2.20090511204103
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/distribunaut/distributable.rb +5 -14
- data/lib/distribunaut/tuple.rb +0 -4
- data/lib/distribunaut/utils/rinda.rb +47 -75
- data/lib/distribunaut.rb +1 -3
- metadata +2 -2
@@ -17,7 +17,6 @@ module Distribunaut # :nodoc:
|
|
17
17
|
module Distributable
|
18
18
|
|
19
19
|
def self.included(base) # :nodoc:
|
20
|
-
raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
|
21
20
|
base.class_eval do
|
22
21
|
include ::DRbUndumped
|
23
22
|
end
|
@@ -34,23 +33,15 @@ module Distribunaut # :nodoc:
|
|
34
33
|
undef :id if method_defined?(:id)
|
35
34
|
undef :inspect if method_defined?(:inspect)
|
36
35
|
undef :to_s if method_defined?(:to_s)
|
37
|
-
|
38
|
-
def borrow(&block)
|
39
|
-
Distribunaut::Utils::Rinda.borrow(:space => :#{base},
|
40
|
-
:object => self,
|
41
|
-
:description => "#{base} Service",
|
42
|
-
:app_name => configatron.distribunaut.app_name.to_sym) do |tuple|
|
43
|
-
yield tuple.object
|
44
|
-
end
|
45
|
-
end
|
46
36
|
|
47
37
|
end
|
48
38
|
}
|
49
|
-
obj = "Distribunaut::Distributed::#{c_name}Proxy".constantize.instance
|
39
|
+
obj = "Distribunaut::Distributed::#{c_name}Proxy".constantize.instance
|
40
|
+
raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
|
50
41
|
Distribunaut::Utils::Rinda.register_or_renew(:space => "#{base}".to_sym,
|
51
|
-
|
52
|
-
|
53
|
-
|
42
|
+
:object => obj,
|
43
|
+
:description => "#{base} Service",
|
44
|
+
:app_name => configatron.distribunaut.app_name)
|
54
45
|
end
|
55
46
|
|
56
47
|
end # Distributable
|
data/lib/distribunaut/tuple.rb
CHANGED
@@ -2,81 +2,53 @@ module Distribunaut
|
|
2
2
|
module Utils # :nodoc:
|
3
3
|
module Rinda
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
tuple
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
52
|
-
tuple.space = $1.to_sym
|
53
|
-
register(tuple)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def available_services
|
58
|
-
ring_server = self.ring_server
|
59
|
-
all = ring_server.read_all([nil, nil, nil, nil])
|
60
|
-
services = []
|
61
|
-
all.each do |service|
|
62
|
-
services << Distribunaut::Tuple.from_array(service)
|
63
|
-
end
|
64
|
-
services
|
65
|
-
end
|
66
|
-
|
67
|
-
def remove_all_services!
|
68
|
-
available_services.each do |service|
|
69
|
-
ring_server.take(service.to_array)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
def build_tuple(values = {})
|
75
|
-
return values if values.is_a?(Distribunaut::Tuple)
|
76
|
-
Distribunaut::Tuple.new({:timeout => configatron.distribunaut.timeout}.merge(values))
|
77
|
-
end
|
78
|
-
|
79
|
-
end # class << self
|
5
|
+
def self.register_or_renew(values = {})
|
6
|
+
tuple = build_tuple(values)
|
7
|
+
begin
|
8
|
+
ring_server.take(tuple.to_search_array, tuple.timeout)
|
9
|
+
rescue ::Rinda::RequestExpiredError => e
|
10
|
+
# it's ok that it expired. It could be that it was never registered.
|
11
|
+
end
|
12
|
+
register(values)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.register(values = {})
|
16
|
+
tuple = build_tuple(values)
|
17
|
+
ring_server.write(tuple.to_array, ::Rinda::SimpleRenewer.new)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.ring_server
|
21
|
+
if configatron.distribunaut.retrieve(:acl, nil)
|
22
|
+
acl = ACL.new(configatron.distribunaut.acl)
|
23
|
+
DRb.install_acl(acl)
|
24
|
+
end
|
25
|
+
::DRb.start_service
|
26
|
+
rs = ::Rinda::RingFinger.primary
|
27
|
+
rs
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.read(values = {})
|
31
|
+
tuple = build_tuple(values)
|
32
|
+
results = ring_server.read(tuple.to_array, tuple.timeout)
|
33
|
+
tuple = Distribunaut::Tuple.from_array(results)
|
34
|
+
tuple.object
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.available_services
|
38
|
+
ring_server = self.ring_server
|
39
|
+
all = ring_server.read_all([nil, nil, nil, nil])
|
40
|
+
services = []
|
41
|
+
all.each do |service|
|
42
|
+
services << Distribunaut::Tuple.from_array(service)
|
43
|
+
end
|
44
|
+
services
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def self.build_tuple(values = {})
|
49
|
+
return values if values.is_a?(Distribunaut::Tuple)
|
50
|
+
Distribunaut::Tuple.new({:timeout => configatron.distribunaut.timeout}.merge(values))
|
51
|
+
end
|
80
52
|
|
81
53
|
end
|
82
54
|
end
|
data/lib/distribunaut.rb
CHANGED
@@ -8,6 +8,7 @@ require 'activesupport'
|
|
8
8
|
|
9
9
|
base = File.join(File.dirname(__FILE__), 'distribunaut')
|
10
10
|
|
11
|
+
configatron.distribunaut.set_default(:share_objects, false)
|
11
12
|
configatron.distribunaut.set_default(:app_name, nil)
|
12
13
|
configatron.distribunaut.set_default(:timeout, 0)
|
13
14
|
|
@@ -16,6 +17,3 @@ Dir.glob(File.join(base, "**", "*.rb")).each do |f|
|
|
16
17
|
require(f)
|
17
18
|
end
|
18
19
|
|
19
|
-
# Make sure no one can call eval() and related
|
20
|
-
# methods remotely!
|
21
|
-
$SAFE = 1 unless $SAFE > 0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markbates-distribunaut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.20090511204103
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markbates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-11 00:00:00 -07:00
|
13
13
|
default_executable: distribunaut_ring_server
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|