markbates-distribunaut 0.1.20090406 → 0.1.20090407

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.
@@ -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::Distributed::Utils::Rinda.register_or_renew(:space => "#{base}".to_sym,
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::Distributed::Utils::Rinda.read(:space => "#{const}".to_sym)
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::Distributed::Utils::Rinda.register_or_renew(:app_name => :app_1, :space => :Test, :object => "Hello World!")
13
- # Distribunaut::Distributed::Utils::Rinda.register_or_renew(:app_name => :app_2, :space => :Test, :object => "Hello WORLD!")
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::Distributed::Utils::Rinda.read(:space => path.to_sym, :app_name => host.to_sym)
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 Distributed
3
- module Utils # :nodoc:
4
- module Rinda
5
-
6
- def self.register_or_renew(options = {})
7
- options = handle_options(options)
8
- begin
9
- ring_server.take([options[:app_name], options[:space], nil, nil], options[:timeout])
10
- rescue ::Rinda::RequestExpiredError => e
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
- def self.register(options = {})
17
- options = handle_options(options)
18
- ring_server.write([options[:app_name],
19
- options[:space],
20
- options[:object],
21
- options[:description]],
22
- ::Rinda::SimpleRenewer.new)
23
- end
24
-
25
- def self.ring_server
26
- if configatron.distribunaut.retrieve(:acl, nil)
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.20090406
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