T
- the type of objects held in this object poolpublic class ConcurrentHolderLinkedPool<T> extends AbstractValidatingPoolService<T> implements HolderValidatingPoolService<T>
ConcurrentLinkedPool
and is utilising a ConcurrentHashMap
for the validation of the restored objects. The validation checks whether
the currently restored object holder has been taken before that from the object pool,
and whether it is currently in taken state.
The object returned by the take
methods is enclosed in a thin wrapper class which
is created by the object pool and which is implementing the Holder
interface. The
underlying object is accessible via the interface's value()
method.
This object pool provides support for fairness with regards to the waiting taker's threads in
the same way as it is provided by the underlying ConcurrentLinkedPool
.
This object pool has support for shrinking (reduction) of the number of
allocated on the pool objects. This functionality is provided by the underlying
ConcurrentLinkedPool
. Note that the shrinking may reduce the
AbstractValidatingPoolService.createdTotal()
to less than the pool AbstractValidatingPoolService.initialSize()
.
ConcurrentLinkedPool
Constructor and Description |
---|
ConcurrentHolderLinkedPool(PoolObjectFactory<T> poolObjectFactory,
int initialSize,
int maxSize,
boolean fair)
Creates a new
ConcurrentHolderLinkedPool with the given
PoolObjectFactory , initial and max sizes, fairness setting,
and no additional Holder info. |
ConcurrentHolderLinkedPool(PoolObjectFactory<T> poolObjectFactory,
int initialSize,
int maxSize,
boolean fair,
boolean additionalInfo)
Creates a new
ConcurrentHolderLinkedPool with the given
PoolObjectFactory , initial and max sizes, fairness setting,
and additional Holder info. |
Modifier and Type | Method and Description |
---|---|
protected Holder<T> |
newHolder(T object) |
boolean |
restore(Holder<T> holder)
Restores (returns) an object to the object pool.
|
boolean |
restore(Holder<T> holder,
boolean valid)
Restores (returns) an object to the object pool.
|
Holder<T> |
take()
Takes an object from the object pool if there is such available.
|
List<Holder<T>> |
takenHolders()
Returns list of all
Holder objects (i.e the wrappers of the underlying
objects) which are currently (at the moment of the call) in taken state in this object
pool. |
Holder<T> |
takeUninterruptibly()
Takes an object from the object pool if there is such available.
|
Holder<T> |
tryTake()
Tries to take an object from the object pool if there is one which is immediately available.
|
Holder<T> |
tryTake(long timeout,
TimeUnit unit)
Takes an object from the object pool if there is such available.
|
createdTotal, initialSize, isFair, isTerminated, maxSize, reduceCreated, remainingCapacity, terminate
drainCreated, remainingCreated, taken, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createdTotal, drainCreated, initialSize, isFair, isTerminated, maxSize, reduceCreated, remainingCapacity, remainingCreated, taken, terminate
public ConcurrentHolderLinkedPool(PoolObjectFactory<T> poolObjectFactory, int initialSize, int maxSize, boolean fair)
ConcurrentHolderLinkedPool
with the given
PoolObjectFactory
, initial and max sizes, fairness setting,
and no additional Holder
info.poolObjectFactory
- the factory which will be used to create new objects
in this object pool as well as to control their lifecycleinitialSize
- the object pool initial size, i.e. the initial number of
allocated in the object pool objectsmaxSize
- the object pool max size, i.e. the max number of allocated
in the object pool objectsfair
- the object pool's fairness setting with regards to waiting threadsIllegalArgumentException
- if one of the following holds:initialSize < 0 || maxSize < 1 || maxSize < initialSize
NullPointerException
- if poolObjectFactory
is nullpublic ConcurrentHolderLinkedPool(PoolObjectFactory<T> poolObjectFactory, int initialSize, int maxSize, boolean fair, boolean additionalInfo)
ConcurrentHolderLinkedPool
with the given
PoolObjectFactory
, initial and max sizes, fairness setting,
and additional Holder
info.poolObjectFactory
- the factory which will be used to create new objects
in this object pool as well as to control their lifecycleinitialSize
- the object pool initial size, i.e. the initial number of
allocated in the object pool objectsmaxSize
- the object pool max size, i.e. the max number of allocated
in the object pool objectsfair
- the object pool's fairness setting with regards to waiting threadsadditionalInfo
- determines whether the returned object holder will include
information for the current stack traceIllegalArgumentException
- if one of the following holds:initialSize < 0 || maxSize < 1 || maxSize < initialSize
NullPointerException
- if poolObjectFactory
is nullpublic Holder<T> take()
null
and the thread's interrupted status will
be set to true
.take
in interface HolderValidatingPoolService<T>
Holder
interface or null
if was interrupted while waitingpublic Holder<T> takeUninterruptibly()
takeUninterruptibly
in interface HolderValidatingPoolService<T>
Holder
interfacepublic Holder<T> tryTake(long timeout, TimeUnit unit)
timeout
for an object to become available. If the calling
thread is interrupted while waiting this call will return null
and the thread's
interrupted status will be set to true
.tryTake
in interface HolderValidatingPoolService<T>
timeout
- the maximum time to wait for an object to become available in the object poolunit
- the time unit of the timeout
argumentHolder
interface or null
if the specified timeout expires
or if was interrupted while waitingpublic Holder<T> tryTake()
null
if no object is available at the moment of the call.tryTake
in interface HolderValidatingPoolService<T>
Holder
interface or null
if there is no object available in the object poolpublic boolean restore(Holder<T> holder)
false
otherwise will return true
. Equivalent to calling restore(holder, true)
.restore
in interface HolderValidatingPoolService<T>
holder
- a thin wrapper enclosing the object that is to be restored to the object pooltrue
if the underlying object from the given holder
was taken
before that from this object pool and if it is currently in taken state,
false
otherwisepublic boolean restore(Holder<T> holder, boolean valid)
false
otherwise will return true
. This validation should not be mistaken with the valid
status of the object state which is provided by the valid
parameter as shown below.restore
in interface HolderValidatingPoolService<T>
holder
- a thin wrapper enclosing the object that is to be restored to the object poolvalid
- if true
the restored object is presumed to be in valid (healthy) state,
otherwise it is treated as invalidtrue
if the underlying object from the given holder
was taken
before that from this object pool and if it is currently in taken state,
false
otherwisepublic List<Holder<T>> takenHolders()
Holder
objects (i.e the wrappers of the underlying
objects) which are currently (at the moment of the call) in taken state in this object
pool. Useful for testing and debugging purposes. The objects in the returned list are
in random order, i.e. the list is not sorted.takenHolders
in interface HolderValidatingPoolService<T>
Copyright © 2013-2014 Simeon Malchev. All Rights Reserved.