public
Description: All the extra stuff you could want for the Mack Framework.
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack-more.git
Added lookup method to Mack::Distributed. [#84 state:resolved]
markbates (author)
Fri Aug 08 12:01:40 -0700 2008
commit  ff5a4840acee04952c3c422f72f7dd2507b55e8d
tree    e24573e6763bae8891a9a1e4a493bf6f4ef1ac40
parent  3265f071f2bfaf1bcac42a33c1a29ba55abbc424
...
1
 
2
3
4
...
1
2
3
4
5
0
@@ -1,4 +1,5 @@
0
 require 'drb/acl'
0
+require 'addressable/uri'
0
 
0
 base = File.join(File.dirname(__FILE__), "mack-distributed")
0
 
...
6
7
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
10
11
...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
0
@@ -6,5 +6,19 @@ module Mack # :nodoc:
0
       Mack::Distributed::Utils::Rinda.read(:klass_def => "#{const}".to_sym)
0
     end
0
     
0
+    # Allows for the specific lookup of services on the ring server
0
+    # 
0
+    # Examples:
0
+    #   Mack::Distributed::Utils::Rinda.register_or_renew(:space => :app_1, :klass_def => :Test, :object => "Hello World!")
0
+    #   Mack::Distributed::Utils::Rinda.register_or_renew(:space => :app_2, :klass_def => :Test, :object => "Hello WORLD!")
0
+    #   Mack::Distributed.lookup("distributed://app_1/Test") # => "Hello World!"
0
+    #   Mack::Distributed.lookup("distributed://app_2/Test") # => "Hello WORLD!"
0
+    def self.lookup(address)
0
+      uri = Addressable::URI.parse(address)
0
+      path = uri.path[1..uri.path.size] # remove the first slash
0
+      host = uri.host
0
+      Mack::Distributed::Utils::Rinda.read(:klass_def => path.to_sym, :space => host.to_sym)
0
+    end
0
+    
0
   end # Distributed
0
 end # Mack
0
\ No newline at end of file
...
34
35
36
 
37
38
39
...
34
35
36
37
38
39
40
0
@@ -34,6 +34,7 @@ module Mack
0
         
0
         def self.read(options = {})
0
           options = handle_options(options)
0
+          puts "options: #{options.inspect}"
0
           ring_server.read([options[:space], options[:klass_def], nil, options[:description]], options[:timeout])[2]
0
         end
0
         
...
44
45
46
47
 
 
 
 
 
 
48
49
50
...
44
45
46
 
47
48
49
50
51
52
53
54
55
0
@@ -44,7 +44,12 @@ describe Mack::Distributed do
0
   
0
   describe "lookup" do
0
     
0
-    it "should look up and return a specific service from rinda"
0
+    it "should look up and return a specific service from rinda" do
0
+      Mack::Distributed::Utils::Rinda.register_or_renew(:space => :app_1, :klass_def => :Test, :object => "Hello World!")
0
+      Mack::Distributed::Utils::Rinda.register_or_renew(:space => :app_2, :klass_def => :Test, :object => "Hello WORLD!")
0
+      Mack::Distributed.lookup("distributed://app_1/Test").should == "Hello World!"
0
+      Mack::Distributed.lookup("distributed://app_2/Test").should == "Hello WORLD!"
0
+    end
0
     
0
   end
0
   

Comments