ComponentAdapter implementation that pools components.
The implementation utilizes a delegated ComponentAdapter to create the instances of the pool. The
pool can be configured to grow unlimited or to a maximum size. If a component is requested from
this adapter, the implementation returns an availailabe instance from the pool or will create a
new one, if the maximum pool size is not reached yet. If none is available, the implementation
can wait a defined time for a returned object before it throws a
PoolException .
This implementation uses the
Pool toy from the ProxyToys project. This ensures, that any component,
that is out of scope will be automatically returned to the pool by the garbage collector.
Additionally will every component instance also implement
com.thoughtworks.proxy.toys.pool.Poolable , that can be used to return the instance
manually. After returning an instance it should not be used in client code anymore.
Before a returning object is added to the available instances of the pool again, it should be
reinitialized to a normalized state. By providing a proper Resetter implementation this can be
done automatically. If the object cannot be reused anymore it can also be dropped and the pool
may request a new instance.
The pool supports components with a lifecycle. If the delegated
ComponentAdapter implements a
LifecycleStrategy , any component retrieved form the pool will be started
before and stopped again, when it returns back into the pool. Also if a component cannot be
resetted it will automatically be disposed. If the container of the pool is disposed, that any
returning object is also disposed and will not return to the pool anymore. Note, that current
implementation cannot dispose pooled objects.
author: Jörg Schaible author: Aslak Hellesøy |