org.carrot2.util.pool
Class FixedSizePool<T,P>

java.lang.Object
  extended by org.carrot2.util.pool.FixedSizePool<T,P>
All Implemented Interfaces:
IParameterizedPool<T,P>

public final class FixedSizePool<T,P>
extends Object
implements IParameterizedPool<T,P>

An object pool storing hard references to a fixed number of instantiated objects at the given key. The objects are never released from the pool until dispose() is called.


Constructor Summary
FixedSizePool(int listSizePerKey)
           
 
Method Summary
<I extends T>
I
borrowObject(Class<I> clazz, P parameter)
          Borrows an object from the pool.
 void dispose()
          Disposes of the pool.
 void init(IInstantiationListener<T,P> objectInstantiationListener, IActivationListener<T,P> objectActivationListener, IPassivationListener<T,P> objectPassivationListener, IDisposalListener<T,P> objectDisposalListener)
          Initialize listeners.
 void returnObject(T object, P parameter)
          Returns an object to the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedSizePool

public FixedSizePool(int listSizePerKey)
Parameters:
listSizePerKey - Each key in the pool points to a list of instances. This field defines how many components are kept for each key.
Method Detail

init

public void init(IInstantiationListener<T,P> objectInstantiationListener,
                 IActivationListener<T,P> objectActivationListener,
                 IPassivationListener<T,P> objectPassivationListener,
                 IDisposalListener<T,P> objectDisposalListener)
Initialize listeners.

Specified by:
init in interface IParameterizedPool<T,P>

borrowObject

public <I extends T> I borrowObject(Class<I> clazz,
                                    P parameter)
                         throws InstantiationException,
                                IllegalAccessException
Description copied from interface: IParameterizedPool
Borrows an object from the pool. If no instance is available, a parameterless constructor should be used to create a new one.

Specified by:
borrowObject in interface IParameterizedPool<T,P>
Parameters:
clazz - class of object to be borrowed
parameter - 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 IParameterizedPool.borrowObject(Class, Object) and IParameterizedPool.returnObject(Object, Object) methods.
Throws:
InstantiationException
IllegalAccessException

returnObject

public void returnObject(T object,
                         P parameter)
Description copied from interface: IParameterizedPool
Returns an object to the pool.

Specified by:
returnObject in interface IParameterizedPool<T,P>
Parameters:
object - object to return
parameter - parameter provided when borrowing the object. If the parameter was not null when borrowing the object, the same value will be passed here.

dispose

public void dispose()
Description copied from interface: IParameterizedPool
Disposes of the pool. No objects can be borrowed from the pool after disposed.

Specified by:
dispose in interface IParameterizedPool<T,P>


Copyright (c) Dawid Weiss, Stanislaw Osinski