markbates-distribunaut 0.1.20090406 → 0.1.20090407
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/distribunaut/distributable.rb +1 -1
- data/lib/distribunaut/distributed.rb +4 -4
- data/lib/distribunaut/tuple.rb +38 -0
- data/lib/distribunaut/utils/rinda.rb +38 -46
- metadata +2 -1
@@ -42,7 +42,7 @@ module Distribunaut # :nodoc:
|
|
42
42
|
}
|
43
43
|
obj = "Distribunaut::Distributed::#{base}Proxy".constantize.instance
|
44
44
|
raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
|
45
|
-
Distribunaut::
|
45
|
+
Distribunaut::Utils::Rinda.register_or_renew(:space => "#{base}".to_sym,
|
46
46
|
:object => obj,
|
47
47
|
:app_name => configatron.distribunaut.app_name)
|
48
48
|
end
|
@@ -3,21 +3,21 @@ module Distribunaut # :nodoc:
|
|
3
3
|
|
4
4
|
# Looks up and tries to find the missing constant using the ring server.
|
5
5
|
def self.const_missing(const)
|
6
|
-
Distribunaut::
|
6
|
+
Distribunaut::Utils::Rinda.read(:space => "#{const}".to_sym)
|
7
7
|
end
|
8
8
|
|
9
9
|
# Allows for the specific lookup of services on the ring server
|
10
10
|
#
|
11
11
|
# Examples:
|
12
|
-
# Distribunaut::
|
13
|
-
# Distribunaut::
|
12
|
+
# Distribunaut::Utils::Rinda.register_or_renew(:app_name => :app_1, :space => :Test, :object => "Hello World!")
|
13
|
+
# Distribunaut::Utils::Rinda.register_or_renew(:app_name => :app_2, :space => :Test, :object => "Hello WORLD!")
|
14
14
|
# Distribunaut::Distributed.lookup("distributed://app_1/Test") # => "Hello World!"
|
15
15
|
# Distribunaut::Distributed.lookup("distributed://app_2/Test") # => "Hello WORLD!"
|
16
16
|
def self.lookup(address)
|
17
17
|
uri = Addressable::URI.parse(address)
|
18
18
|
path = uri.path[1..uri.path.size] # remove the first slash
|
19
19
|
host = uri.host
|
20
|
-
Distribunaut::
|
20
|
+
Distribunaut::Utils::Rinda.read(:space => path.to_sym, :app_name => host.to_sym)
|
21
21
|
end
|
22
22
|
|
23
23
|
end # Distributed
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Distribunaut # :nodoc:
|
2
|
+
class Tuple
|
3
|
+
|
4
|
+
attr_accessor :app_name
|
5
|
+
attr_accessor :space
|
6
|
+
attr_accessor :object
|
7
|
+
attr_accessor :description
|
8
|
+
attr_accessor :timeout
|
9
|
+
|
10
|
+
def initialize(values = {})
|
11
|
+
values.each do |k, v|
|
12
|
+
self.send("#{k}=", v)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_array
|
17
|
+
[self.app_name, self.space, self.object, self.description]
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_search_array
|
21
|
+
[self.app_name, self.space, nil, nil]
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
|
26
|
+
def from_array(ar)
|
27
|
+
tuple = Distribunaut::Tuple.new
|
28
|
+
tuple.app_name = ar[0]
|
29
|
+
tuple.space = ar[1]
|
30
|
+
tuple.object = ar[2]
|
31
|
+
tuple.description = ar[3]
|
32
|
+
return tuple
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end # Tuple
|
38
|
+
end # Distribunaut
|
@@ -1,53 +1,45 @@
|
|
1
1
|
module Distribunaut
|
2
|
-
module
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# it's ok that it expired. It could be that it was never registered.
|
12
|
-
end
|
13
|
-
register(options)
|
2
|
+
module Utils # :nodoc:
|
3
|
+
module Rinda
|
4
|
+
|
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.
|
14
11
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
acl = ACL.new(configatron.distribunaut.acl)
|
28
|
-
DRb.install_acl(acl)
|
29
|
-
end
|
30
|
-
::DRb.start_service
|
31
|
-
rs = ::Rinda::RingFinger.primary
|
32
|
-
rs
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.read(options = {})
|
36
|
-
options = handle_options(options)
|
37
|
-
ring_server.read([options[:app_name], options[:space], nil, options[:description]], options[:timeout])[2]
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
def self.handle_options(options = {})
|
42
|
-
{:app_name => nil,
|
43
|
-
:space => nil,
|
44
|
-
:object => nil,
|
45
|
-
:description => nil,
|
46
|
-
:timeout => configatron.distribunaut.timeout
|
47
|
-
}.merge(options)
|
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)
|
48
24
|
end
|
49
|
-
|
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
|
+
private
|
38
|
+
def self.build_tuple(values = {})
|
39
|
+
return values if values.is_a?(Distribunaut::Tuple)
|
40
|
+
Distribunaut::Tuple.new({:timeout => configatron.distribunaut.timeout}.merge(values))
|
50
41
|
end
|
42
|
+
|
51
43
|
end
|
52
44
|
end
|
53
45
|
end
|
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.1.
|
4
|
+
version: 0.1.20090407
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markbates
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/distribunaut/errors/errors.rb
|
67
67
|
- lib/distribunaut/extensions/drb_object.rb
|
68
68
|
- lib/distribunaut/tasks/ring_server_tasks.rake
|
69
|
+
- lib/distribunaut/tuple.rb
|
69
70
|
- lib/distribunaut/utils/rinda.rb
|
70
71
|
- lib/distribunaut.rb
|
71
72
|
- lib/distribunaut_tasks.rb
|