org.ow2.util.pool.impl.enhanced.impl.basic
Class BasicPool<E>

java.lang.Object
  extended by org.ow2.util.pool.impl.enhanced.impl.basic.BasicPool<E>
Type Parameters:
E - pool item type
All Implemented Interfaces:
IBasicPool<E>, IPool<E>, IResizablePool<E>, IResizable
Direct Known Subclasses:
BasicCluePool

public class BasicPool<E>
extends java.lang.Object
implements IBasicPool<E>

Basic pool implementation. You can dynamically change pool size calling setExpectedSize method.

Author:
Gael Lalire

Field Summary
protected static InfiniteWaitControl INFINITE_WAIT_CONTROL
          Because basic pool do not delegate, we can use one instance.
 
Constructor Summary
BasicPool(IPoolItemFactory<? extends E> poolItemFactory, int initPoolSize, IAccessManager<? super E> accessManager, java.util.concurrent.Executor createItemExecutor, IPoolItemRemoveListener<? super E> poolItemRemoveCB, java.util.concurrent.Executor removeItemExecutor)
           
 
Method Summary
protected  boolean callNextRemoveCallBack()
           
 void clearPool()
          After calling this method the pool will have a zero size and no item will be created until setExpectedSize will be called again.
protected  boolean createNewItem()
           
protected  void createOneItem(E poolItem)
           
 E get()
          This method block is there is no available pool item in the pool.
 E get(IWaitControl timeout)
          This method block is no instance are available.
protected  java.util.List<E> getAvailablePoolItemList()
           
protected  int getDelayedCount()
           
protected  int getExpectedSize()
           
protected  FactoryState getFactoryState()
           
protected  java.util.concurrent.locks.Lock getLock()
           
protected  int getOneItem()
           
protected  IPoolItemFactory<? extends E> getPoolItemFactory()
           
protected  IAccessManager<? super E> getReleaseListener()
           
protected  ISignalClearableCondition getSignalClearableCondition()
           
protected  long getTemporaryBrokenFactoryEndTime()
           
protected  java.util.List<E> getUnmodifiableAvailablePoolItemList()
           
protected  int getUnUsedPoolItem()
           
protected  int getUsedPoolItem()
           
 void lockSizeToZero()
           
 void put(E poolItem)
          This method will never block.
protected  void putOneItem(E poolItem)
           
protected  void releaseOneItem()
           
protected  void releasePoolItem(E releasePoolItem)
           
 void remove(E poolItem)
          This method can be called when you finished to use the pool item instead of put method.
protected  void removeOneItem(E poolItem)
           
protected  void setDelayedCount(int delayedCount)
           
 void setExpectedSize(int expectedSize)
           
protected  void setUsedPoolItem(int usedPoolItem)
           
 void signalAllWaiters()
          Ask pool to recall all timeout.waitOnXXX.
 void unlockSizeToZero()
           
 void waitAllRemoveListenerCompleted()
          After calling this method all pending remove calls will be called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INFINITE_WAIT_CONTROL

protected static final InfiniteWaitControl INFINITE_WAIT_CONTROL
Because basic pool do not delegate, we can use one instance.

Constructor Detail

BasicPool

public BasicPool(IPoolItemFactory<? extends E> poolItemFactory,
                 int initPoolSize,
                 IAccessManager<? super E> accessManager,
                 java.util.concurrent.Executor createItemExecutor,
                 IPoolItemRemoveListener<? super E> poolItemRemoveCB,
                 java.util.concurrent.Executor removeItemExecutor)
Method Detail

getOneItem

protected int getOneItem()

createOneItem

protected void createOneItem(E poolItem)

putOneItem

protected void putOneItem(E poolItem)

releaseOneItem

protected void releaseOneItem()

removeOneItem

protected void removeOneItem(E poolItem)

setExpectedSize

public void setExpectedSize(int expectedSize)
Specified by:
setExpectedSize in interface IResizable
Parameters:
expectedSize - the expectedSize to set

lockSizeToZero

public void lockSizeToZero()
Specified by:
lockSizeToZero in interface IBasicPool<E>

unlockSizeToZero

public void unlockSizeToZero()
Specified by:
unlockSizeToZero in interface IBasicPool<E>

createNewItem

protected boolean createNewItem()
Returns:
true if the call to poolItemFactory was done false otherwise

get

public E get(IWaitControl timeout)
      throws TimeoutPoolException,
             IllegalTimeoutException,
             WaiterInterruptedException,
             java.lang.InterruptedException,
             PoolFactoryBroken
This method block is no instance are available.

Specified by:
get in interface IBasicPool<E>
Specified by:
get in interface IPool<E>
Parameters:
timeout - after this timeout a exception is thrown
Returns:
a pool item
Throws:
TimeoutPoolException - if timeout
IllegalTimeoutException
WaiterInterruptedException
java.lang.InterruptedException
PoolFactoryBroken

get

public E get()
      throws WaiterInterruptedException,
             java.lang.InterruptedException,
             PoolFactoryBroken
Description copied from interface: IBasicPool
This method block is there is no available pool item in the pool. It is same as get(INFINITE_TIMEOUT);

Specified by:
get in interface IBasicPool<E>
Returns:
a non null instance
Throws:
WaiterInterruptedException - if error occurs
java.lang.InterruptedException
PoolFactoryBroken

put

public void put(E poolItem)
         throws NotABusyPoolItemException
This method will never block. If the pool owns too many instances, release method will be apply on pool item.

Specified by:
put in interface IPool<E>
Parameters:
poolItem - a pool item
Throws:
NotABusyPoolItemException - if error occurs

getPoolItemFactory

protected IPoolItemFactory<? extends E> getPoolItemFactory()
Returns:
the poolItemFactory

getReleaseListener

protected IAccessManager<? super E> getReleaseListener()
Returns:
the releaseListener

setUsedPoolItem

protected void setUsedPoolItem(int usedPoolItem)
Parameters:
usedPoolItem - the usedPoolItem to set

getAvailablePoolItemList

protected java.util.List<E> getAvailablePoolItemList()
Returns:
the mutex to sync before calling protected methods

getExpectedSize

protected int getExpectedSize()
Returns:
the expectedSize

getUsedPoolItem

protected int getUsedPoolItem()
Returns:
the usedPoolItem

getUnUsedPoolItem

protected int getUnUsedPoolItem()
Returns:
the unUsedPoolItem

getLock

protected final java.util.concurrent.locks.Lock getLock()
Returns:
the lock

getSignalClearableCondition

protected ISignalClearableCondition getSignalClearableCondition()
Returns:
the signalClearableCondition

getDelayedCount

protected int getDelayedCount()
Returns:
the delayedCount

setDelayedCount

protected void setDelayedCount(int delayedCount)
Parameters:
delayedCount - the delayedCount to set

signalAllWaiters

public void signalAllWaiters()
Description copied from interface: IPool
Ask pool to recall all timeout.waitOnXXX. So if you change a WaitAuthorization state you can avoid all waiters.

Specified by:
signalAllWaiters in interface IPool<E>

releasePoolItem

protected void releasePoolItem(E releasePoolItem)

clearPool

public void clearPool()
               throws java.lang.InterruptedException
Description copied from interface: IBasicPool
After calling this method the pool will have a zero size and no item will be created until setExpectedSize will be called again.

Specified by:
clearPool in interface IBasicPool<E>
Throws:
java.lang.InterruptedException

waitAllRemoveListenerCompleted

public void waitAllRemoveListenerCompleted()
                                    throws java.lang.InterruptedException
Description copied from interface: IBasicPool
After calling this method all pending remove calls will be called.

Specified by:
waitAllRemoveListenerCompleted in interface IBasicPool<E>
Throws:
java.lang.InterruptedException

callNextRemoveCallBack

protected boolean callNextRemoveCallBack()

remove

public void remove(E poolItem)
            throws NotABusyPoolItemException
Description copied from interface: IPool
This method can be called when you finished to use the pool item instead of put method. If you call this method the pool item will be replace with a new.

Specified by:
remove in interface IPool<E>
Parameters:
poolItem - a pool item
Throws:
NotABusyPoolItemException - if error occurs

getUnmodifiableAvailablePoolItemList

protected java.util.List<E> getUnmodifiableAvailablePoolItemList()
Returns:
the unmodifiableAvailablePoolItemList

getTemporaryBrokenFactoryEndTime

protected long getTemporaryBrokenFactoryEndTime()

getFactoryState

protected FactoryState getFactoryState()


Copyright © 2007-2009 OW2 Consortium. All Rights Reserved.