Skip to content

pharo-ide/ObjectPool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ObjectPool

GitHub release Unit Tests Coverage Status Baseline groups

Pharo 7.0 Pharo 8.0 Pharo 9.0 Pharo 10 Pharo 11

Object Pool offers easy way to build pools for objects. One common situation could be pooling database connections. This library was created for supporting pooling of GlorpDBX database connections. However, GlorpDBX related code is different package.

Objects borrowed from OPPool have following basic lifecycle:

  1. Objects are first created.
  2. When objects are borrowed from pool they are activated.
  3. When objects are returned to pool they are passivated.
  4. When objects are no longer usable (some lifecycle operation fails) or needed it is destroyed.

To create pool for of OrderedCollections one could write:

OPBasicPool new
  creator: [OrderedCollection new].

To get new collection from the pool:

pool withPooled: [:o| "Do something"].

To also clear collections when they are returned add passivator

pool passivator:[:o|o removeAll].

Or to do that before borrow add activator:

pool activator:[:o|o removeAll].

To validate objects before borrow add following. Objects that do not validate are destroyed.

pool validator:[:o|o size = 0].

One can set maximum size of pool with #maxIdleObjects. See more about pool configuration in documentation of OPBasicPool.

Installation

Metacello new
  baseline: 'ObjectPool';
  repository: 'github://pharo-ide/ObjectPool';
  load

Use following snippet for stable dependency in your project baseline:

spec
    baseline: 'ObjectPool'
    with: [ spec repository: 'github://pharo-ide/ObjectPool:v1.0.1' ]