common-pool 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -1
- data/README +41 -22
- data/lib/common_pool.rb +5 -3
- metadata +2 -2
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -1,51 +1,70 @@
|
|
1
1
|
== common-pool
|
2
2
|
|
3
|
-
|
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
|
-
|
6
|
-
*
|
7
|
-
*
|
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
|
-
==
|
17
|
+
== Installation
|
10
18
|
|
11
19
|
$ gem install common-pool
|
12
20
|
|
13
|
-
==
|
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
|
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
|
-
#
|
38
|
-
|
39
|
-
|
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
|
-
|
46
|
-
|
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,
|
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
|
+
|
data/lib/common_pool.rb
CHANGED
@@ -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:
|
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 =
|
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
|
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.
|
7
|
-
date: 2007-05-
|
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
|