common-pool 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/CHANGELOG +5 -1
  2. data/README +41 -22
  3. data/lib/common_pool.rb +5 -3
  4. metadata +2 -2
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
- *0.5.0* (14th May 2007)
1
+ *0.3.1* (16th May 2007)
2
+
3
+ * Return validation_timeout and idle_check_status as part of status_info returned
4
+
5
+ *0.3.0* (14th May 2007)
2
6
 
3
7
  * First release
data/README CHANGED
@@ -1,51 +1,70 @@
1
1
  == common-pool
2
2
 
3
- Object pooling with idle objects eviction check similar with Apache Common Pool.
3
+ First in first out (FIFO) object pooling mechanism with idle objects eviction check, similar with {Apache Common Pool}[link:http://jakarta.apache.org/commons/pool/].
4
4
 
5
- Links:
6
- * http://common-pool.rubyforge.org
7
- * http://www.pluitsolutions.com/common-pool
5
+ It supports the following configuration parameters:
6
+ * min_idle
7
+ * max_idle
8
+ * max_idle_time
9
+ * max_active
10
+ * timeout
11
+ * validation_timeout
12
+ * idle_check_no_per_run
13
+ * idle_check_interval
14
+
15
+ Overwrite <code>CommonPool::PoolDataSource</code> to create object to be returned to the pool.
8
16
 
9
- == INSTALLATION
17
+ == Installation
10
18
 
11
19
  $ gem install common-pool
12
20
 
13
- == EXAMPLE
21
+ == Example
14
22
 
15
23
  require 'common_pool'
16
-
24
+
17
25
  # Extend data source object
18
26
  class RandomNumberDataSource < CommonPool::PoolDataSource
19
27
  # Overwrite to return object to be stored in the pool.
20
28
  def create_object
21
29
  rand(1000)
22
30
  end
23
-
31
+
24
32
  # Overwrite to check if idle object in the pool is still valid.
25
33
  def valid?(object)
26
34
  true
27
35
  end
28
36
  end
29
-
37
+
30
38
  # Create a new object pool
31
39
  object_pool = ObjectPool.new(RandomNumberDataSource.new)
32
-
33
- # Borrow and return an object from the pool
40
+
41
+ # Borrow object from the pool
34
42
  object = object_pool.borrow_object
43
+
44
+ # Return object to the pool
35
45
  object_pool.return_object(object)
36
-
37
- # Borrow and invalidate object
38
- object = object_pool.borrow_object
39
- object_pool.return_object(object)
40
-
46
+
47
+ # Or invalidate object and remove it from the pool
48
+ object_pool.invalidate_object(object)
49
+
41
50
  # Create object pool with idle objects eviction thread
42
51
  object_pool = ObjectPool.new(RandomNumberDataSource.new) do |config|
43
52
  config.min_idle = 5
44
53
  config.max_idle = 10
45
- config.idle_check_no_per_run = 10 # check max 10 idle objects per run
46
- config.idle_check_interval = 10 * 60 # check every 10 minutes
54
+
55
+ # max 10 idle objects checked per run
56
+ config.idle_check_no_per_run = 10
57
+
58
+ # check idle objects every 10 minutes
59
+ config.idle_check_interval = 10 * 60
47
60
  end
48
-
49
- # Return a hash of pool instance status variables, including active and idle objects list and
50
- # configuration options
51
- object_pool.status_info
61
+
62
+ # Return a hash of pool instance status variables, i.e.
63
+ # active and idle lists size, and configuration options
64
+ object_pool.status_info
65
+
66
+ == Links
67
+ * http://www.rubyforge.org/projects/common-pool
68
+ * http://www.pluitsolutions.com/common-pool
69
+
70
+
@@ -42,7 +42,7 @@ module CommonPool
42
42
  # Maximum number of active objects in the pool. Default: 8.
43
43
  attr_accessor :max_active
44
44
 
45
- # Request timeout when creating object for the pool, timeout in seconds. Default: 30.
45
+ # Request timeout when creating object for the pool, timeout in seconds. Default: 60.
46
46
  # If set to 0 or less, there will be no timeout.
47
47
  attr_accessor :timeout
48
48
 
@@ -73,13 +73,14 @@ module CommonPool
73
73
  self.max_active = 8
74
74
  self.idle_check_no_per_run = 3
75
75
  self.idle_check_interval= 0
76
- self.timeout = 30
76
+ self.timeout = 60
77
77
  self.validation_timeout = 30
78
78
  end
79
79
 
80
80
  # Convert configuration properties to hash object.
81
81
  def to_hash
82
82
  { :timeout => self.timeout,
83
+ :validation_tmeout => self.validation_timeout,
83
84
  :min_idle => self.min_idle,
84
85
  :max_idle => self.max_idle,
85
86
  :max_idle_time => self.max_idle_time,
@@ -253,7 +254,8 @@ module CommonPool
253
254
  # Return a hash of active and idle objects size with pool instance configuration options.
254
255
  def status_info
255
256
  {:active_objects => @active_list.size,
256
- :idle_objects => @idle_list.size}.merge(self.config.to_hash)
257
+ :idle_objects => @idle_list.size,
258
+ :idle_check_status => @idle_check_status}.merge(self.config.to_hash)
257
259
  end
258
260
 
259
261
  # Check if an idle object is valid, return false if <code>validation_timeout</code> period reached.
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: common-pool
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2007-05-14 00:00:00 +08:00
6
+ version: 0.3.1
7
+ date: 2007-05-16 00:00:00 +08:00
8
8
  summary: Common Pool - Object Pooling
9
9
  require_paths:
10
10
  - lib