org.carrot2.util.pool.IParameterizedPool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of carrot2-mini Show documentation
Show all versions of carrot2-mini Show documentation
Carrot2 search results clustering framework. Minimal functional subset
(core algorithms and infrastructure, no document sources).
/*
* Carrot2 project.
*
* Copyright (C) 2002-2016, Dawid Weiss, Stanisław Osiński.
* All rights reserved.
*
* Refer to the full license file "carrot2.LICENSE"
* in the root folder of the repository checkout or at:
* http://www.carrot2.org/carrot2.LICENSE
*/
package org.carrot2.util.pool;
/**
* A parameterized pool of objects. Each borrowed object is characterized by its class and
* an arbitrary parameter. The [class, parameter] pair uniquely identifies a "class"
* (equivalence class) of pooled objects.
*
* Please see {@link SoftUnboundedPool} for a reference implementation.
*
*/
public interface IParameterizedPool
{
/**
* 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.
*/
public void init(IInstantiationListener objectInstantiationListener,
IActivationListener objectActivationListener,
IPassivationListener objectPassivationListener,
IDisposalListener objectDisposalListener);
/**
* Borrows an object from the pool. If no instance is available, a parameterless
* constructor should be used to create a new one.
*
* @param clazz class of object to be borrowed
* @param 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
* {@link Object#equals(Object)} and {@link 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
* {@link #borrowObject(Class, Object)} and
* {@link #returnObject(Object, Object)} methods.
*/
public I borrowObject(Class clazz, P parameter)
throws InstantiationException, IllegalAccessException;
/**
* Returns an object to the pool.
*
* @param object object to return
* @param parameter parameter provided when borrowing the object. If the parameter was
* not null
when borrowing the object, the same value will be
* passed here.
*/
public void returnObject(T object, P parameter);
/**
* Disposes of the pool. No objects can be borrowed from the pool after disposed.
*/
public void dispose();
}