Permalink
Browse files

Added a Tuple class.

  • Loading branch information...
1 parent e6b97ee commit 75664752d3f10a4274d94ee4d2193d097e25f39d @markbates committed Apr 7, 2009
@@ -42,7 +42,7 @@ def to_s
}
obj = "Distribunaut::Distributed::#{base}Proxy".constantize.instance
raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
- Distribunaut::Distributed::Utils::Rinda.register_or_renew(:space => "#{base}".to_sym,
+ Distribunaut::Utils::Rinda.register_or_renew(:space => "#{base}".to_sym,
:object => obj,
:app_name => configatron.distribunaut.app_name)
end
@@ -3,21 +3,21 @@ module Distributed # :nodoc:
# Looks up and tries to find the missing constant using the ring server.
def self.const_missing(const)
- Distribunaut::Distributed::Utils::Rinda.read(:space => "#{const}".to_sym)
+ Distribunaut::Utils::Rinda.read(:space => "#{const}".to_sym)
end
# Allows for the specific lookup of services on the ring server
#
# Examples:
- # Distribunaut::Distributed::Utils::Rinda.register_or_renew(:app_name => :app_1, :space => :Test, :object => "Hello World!")
- # Distribunaut::Distributed::Utils::Rinda.register_or_renew(:app_name => :app_2, :space => :Test, :object => "Hello WORLD!")
+ # Distribunaut::Utils::Rinda.register_or_renew(:app_name => :app_1, :space => :Test, :object => "Hello World!")
+ # Distribunaut::Utils::Rinda.register_or_renew(:app_name => :app_2, :space => :Test, :object => "Hello WORLD!")
# Distribunaut::Distributed.lookup("distributed://app_1/Test") # => "Hello World!"
# Distribunaut::Distributed.lookup("distributed://app_2/Test") # => "Hello WORLD!"
def self.lookup(address)
uri = Addressable::URI.parse(address)
path = uri.path[1..uri.path.size] # remove the first slash
host = uri.host
- Distribunaut::Distributed::Utils::Rinda.read(:space => path.to_sym, :app_name => host.to_sym)
+ Distribunaut::Utils::Rinda.read(:space => path.to_sym, :app_name => host.to_sym)
end
end # Distributed
@@ -1,53 +1,51 @@
module Distribunaut
- module Distributed
- module Utils # :nodoc:
- module Rinda
-
- def self.register_or_renew(options = {})
- options = handle_options(options)
- begin
- ring_server.take([options[:app_name], options[:space], nil, nil], options[:timeout])
- rescue ::Rinda::RequestExpiredError => e
- # it's ok that it expired. It could be that it was never registered.
- end
- register(options)
+ module Utils # :nodoc:
+ module Rinda
+
+ def self.register_or_renew(options = {})
+ options = handle_options(options)
+ begin
+ ring_server.take([options[:app_name], options[:space], nil, nil], options[:timeout])
+ rescue ::Rinda::RequestExpiredError => e
+ # it's ok that it expired. It could be that it was never registered.
end
-
- def self.register(options = {})
- options = handle_options(options)
- ring_server.write([options[:app_name],
- options[:space],
- options[:object],
- options[:description]],
- ::Rinda::SimpleRenewer.new)
- end
-
- def self.ring_server
- if configatron.distribunaut.retrieve(:acl, nil)
- acl = ACL.new(configatron.distribunaut.acl)
- DRb.install_acl(acl)
- end
- ::DRb.start_service
- rs = ::Rinda::RingFinger.primary
- rs
- end
-
- def self.read(options = {})
- options = handle_options(options)
- ring_server.read([options[:app_name], options[:space], nil, options[:description]], options[:timeout])[2]
- end
-
- private
- def self.handle_options(options = {})
- {:app_name => nil,
- :space => nil,
- :object => nil,
- :description => nil,
- :timeout => configatron.distribunaut.timeout
- }.merge(options)
+ register(options)
+ end
+
+ def self.register(options = {})
+ options = handle_options(options)
+ ring_server.write([options[:app_name],
+ options[:space],
+ options[:object],
+ options[:description]],
+ ::Rinda::SimpleRenewer.new)
+ end
+
+ def self.ring_server
+ if configatron.distribunaut.retrieve(:acl, nil)
+ acl = ACL.new(configatron.distribunaut.acl)
+ DRb.install_acl(acl)
end
-
+ ::DRb.start_service
+ rs = ::Rinda::RingFinger.primary
+ rs
+ end
+
+ def self.read(options = {})
+ options = handle_options(options)
+ ring_server.read([options[:app_name], options[:space], nil, options[:description]], options[:timeout])[2]
+ end
+
+ private
+ def self.handle_options(options = {})
+ {:app_name => nil,
+ :space => nil,
+ :object => nil,
+ :description => nil,
+ :timeout => configatron.distribunaut.timeout
+ }.merge(options)
end
+
end
end
end
@@ -50,8 +50,8 @@ class Mouse
describe "lookup" do
it "should look up and return a specific service from rinda" do
- Distribunaut::Distributed::Utils::Rinda.register_or_renew(:app_name => :app_1, :space => :Test, :object => "Hello World!")
- Distribunaut::Distributed::Utils::Rinda.register_or_renew(:app_name => :app_2, :space => :Test, :object => "Hello WORLD!")
+ Distribunaut::Utils::Rinda.register_or_renew(:app_name => :app_1, :space => :Test, :object => "Hello World!")
+ Distribunaut::Utils::Rinda.register_or_renew(:app_name => :app_2, :space => :Test, :object => "Hello WORLD!")
Distribunaut::Distributed.lookup("distributed://app_1/Test").should == "Hello World!"
Distribunaut::Distributed.lookup("distributed://app_2/Test").should == "Hello WORLD!"
end
@@ -66,7 +66,7 @@ def to_s
"i'm a bike"
end
end
- c = Distribunaut::Distributed::Utils::Rinda.read(:space => :Bike)
+ c = Distribunaut::Utils::Rinda.read(:space => :Bike)
c.inspect.should match(/Bike/)
c.new.to_s.should match(/i'm a bike/)
end
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper")
-describe Distribunaut::Distributed::Utils::Rinda do
+describe Distribunaut::Utils::Rinda do
before(:each) do
begin
@@ -17,17 +17,17 @@
end
it "should have access to the ring server" do
- rs = Distribunaut::Distributed::Utils::Rinda.ring_server
+ rs = Distribunaut::Utils::Rinda.ring_server
rs.should_not be_nil
rs.is_a?(Rinda::TupleSpace).should == true
end
it "should be able to register new service" do
str = String.randomize(40)
- rs = Distribunaut::Distributed::Utils::Rinda.ring_server
+ rs = Distribunaut::Utils::Rinda.ring_server
serv = nil
lambda { rs.read([:testing, :String, nil, "test_register-#{str}"], 0)[2] }.should raise_error(Rinda::RequestExpiredError)
- Distribunaut::Distributed::Utils::Rinda.register(:app_name => :testing, :space => :String, :object => str, :description => "test_register-#{str}")
+ Distribunaut::Utils::Rinda.register(:app_name => :testing, :space => :String, :object => str, :description => "test_register-#{str}")
serv = nil
serv = rs.read([:testing, :String, nil, "test_register-#{str}"], 1)[2]
serv.should_not be_nil
@@ -36,17 +36,17 @@
it "should be able to register or renew service(s)" do
str = String.randomize(40)
- rs = Distribunaut::Distributed::Utils::Rinda.ring_server
+ rs = Distribunaut::Utils::Rinda.ring_server
serv = nil
lambda { rs.read([:testing, :String, nil, "test_register_or_renew"], 0)[2] }.should raise_error(Rinda::RequestExpiredError)
- Distribunaut::Distributed::Utils::Rinda.register_or_renew(:app_name => :testing, :space => :String, :object => str, :description => "test_register_or_renew")
+ Distribunaut::Utils::Rinda.register_or_renew(:app_name => :testing, :space => :String, :object => str, :description => "test_register_or_renew")
serv = nil
serv = rs.read([:testing, :String, nil, "test_register_or_renew"], 1)[2]
serv.should_not be_nil
serv.should == str
str2 = String.randomize(40)
- Distribunaut::Distributed::Utils::Rinda.register_or_renew(:app_name => :testing, :space => :String, :object => str2, :description => "test_register_or_renew")
+ Distribunaut::Utils::Rinda.register_or_renew(:app_name => :testing, :space => :String, :object => str2, :description => "test_register_or_renew")
serv = nil
serv = rs.read([:testing, :String, nil, "test_register_or_renew"], 1)[2]
serv.should_not be_nil

0 comments on commit 7566475

Please sign in to comment.