public
Description: Ruby Common Pool
Homepage: http://www.pluitsolutions.com/projects/common-pool
Clone URL: git://github.com/jugend/common-pool.git
Herryanto Siatono (author)
Fri Jan 23 20:09:59 -0800 2009
name age message
file CHANGELOG Fri Jan 23 19:59:59 -0800 2009 first commit [Herryanto Siatono]
file MIT-LICENSE Fri Jan 23 19:59:59 -0800 2009 first commit [Herryanto Siatono]
file README Fri Jan 23 20:09:59 -0800 2009 Add github link [Herryanto Siatono]
file Rakefile Fri Jan 23 19:59:59 -0800 2009 first commit [Herryanto Siatono]
directory doc/ Fri Jan 23 19:59:59 -0800 2009 first commit [Herryanto Siatono]
directory lib/ Fri Jan 23 19:59:59 -0800 2009 first commit [Herryanto Siatono]
directory pkg/ Fri Jan 23 19:59:59 -0800 2009 first commit [Herryanto Siatono]
directory test/ Fri Jan 23 19:59:59 -0800 2009 first commit [Herryanto Siatono]
README
== common-pool

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/].

It supports the following configuration parameters:
* min_idle
* max_idle
* max_idle_time
* max_active
* timeout
* validation_timeout
* idle_check_no_per_run
* idle_check_interval

Overwrite <code>CommonPool::PoolDataSource</code> to create object to be returned to the pool.

== Installation

  $ gem install common-pool

== Example

  require 'common_pool'    
  
  # Extend data source object
  class RandomNumberDataSource < CommonPool::PoolDataSource
    # Overwrite to return object to be stored in the pool.
    def create_object
      rand(1000)
    end
    
    # Overwrite to check if idle object in the pool is still valid.
    def valid?(object)
      true
    end
  end
  
  # Create a new object pool
  object_pool = ObjectPool.new(RandomNumberDataSource.new)
  
  # Borrow object from the pool
  object = object_pool.borrow_object

  # Return object to the pool
  object_pool.return_object(object)
  
  # Or invalidate object and remove it from the pool
  object_pool.invalidate_object(object)
  
  # Create object pool with idle objects eviction thread
  object_pool = ObjectPool.new(RandomNumberDataSource.new) do |config|
    config.min_idle = 5
    config.max_idle = 10
  
    # max 10 idle objects checked per run
    config.idle_check_no_per_run = 10

    # check idle objects every 10 minutes
    config.idle_check_interval = 10 * 60
  end

  # Return a hash of pool instance status variables, i.e.
  # active and idle lists size, and configuration options
  object_pool.status_info

== Source Codes
http://github.com/jugend/common-pool/tree/master

== Links
* http://www.pluitsolutions.com/common-pool