org.sadun.util.pool2
Class ObjectPool

java.lang.Object
  extended byorg.sadun.util.pool.ObjectPool
      extended byorg.sadun.util.pool2.ObjectPool
All Implemented Interfaces:
java.io.Serializable

public class ObjectPool
extends ObjectPool

NOT COMPLETE YET.

A pool of object which handles transparent passivation/activation.

This pool create and allocate pooled objects referencing the original objects and implementing the same interface(s).

The pool can be used either accessing objects by interface or by class.

The given object class should implement one or more specific interface(s). The instances returned by the acquire() method can be directly cast to that interface(s). For example, if a class MyTestObject implements the javax.swing.Action interface, the following code can be used:

  ObjectPool pool = new ObjectPool("test pool", 10, MyTestObject.class);
  ...
  Action action = (Action)pool.acquire();
  Object obj = action.getValue();
  ...
  action.release();
  ...
  pool.dispose();
 

If the given object is used directly as a class (rather than interface), the following conditions hold:

For example:

   ObjectPool pool = new ObjectPool("test pool", 10, MyTestObject.class);
   ...
   PooledObject pObj = (PooledObject)pool.acquire();
   MyTestObject obj = (MyTestObject)pObj._getOriginal();
   obj.myTestMethod();
   pObj._releaseOriginal();
 
.

Version:
1.0
Author:
Cristiano Sadun
See Also:
Serialized Form

Nested Class Summary
static class ObjectPool.DefaultPassivationManagerFactory
          An ObjectPool.PassivationManagerFactory which produces DefaultPassivationManagers
protected static class ObjectPool.PassivationManagerFactory
          A base class for a factory of BasePassivationManagers.
protected static class ObjectPool.PooledObjectFactory
          A object factory which produces BasePooledObject wrappers for other classes.
 
Nested classes inherited from class org.sadun.util.pool.ObjectPool
ObjectPool.BaseFactory, ObjectPool.Factory, ObjectPool.ObjectFactory, ObjectPool.ObjectPoolException, ObjectPool.PooledObjectWrapper
 
Field Summary
 
Fields inherited from class org.sadun.util.pool.ObjectPool
free, pool, used
 
Constructor Summary
ObjectPool(java.lang.String poolName, Configuration configuration, java.lang.Class objectType)
          Create a named object pool of objects of the given class and the given Configuration (which also provides the size of the pool).
ObjectPool(java.lang.String poolName, Configuration configuration, java.lang.Class objectType, java.lang.Object[] params)
          Create a named object pool of objects of the given class and the given Configuration (which also provides the size of the pool).
ObjectPool(java.lang.String poolName, Configuration configuration, java.lang.Class objectType, java.lang.Object[] params, Setup setupObject)
          Create a named object pool of objects of the given class and the given Configuration (which also provides the size of the pool).
ObjectPool(java.lang.String poolName, Configuration configuration, java.lang.Class objectType, Setup setupObject)
          Create a named object pool of objects of the given class and the given Configuration (which also provides the size of the pool).
ObjectPool(java.lang.String poolName, Configuration configuration, ObjectPool.Factory factory)
          Create a named object pool of objects of the given class and the given Configuration (which also provides the size of the pool).
ObjectPool(java.lang.String poolName, int n, java.lang.Class objectType)
          Create a named object pool of n objects of the given class and a default Configuration.
ObjectPool(java.lang.String poolName, int n, java.lang.Class objectType, java.lang.Object[] params)
          Create a named object pool of n objects of the given class and a default Configuration.
 
Method Summary
 PooledObject acquireInstance()
          A convenience method which already casts the result of acquire() to the PooledObject type.
 void dispose()
           
 Configuration getConfiguration()
          Returns the configuration.
static java.io.PrintStream getDefaultLogStream()
          Returns the defaultLogStream.
 java.io.PrintStream getLogStream()
          Returns the logStream.
 java.lang.String getName()
          Returns the name.
 BasePassivationManager getPassivationManager()
          Returns the passivationManager.
static void main(java.lang.String[] args)
          Test method
static void setDefaultLogStream(java.io.PrintStream defaultLogStream)
          Sets the defaultLogStream.
 void setLogStream(java.io.PrintStream logStream)
          Sets the logStream.
 
Methods inherited from class org.sadun.util.pool.ObjectPool
acquire, acquire, acquire, destroy, getFactory, getFreeCount, getObjectType, getSize, getUsedCount, newPool, newPool, release, release, release, renew, setFactory, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectPool

public ObjectPool(java.lang.String poolName,
                  Configuration configuration,
                  java.lang.Class objectType)
           throws ObjectPool.ObjectPoolException
Create a named object pool of objects of the given class and the given Configuration (which also provides the size of the pool).

The objects are created by invoking their default constructor.

Parameters:
poolName - the name of the pool
configuration - a Configuration object
objectType - the class of objects to create

ObjectPool

public ObjectPool(java.lang.String poolName,
                  Configuration configuration,
                  java.lang.Class objectType,
                  Setup setupObject)
           throws ObjectPool.ObjectPoolException
Create a named object pool of objects of the given class and the given Configuration (which also provides the size of the pool).

The objects are created by invoking their default constructor.

After the creation, each object is passed by the given Setup object.

Parameters:
poolName - the name of the pool
configuration - a Configuration object
objectType - the class of objects to create
setupObject - the Setup object used for post-construction setup

ObjectPool

public ObjectPool(java.lang.String poolName,
                  Configuration configuration,
                  java.lang.Class objectType,
                  java.lang.Object[] params)
Create a named object pool of objects of the given class and the given Configuration (which also provides the size of the pool).

The objects are created by invoking the constructor matching the types of the given parameter objects.

Parameters:
poolName - the name of the pool
configuration - a Configuration object
objectType - the class of objects to create
params - the array of parameters used for constructing the object

ObjectPool

public ObjectPool(java.lang.String poolName,
                  Configuration configuration,
                  java.lang.Class objectType,
                  java.lang.Object[] params,
                  Setup setupObject)
           throws ObjectPool.ObjectPoolException
Create a named object pool of objects of the given class and the given Configuration (which also provides the size of the pool).

The objects are created by invoking the constructor matching the types of the given parameter objects.

After the creation, each object is passed by the given Setup object.

Parameters:
poolName - the name of the pool
configuration - a Configuration object
objectType - the class of objects to create
params - the array of parameters used for constructing the object
setupObject - the Setup object used for post-construction setup

ObjectPool

public ObjectPool(java.lang.String poolName,
                  int n,
                  java.lang.Class objectType,
                  java.lang.Object[] params)
Create a named object pool of n objects of the given class and a default Configuration.

The objects are created by invoking the constructor matching the types of the given parameter objects.

Parameters:
n - the number of objects to create
poolName - the name of the pool
objectType - the class of objects to create
params - the array of parameters used for constructing the object

ObjectPool

public ObjectPool(java.lang.String poolName,
                  int n,
                  java.lang.Class objectType)
Create a named object pool of n objects of the given class and a default Configuration.

The objects are created by invoking their default constructor.

Parameters:
n - the number of objects to create
poolName - the name of the pool
objectType - the class of objects to create

ObjectPool

public ObjectPool(java.lang.String poolName,
                  Configuration configuration,
                  ObjectPool.Factory factory)
           throws ObjectPool.ObjectPoolException
Create a named object pool of objects of the given class and the given Configuration (which also provides the size of the pool).

The objects are created by using the given object factory.

Parameters:
poolName - the name of the pool
configuration - a Configuration object
factory - the object factory which produces the instances to pool.
Method Detail

getDefaultLogStream

public static java.io.PrintStream getDefaultLogStream()
Returns the defaultLogStream.

Returns:
PrintStream

setDefaultLogStream

public static void setDefaultLogStream(java.io.PrintStream defaultLogStream)
Sets the defaultLogStream.

Parameters:
defaultLogStream - The defaultLogStream to set

getLogStream

public java.io.PrintStream getLogStream()
Returns the logStream.

Returns:
PrintStream

setLogStream

public void setLogStream(java.io.PrintStream logStream)
Sets the logStream.

Parameters:
logStream - The logStream to set

getConfiguration

public Configuration getConfiguration()
Returns the configuration.

Returns:
Configuration

acquireInstance

public PooledObject acquireInstance()
A convenience method which already casts the result of acquire() to the PooledObject type.

Returns:
one object in the pool, obtained invoking acquire()

getName

public java.lang.String getName()
Returns the name.

Returns:
String

dispose

public void dispose()

getPassivationManager

public BasePassivationManager getPassivationManager()
Returns the passivationManager.

Returns:
BasePassivationManager

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test method

Throws:
java.lang.Exception