Package org.vibur.objectpool
Interface PoolObjectFactory<T>
- Type Parameters:
T- the type of objects held in the client object pool
public interface PoolObjectFactory<T>
Defines the interface that will be implemented by the factory used by the object pools
defined in the package, in order to control the lifecycle of the objects in the pools.
- Author:
- Simeon Malchev
-
Method Summary
Modifier and TypeMethodDescriptioncreate()Creates a new object for the calling object pool.voidA method which will be called when an object from the object pool needs to be destroyed, which is when thereadyToTake(T)orreadyToRestore(T)methods have returnedfalse, or when the pool is shrinking its size (via callingreduceCreatedBy/To), or when the pool is terminating.booleanreadyToRestore(T obj) A validation/passivation hook which will be called by therestoremethods ofConcurrentPoolwhen an object taken before that from the object pool is about to be restored (returned back) to the pool.booleanreadyToTake(T obj) A validation/activation hook which will be called by thetake...methods ofConcurrentPoolwhen an object from the object pool is requested by the application.
-
Method Details
-
create
T create()Creates a new object for the calling object pool. This object is presumed to be ready (and valid) for immediate use. Should never returnnull.This method will be called by the constructors of
ConcurrentPool, and by any of itstake...methods if they were able to obtain a permit from the countingSemaphoreguarding the pool, but there was no ready and valid object in the pool. I.e., this is the case when a new object is created lazily in the pool upon request.- Returns:
- a new object for this object pool
-
readyToTake
A validation/activation hook which will be called by thetake...methods ofConcurrentPoolwhen an object from the object pool is requested by the application. This is an optional operation which concrete implementation may simply always returntrue.If there is a particular activation or validation which needs to be done for the taken from the pool object, this is the ideal place where it can be done.
- Parameters:
obj- an object which is taken from the object pool and which is to be given to the calling application- Returns:
trueif the validation/activation is successful,falseotherwise- See Also:
-
readyToRestore
A validation/passivation hook which will be called by therestoremethods ofConcurrentPoolwhen an object taken before that from the object pool is about to be restored (returned back) to the pool. This is an optional operation which concrete implementation may simply always returntrue.If there is a particular passivation or validation which needs to be done for the restored to the pool object, this is the ideal place where it can be done.
- Parameters:
obj- an object which has been taken before that from this object pool and which is now to be restored to the pool- Returns:
trueif the validation/passivation is successful,falseotherwise- See Also:
-
destroy
A method which will be called when an object from the object pool needs to be destroyed, which is when thereadyToTake(T)orreadyToRestore(T)methods have returnedfalse, or when the pool is shrinking its size (via callingreduceCreatedBy/To), or when the pool is terminating. The simplest implementation of this method may simply do nothing, however if there are any allocated resources associated with the to-be-destroyed object, like network connections or similar, this is the ideal place where they can be de-allocated.- Parameters:
obj- an object from the pool which needs to be destroyed
-