<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -13,7 +13,7 @@ require File.join(File.dirname(__FILE__), 'lib', 'distribunaut_tasks')
 
 @gem_spec = Gem::Specification.new do |s|
   s.name = &quot;distribunaut&quot;
-  s.version = &quot;0.2.1&quot;
+  s.version = &quot;0.2.2&quot;
   s.summary = &quot;distribunaut&quot;
   s.description = &quot;distribunaut was developed by: markbates&quot;
   s.author = &quot;markbates&quot;</diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -2,11 +2,11 @@
 
 Gem::Specification.new do |s|
   s.name = %q{distribunaut}
-  s.version = &quot;0.2.1.20090624214017&quot;
+  s.version = &quot;0.2.2.20090626214209&quot;
 
   s.required_rubygems_version = Gem::Requirement.new(&quot;&gt;= 0&quot;) if s.respond_to? :required_rubygems_version=
   s.authors = [&quot;markbates&quot;]
-  s.date = %q{2009-06-24}
+  s.date = %q{2009-06-26}
   s.default_executable = %q{distribunaut_ring_server}
   s.description = %q{distribunaut was developed by: markbates}
   s.email = %q{mark@mackframework.com}</diff>
      <filename>distribunaut.gemspec</filename>
    </modified>
    <modified>
      <diff>@@ -17,6 +17,7 @@ module Distribunaut # :nodoc:
   module Distributable
       
       def self.included(base) # :nodoc:
+        raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
         base.class_eval do
           include ::DRbUndumped
         end
@@ -33,15 +34,23 @@ module Distribunaut # :nodoc:
             undef :id if method_defined?(:id)
             undef :inspect if method_defined?(:inspect)
             undef :to_s if method_defined?(:to_s)
+            
+            def borrow(&amp;block)
+              Distribunaut::Utils::Rinda.borrow(:space =&gt; :#{base}, 
+                                                :object =&gt; self,
+                                                :description =&gt; &quot;#{base} Service&quot;,
+                                                :app_name =&gt; configatron.distribunaut.app_name.to_sym) do |tuple|
+                yield tuple.object
+              end
+            end
           
           end
         }
-        obj = &quot;Distribunaut::Distributed::#{c_name}Proxy&quot;.constantize.instance 
-        raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
+        obj = &quot;Distribunaut::Distributed::#{c_name}Proxy&quot;.constantize.instance
         Distribunaut::Utils::Rinda.register_or_renew(:space =&gt; &quot;#{base}&quot;.to_sym, 
-                                                                  :object =&gt; obj,
-                                                                  :description =&gt; &quot;#{base} Service&quot;,
-                                                                  :app_name =&gt; configatron.distribunaut.app_name.to_sym)
+                                                     :object =&gt; obj,
+                                                     :description =&gt; &quot;#{base} Service&quot;,
+                                                     :app_name =&gt; configatron.distribunaut.app_name.to_sym)
       end
       
   end # Distributable</diff>
      <filename>lib/distribunaut/distributable.rb</filename>
    </modified>
    <modified>
      <diff>@@ -35,6 +35,24 @@ module Distribunaut
           tuple = Distribunaut::Tuple.from_array(results)
           tuple.object
         end
+        
+        def borrow(values = {}, &amp;block)
+          tuple = build_tuple(values)
+          results = ring_server.take(tuple.to_array, tuple.timeout)
+          tuple = Distribunaut::Tuple.from_array(results)
+          tuple.space = &quot;#{tuple.space}-onloan-#{Time.now}&quot;.to_sym
+          register(tuple)
+          begin
+            yield tuple if block_given?
+          rescue Exception =&gt; e
+            raise e
+          ensure
+            # (.+)-onloan-.+$
+            tuple.space.to_s.match(/(.+)-onloan-.+$/)
+            tuple.space = $1.to_sym
+            register(tuple)
+          end
+        end
       
         def available_services
           ring_server = self.ring_server</diff>
      <filename>lib/distribunaut/utils/rinda.rb</filename>
    </modified>
    <modified>
      <diff>@@ -58,7 +58,8 @@ describe Distribunaut::Distributable do
     end
     
     axl_proxy = Distribunaut::Distributed::Axl.new
-    axl_proxy.inspect.should == &quot;Sweet Child O'Mine&quot;
+    # axl_proxy.inspect.should == &quot;Sweet Child O'Mine&quot;
+    axl_proxy.inspect.should match(/#&lt;DRb::DRbObject:0x\d{1,10} @ref=\d{1,10}, @uri=\\&quot;druby:\/\/127.0.0.1:\d{3,6}\\&quot;&gt;|Sweet Child O'Mine/)
     axl_proxy.yell.should == 'YEAH!!!!'
     
     axls = Distribunaut::Distributed::Axl.find
@@ -66,4 +67,25 @@ describe Distribunaut::Distributable do
     axls.size.should == 2
   end
   
+  describe 'borrow' do
+    
+    it 'should return the object and prevent others from accessing it' do
+      class Cracker
+        include Distribunaut::Distributable
+        
+        def self.monkeys
+          &quot;You should be guarded by monkeys...&quot;
+        end
+      end
+      lambda {
+        Distribunaut::Distributed::Cracker.borrow do |cracker|
+          cracker.monkeys.should == &quot;You should be guarded by monkeys...&quot;
+          lambda{Distribunaut::Distributed::Cracker.monkeys}.should raise_error(Rinda::RequestExpiredError)
+        end
+        raise Distribunaut::TestingError
+      }.should raise_error(Distribunaut::TestingError)
+    end
+    
+  end
+  
 end</diff>
      <filename>spec/distribunaut/distributable_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -24,6 +24,41 @@ describe Distribunaut::Utils::Rinda do
     
   end
   
+  describe 'borrow' do
+    
+    it 'should lock a tuple for the duration of the block and then return it back at the end' do
+      Distribunaut::Utils::Rinda.register_or_renew(:app_name =&gt; :testing, :space =&gt; :String, :object =&gt; 'A', :description =&gt; &quot;AAA&quot;)
+      obj = Distribunaut::Utils::Rinda.read(:app_name =&gt; :testing, :space =&gt; :String)
+      obj.should_not be_nil
+      obj.should == 'A'
+      lambda do
+        Distribunaut::Utils::Rinda.borrow(:app_name =&gt; :testing, :space =&gt; :String) do |tuple|
+          tuple.object.should == 'A'
+          tuple.space.to_s.should match(/(.+)\-onloan\-.+$/)
+          lambda{Distribunaut::Utils::Rinda.read(:app_name =&gt; :testing, :space =&gt; :String)}.should raise_error(Rinda::RequestExpiredError)
+          raise Distribunaut::TestingError.new
+        end
+      end.should raise_error(Distribunaut::TestingError)
+      
+      obj = Distribunaut::Utils::Rinda.read(:app_name =&gt; :testing, :space =&gt; :String)
+      obj.should_not be_nil
+      obj.should == 'A'
+    end
+    
+  end
+  
+  describe 'read' do
+    
+    it 'should return a tuple from the ring server' do
+      Distribunaut::Utils::Rinda.register_or_renew(:app_name =&gt; :testing, :space =&gt; :String, :object =&gt; 'A', :description =&gt; &quot;AAA&quot;)
+      obj = Distribunaut::Utils::Rinda.read(:app_name =&gt; :testing, :space =&gt; :String)
+      obj.should_not be_nil
+      obj.should == 'A'
+      lambda {Distribunaut::Utils::Rinda.read(:app_name =&gt; :testing, :space =&gt; :String2)}.should raise_error(Rinda::RequestExpiredError)
+    end
+    
+  end
+  
   describe 'register' do
     
     it &quot;should be able to register new service&quot; do</diff>
      <filename>spec/distribunaut/utils/rinda_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,15 +8,20 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'distribunaut')
 
 configatron.distribunaut.app_name = :test_app
 
+$test_ring_server_started = false
+
 Spec::Runner.configure do |config|
   
   config.before(:all) do
-    begin
-      DRb.start_service
-      Rinda::RingServer.new(Rinda::TupleSpace.new)
-    rescue Errno::EADDRINUSE =&gt; e
-      # it's fine to ignore this, it's expected that it's already running.
-      # all other exceptions should be thrown
+    unless $test_ring_server_started
+      begin
+        DRb.start_service
+        Rinda::RingServer.new(Rinda::TupleSpace.new)
+        $test_ring_server_started = true
+      rescue Exception =&gt; e
+        # it's fine to ignore this, it's expected that it's already running.
+        # all other exceptions should be thrown
+      end
     end
   end
   
@@ -48,3 +53,8 @@ class String
   end
   
 end
+
+module Distribunaut
+  class TestingError &lt; StandardError
+  end
+end</diff>
      <filename>spec/spec_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f804b4b3eccc2f79b6d8d22f65caf938b850351b</id>
    </parent>
  </parents>
  <author>
    <name>Mark Bates</name>
    <email>mark@markbates.com</email>
  </author>
  <url>http://github.com/markbates/distribunaut/commit/cc0245d9dfd977ac40d8ac80955220dc0ecc1e68</url>
  <id>cc0245d9dfd977ac40d8ac80955220dc0ecc1e68</id>
  <committed-date>2009-06-26T18:42:27-07:00</committed-date>
  <authored-date>2009-06-26T18:42:27-07:00</authored-date>
  <message>Added the ability to borrow a service.</message>
  <tree>e679439fd51332e6ae3ca3e72cb75564e1dcf1ff</tree>
  <committer>
    <name>Mark Bates</name>
    <email>mark@markbates.com</email>
  </committer>
</commit>
