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
More work on distributed objects [#10]
markbates (author)
Tue Aug 05 14:15:53 -0700 2008
commit  59fece7a6a3511724a08edbab4d8e4267b462468
tree    3a4fb3a672aba1fd3e43097819f3dea6f6b845ba
parent  05bfe9ca17d7bb89e1a5445d6fcb963b38e1f572
...
3
4
5
6
7
8
9
10
11
12
 
 
 
 
 
 
 
 
13
14
15
 
 
 
 
 
 
 
16
17
18
 
 
 
 
 
 
19
20
21
...
3
4
5
 
 
 
 
 
 
 
6
7
8
9
10
11
12
13
14
 
 
15
16
17
18
19
20
21
22
 
 
23
24
25
26
27
28
29
30
31
0
@@ -3,19 +3,29 @@ module Mack
0
     module Object
0
       
0
       def self.included(base)
0
-        base.class_eval do
0
-          include ::DRbUndumped
0
-        end
0
-        eval %{
0
-          class ::Mack::Distributed::#{base}Proxy < Mack::Utils::BlankSlate
0
-            include Singleton
0
-            include DRbUndumped
0
+        if app_config.mack.share_objects
0
+          base.class_eval do
0
+            include ::DRbUndumped
0
+          end
0
+          eval %{
0
+            class ::Mack::Distributed::#{base}Proxy
0
+              include Singleton
0
+              include DRbUndumped
0
 
0
-            def method_missing(sym, *args)
0
-              #{base}.send(sym, *args)
0
+              def method_missing(sym, *args)
0
+                #{base}.send(sym, *args)
0
+              end
0
+            
0
+              # def respond_to?(sym)
0
+              #   #{base}.respond_to?(sym)
0
+              # end
0
             end
0
-          end
0
-        }
0
+          }
0
+          raise Mack::Distributed::Errors::ApplicationNameUndefined.new if app_config.mack.distributed_app_name.nil?
0
+          Mack::Distributed::Utils::Rinda.register_or_renew(:space => app_config.mack.distributed_app_name.to_sym, 
0
+                                                            :klass_def => "#{base}".to_sym, 
0
+                                                            :object => "Mack::Distributed::#{base}Proxy".constantize.instance)
0
+        end
0
       end
0
       
0
     end # Object
...
36
37
38
39
 
40
41
42
...
36
37
38
 
39
40
41
42
0
@@ -36,7 +36,7 @@ module Mack
0
         
0
         private
0
         def self.handle_options(options = {})
0
-          {:space => :name, :klass_def => nil, :object => nil, :description => nil, :timeout => app_config.mack.drb_timeout}.merge(options)
0
+          {:space => nil, :klass_def => nil, :object => nil, :description => nil, :timeout => app_config.mack.drb_timeout}.merge(options)
0
         end
0
         
0
       end
...
8
9
10
 
 
11
12
13
...
8
9
10
11
12
13
14
15
0
@@ -8,5 +8,7 @@ mack::page_cache: true
0
 
0
 mack::use_distributed_routes: false
0
 mack::distributed_app_name: fake_app
0
+mack::share_objects: true
0
+mack::drb_timeout: 0
0
 
0
 mack::testing_framework: rspec
0
\ No newline at end of file
...
4
5
6
7
8
9
10
11
 
 
 
 
 
 
 
12
13
14
15
16
17
18
19
20
 
 
 
 
21
22
23
24
 
25
26
27
...
32
33
34
 
 
 
 
 
 
 
 
 
35
36
37
38
39
 
40
41
42
...
4
5
6
 
 
 
 
 
7
8
9
10
11
12
13
14
 
 
 
 
15
16
17
 
18
19
20
21
22
23
24
 
25
26
27
28
...
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
49
50
51
52
0
@@ -4,24 +4,25 @@ require 'rinda/tuplespace'
0
 
0
 describe Mack::Distributed::Object do
0
 
0
-  class Car
0
-    include Mack::Distributed::Object
0
-    
0
-    def make
0
-      "Toyota"
0
+  before(:each) do
0
+    begin
0
+      DRb.start_service
0
+      Rinda::RingServer.new(Rinda::TupleSpace.new)
0
+    rescue Errno::EADDRINUSE => e
0
+      # it's fine to ignore this, it's expected that it's already running.
0
+      # all other exceptions should be thrown
0
     end
0
-    
0
-    def self.buy
0
-    end
0
-    
0
   end
0
 
0
   it "should include DRbUndumped" do
0
-    Car.new.should be_is_a(DRbUndumped)
0
+    class Pool
0
+      include Mack::Distributed::Object
0
+    end
0
+    Pool.new.should be_is_a(DRbUndumped)
0
   end
0
   
0
   it "should defined a proxy singleton" do
0
-    lambda{Mack::Distributed::BoatProxy}.should raise_error(NameError)
0
+    lambda{Mack::Distributed::BoatProxy}.should raise_error(Rinda::RequestExpiredError)
0
     class Boat
0
       include Mack::Distributed::Object
0
     end
0
@@ -32,11 +33,20 @@ describe Mack::Distributed::Object do
0
   end
0
   
0
   it "should respond with the methods of the underlying class" do
0
+    class Car
0
+      include Mack::Distributed::Object
0
+      def make
0
+        "Toyota"
0
+      end
0
+      def self.buy
0
+        true
0
+      end
0
+    end
0
     car = Mack::Distributed::CarProxy.instance.new
0
     car.should be_is_a(Car)
0
     car.make.should == "Toyota"
0
     car.respond_to?(:make).should == true
0
-    Mack::Distributed::CarProxy.instance.respond_to?(:buy).should == true
0
+    Mack::Distributed::CarProxy.instance.buy.should == true
0
   end
0
   
0
 
...
2
3
4
5
 
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
...
22
23
24
25
 
26
27
28
...
2
3
4
 
5
6
7
8
 
9
10
11
12
 
 
 
 
13
14
15
...
17
18
19
 
20
21
22
23
0
@@ -2,19 +2,14 @@ require File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper")
0
 
0
 describe "droute_url" do
0
   
0
-  before(:all) do
0
+  before(:each) do
0
     begin
0
       DRb.start_service
0
       Rinda::RingServer.new(Rinda::TupleSpace.new)
0
-      # DRb.thread.join
0
     rescue Errno::EADDRINUSE => e
0
       # it's fine to ignore this, it's expected that it's already running.
0
       # all other exceptions should be thrown
0
     end
0
-    begin
0
-      rs.take([:testing, :String, nil, nil], 0)
0
-    rescue Exception => e
0
-    end
0
     app_config.load_hash({"mack::use_distributed_routes" => true, "mack::distributed_app_name" => :known_app}, :distributed_route_test)
0
     Mack::Routes.build do |r| # force the routes to go the DRb server
0
       r.known "/my_known_app/my_known_url", :controller => :foo, :action => :bar
0
@@ -22,7 +17,7 @@ describe "droute_url" do
0
     end
0
   end
0
   
0
-  after(:all) do
0
+  after(:each) do
0
     app_config.revert
0
   end
0
   
...
4
5
6
7
 
8
9
10
11
12
13
14
...
4
5
6
 
7
8
9
10
 
11
12
13
0
@@ -4,11 +4,10 @@ require 'rinda/tuplespace'
0
 
0
 describe Mack::Distributed::Utils::Rinda do
0
   
0
-  before(:all) do 
0
+  before(:each) do 
0
     begin
0
       DRb.start_service
0
       Rinda::RingServer.new(Rinda::TupleSpace.new)
0
-      # DRb.thread.join
0
     rescue Errno::EADDRINUSE => e
0
       # it's fine to ignore this, it's expected that it's already running.
0
       # all other exceptions should be thrown

Comments