|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.sadun.util.pool.ObjectPool org.sadun.util.pool2.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:
acquire()
method cannot be cast to the original class directly, but to the PooledObject
interface.
_getOriginal()
on the returned object, and must be released by _releaseOriginal()
.
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();.
Nested Class Summary | |
static class |
ObjectPool.DefaultPassivationManagerFactory
An ObjectPool.PassivationManagerFactory which
produces DefaultPassivationManager s |
protected static class |
ObjectPool.PassivationManagerFactory
A base class for a factory of BasePassivationManager s.
|
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 |
public ObjectPool(java.lang.String poolName, Configuration configuration, java.lang.Class objectType) throws ObjectPool.ObjectPoolException
Configuration
(which also provides
the size of the pool).
The objects are created by invoking their default constructor.
poolName
- the name of the poolconfiguration
- a Configuration
objectobjectType
- the class of objects to createpublic ObjectPool(java.lang.String poolName, Configuration configuration, java.lang.Class objectType, Setup setupObject) throws ObjectPool.ObjectPoolException
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
.
poolName
- the name of the poolconfiguration
- a Configuration
objectobjectType
- the class of objects to createsetupObject
- the Setup object
used
for post-construction setuppublic ObjectPool(java.lang.String poolName, Configuration configuration, java.lang.Class objectType, java.lang.Object[] params)
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.
poolName
- the name of the poolconfiguration
- a Configuration
objectobjectType
- the class of objects to createparams
- the array of parameters used for constructing the objectpublic ObjectPool(java.lang.String poolName, Configuration configuration, java.lang.Class objectType, java.lang.Object[] params, Setup setupObject) throws ObjectPool.ObjectPoolException
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
.
poolName
- the name of the poolconfiguration
- a Configuration
objectobjectType
- the class of objects to createparams
- the array of parameters used for constructing the objectsetupObject
- the Setup object
used
for post-construction setuppublic ObjectPool(java.lang.String poolName, int n, java.lang.Class objectType, java.lang.Object[] params)
Configuration
.
The objects are created by invoking the constructor matching the types of the given parameter objects.
n
- the number of objects to createpoolName
- the name of the poolobjectType
- the class of objects to createparams
- the array of parameters used for constructing the objectpublic ObjectPool(java.lang.String poolName, int n, java.lang.Class objectType)
Configuration
.
The objects are created by invoking their default constructor.
n
- the number of objects to createpoolName
- the name of the poolobjectType
- the class of objects to createpublic ObjectPool(java.lang.String poolName, Configuration configuration, ObjectPool.Factory factory) throws ObjectPool.ObjectPoolException
Configuration
(which also provides
the size of the pool).
The objects are created by using the given object factory
.
poolName
- the name of the poolconfiguration
- a Configuration
objectfactory
- the object factory
which produces the instances to pool.Method Detail |
public static java.io.PrintStream getDefaultLogStream()
public static void setDefaultLogStream(java.io.PrintStream defaultLogStream)
defaultLogStream
- The defaultLogStream to setpublic java.io.PrintStream getLogStream()
public void setLogStream(java.io.PrintStream logStream)
logStream
- The logStream to setpublic Configuration getConfiguration()
public PooledObject acquireInstance()
acquire()
to the PooledObject
type.
acquire()
public java.lang.String getName()
public void dispose()
public BasePassivationManager getPassivationManager()
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |