Protomatter Software v1.1.8

com.protomatter.pool
Class SimpleObjectPool

java.lang.Object
  |
  +--com.protomatter.pool.SimpleObjectPool
All Implemented Interfaces:
ObjectPool
Direct Known Subclasses:
GrowingObjectPool

public abstract class SimpleObjectPool
extends java.lang.Object
implements ObjectPool

A minimal implementation of an ObjectPool. This class provides a non-growing pool that sleeps the threads that are trying to check something out of the pool, and wakes them up in-order when something is checked back in.

See Also:
ObjectPool

Field Summary
protected  java.lang.Object sync
          An object used for synchronization.
 
Constructor Summary
SimpleObjectPool()
          Initialize the object pool.
SimpleObjectPool(boolean monitorCheckedOutObjects)
          Initialize the object pool.
 
Method Summary
 void checkin(ObjectPoolObject opo)
          Check an object back into the pool.
protected abstract  void checkinPoolObject(ObjectPoolObject o)
          This method needs to be implemented by sub-classes.
 ObjectPoolObject checkout()
          Implements a first in, first out reservation scheme.
protected abstract  ObjectPoolObject createObjectPoolObject()
          To be implemented by sub-classes.
protected  java.util.List getCheckedOutObjects()
          Get the list of objects that are currently checked out of the pool.
protected abstract  ObjectPoolObject getNextPoolObject()
          This method needs to be implemented by sub-classes.
 int getNumWaiters()
          Get the number of threads waiting for an object to become available.
 int getObjectsInUse()
          Get the number of objects that are currently checked out.
protected  java.lang.Object getSyncObject()
          Get a reference to the object being used as a synchronization lock.
 void removeWaiter(java.lang.Thread t)
          Remove the given thread from the list of waiters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.protomatter.pool.ObjectPool
init, reInitializeObjectPool
 

Field Detail

sync

protected java.lang.Object sync
An object used for synchronization.
Constructor Detail

SimpleObjectPool

public SimpleObjectPool()
Initialize the object pool. Checked out objects will be monitored.

SimpleObjectPool

public SimpleObjectPool(boolean monitorCheckedOutObjects)
Initialize the object pool. Checked out objects will be monitored if monitorCheckedOutObjects is true.
Method Detail

getSyncObject

protected java.lang.Object getSyncObject()
Get a reference to the object being used as a synchronization lock. Subclasses that need to lock the operation of the pool while they perform maintenance should synchronize on this object and then manipulate the pool.

getNumWaiters

public int getNumWaiters()
Get the number of threads waiting for an object to become available.

getObjectsInUse

public int getObjectsInUse()
Get the number of objects that are currently checked out.
Specified by:
getObjectsInUse in interface ObjectPool

removeWaiter

public final void removeWaiter(java.lang.Thread t)
Remove the given thread from the list of waiters. This method should only be called if you know what you're doing.

checkout

public ObjectPoolObject checkout()
                          throws java.lang.Exception
Implements a first in, first out reservation scheme. If no threads are waiting for the object, then the caller never blocks. If there are waiters, then the caller "get's in line," and waits for their turn with the object.
Specified by:
checkout in interface ObjectPool
Throws:
java.lang.Exception - If there is a problem checking an object out of the pool.

checkin

public void checkin(ObjectPoolObject opo)
             throws java.lang.Exception
Check an object back into the pool. If there are threads in the wait queue, the thread that has been waiting longest will get the shared object next. The waiter may not receive the shared object immediately, however.
Specified by:
checkin in interface ObjectPool
Throws:
java.lang.Exception - If there was a problem checking in the object.

getCheckedOutObjects

protected java.util.List getCheckedOutObjects()
Get the list of objects that are currently checked out of the pool.

getNextPoolObject

protected abstract ObjectPoolObject getNextPoolObject()
                                               throws java.lang.Exception
This method needs to be implemented by sub-classes. It should return the next element in the pool, or null if the pool is empty. Growable implementations should use this method to add more elements to the pool.
Throws:
java.lang.Exception - If there is a problem getting the next object for the pool -- this is implementation specific.

checkinPoolObject

protected abstract void checkinPoolObject(ObjectPoolObject o)
                                   throws java.lang.Exception
This method needs to be implemented by sub-classes. It should add the given ObjectPoolObject to the pool.
Throws:
java.lang.Exception - If there is a problem checking in the object -- this is implementation specific.

createObjectPoolObject

protected abstract ObjectPoolObject createObjectPoolObject()
                                                    throws java.lang.Exception
To be implemented by sub-classes. This is a factory method for creating objects that go in this pool.
Throws:
java.lang.Exception - If there is a problem creating the next object for the pool -- this is implementation specific.

Protomatter Software v1.1.8
Copyright 1998-2002 Nate Sammons

Protomatter Software v1.1.8 http://protomatter.sourceforge.net/1.1.8