|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.thoughtworks.proxy.toys.pool.Pool
public class Pool
A simple pool implementation that collects its unused components of a specific type automatically.
The pool will only manage instances that were explicitly passed into the pool before. For more sophisticated pooling strategies, derive from this class or wrap it.
The implementation will provide these instances wrapped by a proxy, that will return the instance automatically to
the pool, if it falls out of scope and is collected by the garbage collector. Since the pool only returns instances
wrapped by a proxy that implements the Poolable
interface, this can be used to release th instance manually
to the pool also. With an implementation of the Resetter
interface each element's status can be reset or the
element can be dropped from the pool at all, if it is exhausted.
A client can use the pool's monitor for an improved synchronization. Everytime an object is returned to the pool, all
waiting Threads of the monitor will be notified. This notification will happen independently of the result of the
Resetter.reset(Object)
method.
com.thoughtworks.proxy.toys.pool
,
Serialized FormNested Class Summary | |
---|---|
protected static class |
Pool.PoolingInvoker
The Invoker of the proxy. |
Field Summary | |
---|---|
static int |
SERIALIZATION_FORCE
SERIALIZATION_FORCE is the value for serialization of the pool with or without serializable
objects. |
static int |
SERIALIZATION_NONE
SERIALIZATION_NONE is the value for serialization of the pool without the objects. |
static int |
SERIALIZATION_STANDARD
SERIALIZATION_STANDARD is the value for the standard serialization of the pool with its objects. |
Constructor Summary | |
---|---|
Pool(Class type,
Resetter resetter)
Construct an Pool using the StandardProxyFactory . |
|
Pool(Class type,
Resetter resetter,
ProxyFactory proxyFactory)
Construct a populated Pool with a specific proxy factory. |
|
Pool(Class type,
Resetter resetter,
ProxyFactory proxyFactory,
int serializationMode)
Construct a populated Pool with a specific proxy factory and a serialization mode. |
Method Summary | |
---|---|
void |
add(Object instance)
Add a new instance as resource to the pool. |
void |
add(Object[] instances)
Add an array of new instances as resources to the pool. |
Object |
get()
Get an instance from the pool. |
int |
getAvailable()
Return the number of available instances of the pool. |
void |
release(Object object)
Release a pool instance manually. |
int |
size()
Retrieve the number of instances managed by the pool. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SERIALIZATION_FORCE
SERIALIZATION_FORCE
is the value for serialization of the pool with or without serializable
objects. If the obejcts cannot be serialized, the pool is emtpy after serialization und must be populated again.
public static final int SERIALIZATION_STANDARD
SERIALIZATION_STANDARD
is the value for the standard serialization of the pool with its objects.
If the obejcts cannot be serialized, a NotSerializableException
is thrown.
public static final int SERIALIZATION_NONE
SERIALIZATION_NONE
is the value for serialization of the pool without the objects. The pool is
emtpy after serialization und must be populated again.
Constructor Detail |
---|
public Pool(Class type, Resetter resetter)
StandardProxyFactory
.
type
- the type of the instancesresetter
- the resetter of the pooled elementspublic Pool(Class type, Resetter resetter, ProxyFactory proxyFactory)
type
- the type of the instancesresetter
- the resetter of the pooled elementsproxyFactory
- the proxy factory to usepublic Pool(Class type, Resetter resetter, ProxyFactory proxyFactory, int serializationMode)
SERIALIZATION_STANDARD
: the standard mode, i.e. all elements of the pool are also serialized and a
NotSerializableException
may thrownSERIALIZATION_NONE
: no element of the pool is also serialized and it must be populated again after
serializationSERIALIZATION_FORCE
: all element of the pool are serialized, if possible. Otherwise the pool is
empty after serialization and must be populated again.
type
- the type of the instancesresetter
- the resetter of the pooled elementsproxyFactory
- the proxy factory to useserializationMode
- true
if serialization is done even if the pooled objects are not
serializable. The deserialized Pool will not have any objects in the Pool though.
IllegalArgumentException
- if the serialization mode is not one of the predefined valuesMethod Detail |
---|
public void add(Object instance)
instance
- the new instance
NullPointerException
- if instance is null
public void add(Object[] instances)
instances
- the instances
NullPointerException
- if instance is null
public Object get()
System.gc()
first.
public void release(Object object)
object
- the instance to release
ClassCastException
- if object was not Poolable
.
IllegalArgumentException
- if the object was not from this pool.public int getAvailable()
System.gc()
first. The pool's monitor
will be notified, if any object was collected and the Resetter
retunred the object.
public int size()
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |