sam / do fork watch download tarball
public
Rubygem
Description: DataObjects
Homepage: http://rubyforge.org/projects/dorb
Clone URL: git://github.com/sam/do.git
More pooling work.
sam (author)
Wed May 07 11:59:48 -0700 2008
commit  069209c8bce372338ca37ea3c0c3437972f9705f
tree    d9e58311c177eefd649a65b8e914d242d4c644f1
parent  721c5d3bf12a6d9f8b76f3757b1a29f0c48c3de3
...
19
20
21
 
 
 
 
22
23
24
...
47
48
49
 
50
51
52
...
63
64
65
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
68
69
...
73
74
75
 
 
 
76
77
78
...
19
20
21
22
23
24
25
26
27
28
...
51
52
53
54
55
56
57
...
68
69
70
 
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
109
110
111
112
113
114
115
116
117
0
@@ -19,6 +19,10 @@ class Object
0
       target.extend(ClassMethods)
0
     end
0
     
0
+ def release
0
+ self.class.release(self)
0
+ end
0
+
0
     class Pools
0
       
0
       attr_reader :type
0
@@ -47,6 +51,7 @@ class Object
0
       
0
         def initialize(type)
0
           @type = type
0
+ @mutex = Mutex.new
0
           @available = []
0
           @reserved = []
0
         end
0
@@ -63,7 +68,38 @@ class Object
0
           @available = []
0
           @reserved = []
0
         end
0
-
0
+
0
+ def self.acquire(connection_uri)
0
+ conn = nil
0
+ connection_string = connection_uri.to_s
0
+
0
+ @connection_lock.synchronize do
0
+ unless @available_connections[connection_string].empty?
0
+ conn = @available_connections[connection_string].pop
0
+ else
0
+ conn = allocate
0
+ conn.send(:initialize, connection_uri)
0
+ at_exit { conn.real_close }
0
+ end
0
+
0
+ @reserved_connections << conn
0
+ end
0
+
0
+ return conn
0
+ end
0
+
0
+ def self.release(connection)
0
+ @connection_lock.synchronize do
0
+ if @reserved_connections.delete?(connection)
0
+ @available_connections[connection.to_s] << connection
0
+ end
0
+ end
0
+ return nil
0
+ end
0
+
0
+ private
0
+ def synchronize
0
+ end
0
       end
0
     end
0
     
0
@@ -73,6 +109,9 @@ class Object
0
         unless instance_methods.include?("dispose")
0
           raise MustImplementDisposeError.new("#{self.name} must implement a `dispose' instance-method.")
0
         end
0
+
0
+ # uri = uri.is_a?(String) ? Addressable::URI::parse(uri) : uri
0
+ # DataObjects.const_get(uri.scheme.capitalize)::Connection.acquire(uri)
0
       end
0
       
0
       def pools
...
24
25
26
 
 
 
 
 
27
28
29
...
64
65
66
67
68
69
70
71
...
83
84
85
 
 
86
87
...
24
25
26
27
28
29
30
31
32
33
34
...
69
70
71
 
 
72
73
74
...
86
87
88
89
90
91
92
0
@@ -24,6 +24,11 @@ describe "Object::Pooling" do
0
     Object::Pooling::size.should == 4
0
   end
0
   
0
+ it "should respond to ::new and #release" do
0
+ Thing.should respond_to(:new)
0
+ Thing.instance_methods.should include("release")
0
+ end
0
+
0
   it "should raise an error if the target object doesn't implement a `dispose' method" do
0
     lambda do
0
       class Durian
0
@@ -64,8 +69,6 @@ describe "Object::Pooling" do
0
     fred.release
0
   end
0
   
0
- it "should dispose idle available objects"
0
-
0
   it "should allow you to flush all pools, or an individual pool" do
0
     pending
0
     
0
@@ -83,4 +86,6 @@ describe "Object::Pooling" do
0
     
0
     Thing::pools['bob'].flush!
0
   end
0
+
0
+ it "should dispose idle available objects"
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.