org.carrot2.util.pool
Interface IParameterizedPool<T,P>
- All Known Implementing Classes:
- FixedSizePool, SoftUnboundedPool
public interface IParameterizedPool<T,P>
A parameterized pool of objects. Each borrowed object is characterized by its class and
an arbitrary parameter. The pair uniquely identifies a "class"
(equivalence class) of pooled objects.
Please see SoftUnboundedPool for a reference implementation.
init
void init(IInstantiationListener<T,P> objectInstantiationListener,
IActivationListener<T,P> objectActivationListener,
IPassivationListener<T,P> objectPassivationListener,
IDisposalListener<T,P> objectDisposalListener)
- Initializes the pool with a number of listeners. The appropriate listeners
must be called at the relevant stages of a pooled object's life cycle.
borrowObject
<I extends T> I borrowObject(Class<I> clazz,
P parameter)
throws InstantiationException,
IllegalAccessException
- Borrows an object from the pool. If no instance is available, a parameterless
constructor should be used to create a new one.
- Parameters:
clazz - class of object to be borrowedparameter - additional parameter determining a possible sub type within the
same class of objects being borrowed. A combination of class and
parameter uniquely identifies a "class" (equivalence class) of pooled
objects. The parameter is assumed to correctly implement the
Object.equals(Object) and Object.hashCode() methods. The
parameter can be null. The implementation must pass the
parameter to all listeners when managing the life cycle of the pooled
object. It is the callers responsibility to ensure that exactly the same
value of the parameter is passed to the corresponding
borrowObject(Class, Object) and
returnObject(Object, Object) methods.
- Throws:
InstantiationException
IllegalAccessException
returnObject
void returnObject(T object,
P parameter)
- Returns an object to the pool.
- Parameters:
object - object to returnparameter - parameter provided when borrowing the object. If the parameter was
not null when borrowing the object, the same value will be
passed here.
dispose
void dispose()
- Disposes of the pool. No objects can be borrowed from the pool after disposed.
Copyright (c) Dawid Weiss, Stanislaw Osinski