|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jboss.minerva.pools.ObjectPool
A generic object pool. You must provide a PoolObjectFactory (or the class of a Java Bean) so the pool knows what kind of objects to create. It has many configurable parameters, such as the minimum and maximum size of the pool, whether to enable idle timeouts, etc. If the pooled objects implement PooledObject, they will automatically be returned to the pool at the appropriate times.
In general, the appropriate way to use a pool is:
PooledObject
Constructor Summary | |
ObjectPool()
Creates a new pool. |
|
ObjectPool(java.lang.Class javaBeanClass,
java.lang.String poolName)
Creates a new pool with the specified parameters. |
|
ObjectPool(PoolObjectFactory factory,
java.lang.String poolName)
Creates a new pool with the specified parameters. |
Method Summary | |
long |
getGCInterval()
Gets the length of time between garbage collection and idle timeout runs. |
long |
getGCMinIdleTime()
Gets the minimum idle time to make an object eligible for garbage collection. |
long |
getIdleTimeout()
Gets the minimum idle time to release an unused object from the pool. |
java.io.PrintWriter |
getLogWriter()
Gets a log writer used to record pool events. |
float |
getMaxIdleTimeoutPercent()
Gets the idle timeout percent as a fraction between 0 and 1. |
int |
getMaxSize()
Gets the maximum size of the pool. |
int |
getMinSize()
Gets the minimum size of the pool. |
java.lang.String |
getName()
Gets the name of the pool. |
java.lang.Object |
getObject()
Gets an object from the pool. |
void |
initialize()
Prepares the pool for use. |
boolean |
isBlocking()
Gets whether a request for an object will block if the pool size is maxed out and no objects are available. |
boolean |
isGCEnabled()
Gets whether garbage collection is enabled. |
boolean |
isIdleTimeoutEnabled()
Gets whether the pool releases instances that have not been used recently. |
boolean |
isInvalidateOnError()
Gets whether objects are removed from the pool in case of errors. |
boolean |
isTimestampUsed()
Gets whether object clients can update the last used time. |
void |
markObjectAsInvalid(java.lang.Object object)
Indicates that an object is no longer valid, and should be removed from the pool entirely. |
void |
objectClosed(PoolEvent evt)
If the object has been closed, release it. |
void |
objectError(PoolEvent evt)
If the object had an error, we assume this will propogate and preclude it from being closed, so we will close it. |
void |
objectUsed(PoolEvent evt)
If we're tracking the last used times, update the last used time for the specified object. |
void |
releaseObject(java.lang.Object object)
Returns an object to the pool. |
void |
setBlocking(boolean blocking)
Sets whether a request for an object will block if the pool size is maxed out and no objects are available. |
void |
setGCEnabled(boolean enabled)
Sets whether garbage collection is enabled. |
void |
setGCInterval(long millis)
Sets the length of time between garbage collection and idle timeout runs. |
void |
setGCMinIdleTime(long millis)
Sets the minimum idle time to make an object eligible for garbage collection. |
void |
setIdleTimeout(long millis)
Sets the minimum idle time to release an unused object from the pool. |
void |
setIdleTimeoutEnabled(boolean enableTimeout)
Sets whether the pool should release instances that have not been used recently. |
void |
setInvalidateOnError(boolean invalidate)
Sets the response for object errors. |
void |
setLastUsed(java.lang.Object object)
Sets the last used time for an object in the pool that is currently in use. |
void |
setLogWriter(java.io.PrintWriter writer)
Sets a log writer used to record pool events. |
void |
setMaxIdleTimeoutPercent(float percent)
Sets the idle timeout percent as a fraction between 0 and 1. |
void |
setMaxSize(int size)
Sets the maximum size of the pool. |
void |
setMinSize(int size)
Sets the minimum size of the pool. |
void |
setName(java.lang.String name)
Sets the name of the pool. |
void |
setObjectFactory(java.lang.Class javaBeanClass)
Sets the object factory as a new factory for Java Beans. |
void |
setObjectFactory(PoolObjectFactory factory)
Sets the object factory for the pool. |
void |
setTimestampUsed(boolean timestamp)
Sets whether object clients can update the last used time. |
void |
shutDown()
Shuts down the pool. |
java.lang.String |
toString()
Returns the pool name and status. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public ObjectPool()
setName(java.lang.String)
,
setObjectFactory(org.jboss.minerva.pools.PoolObjectFactory)
,
initialize()
public ObjectPool(PoolObjectFactory factory, java.lang.String poolName)
factory
- The object factory that will create the objects to go in
the pool.poolName
- The name of the pool. This does not have to be unique
across all pools, but it is strongly recommended (and it may be a
requirement for certain uses of the pool).initialize()
public ObjectPool(java.lang.Class javaBeanClass, java.lang.String poolName)
javeBeanClass
- The Class of a Java Bean. New instances for the
pool will be created with the no-argument constructor, and no
particular initialization or cleanup will be performed on the
instances. Use a PoolObjectFactory if you want more control over
the instances.poolName
- The name of the pool. This does not have to be unique
across all pools, but it is strongly recommended (and it may be a
requirement for certain uses of the pool).initialize()
Method Detail |
public void setObjectFactory(PoolObjectFactory factory)
java.lang.IllegalStateException
- Occurs when you try to set the object factory after the pool has been
initialized.public void setObjectFactory(java.lang.Class javaBeanClass)
java.lang.IllegalStateException
- Occurs when you try to set the object factory after the pool has been
initialized.public void setName(java.lang.String name)
java.lang.IllegalStateException
- Occurs when you try to set the name of the pool more than once.public java.lang.String getName()
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
public void setLogWriter(java.io.PrintWriter writer) throws java.sql.SQLException
java.lang.IllegalStateException
- Occurs when you try to set the log writer after the pool has been
initialized.public void setMinSize(int size)
java.lang.IllegalStateException
- Occurs when you try to set the minimum size after the pool has been
initialized.public int getMinSize()
setMinSize(int)
public void setMaxSize(int size)
size
- The maximum size of the pool, or 0 if the pool should grow
indefinitely (not recommended).java.lang.IllegalStateException
- Occurs when you try to set the maximum size after the pool has been
initialized.setBlocking(boolean)
public int getMaxSize()
setMaxSize(int)
public void setIdleTimeoutEnabled(boolean enableTimeout)
The default is disabled.
java.lang.IllegalStateException
- Occurs when you try to set the idle timeout state after the pool has
been initialized.setGCInterval(long)
,
setIdleTimeout(long)
,
setMaxIdleTimeoutPercent(float)
,
setMinSize(int)
public boolean isIdleTimeoutEnabled()
setIdleTimeoutEnabled(boolean)
public void setGCEnabled(boolean enabled)
java.lang.IllegalStateException
- Occurs when you try to set the garbage collection state after the pool
has been initialized.setGCMinIdleTime(long)
,
setGCInterval(long)
public boolean isGCEnabled()
setGCEnabled(boolean)
public void setMaxIdleTimeoutPercent(float percent)
java.lang.IllegalStateException
- Occurs when you try to set the idle timeout percent after the pool
has been initialized.java.lang.IllegalArgumentException
- Occurs when the percent parameter is not between 0 and 1.setIdleTimeoutEnabled(boolean)
public float getMaxIdleTimeoutPercent()
setMaxIdleTimeoutPercent(float)
public void setIdleTimeout(long millis)
millis
- The idle time, in milliseconds.java.lang.IllegalStateException
- Occurs when you try to set the idle timeout after the pool
has been initialized.setIdleTimeoutEnabled(boolean)
public long getIdleTimeout()
setIdleTimeout(long)
public void setGCMinIdleTime(long millis)
millis
- The idle time, in milliseconds.java.lang.IllegalStateException
- Occurs when you try to set the garbage collection idle time after the
pool has been initialized.setGCEnabled(boolean)
public long getGCMinIdleTime()
setGCMinIdleTime(long)
public void setGCInterval(long millis)
java.lang.IllegalStateException
- Occurs when you try to set the garbage collection interval after the
pool has been initialized.public long getGCInterval()
setGCInterval(long)
public void setBlocking(boolean blocking)
java.lang.IllegalStateException
- Occurs when you try to set the blocking parameter after the
pool has been initialized.public boolean isBlocking()
setBlocking(boolean)
public void setTimestampUsed(boolean timestamp)
java.lang.IllegalStateException
- Occurs when you try to set the timestamp parameter after the
pool has been initialized.public boolean isTimestampUsed()
public void setInvalidateOnError(boolean invalidate)
markObjectAsInvalid(java.lang.Object)
,
objectError(org.jboss.minerva.pools.PoolEvent)
public boolean isInvalidateOnError()
public void initialize()
java.lang.IllegalStateException
- Occurs when you try to initialize the pool without setting the object
factory or name, or you initialize the pool more than once.public void shutDown()
public java.lang.Object getObject()
setBlocking(boolean)
public void setLastUsed(java.lang.Object object)
java.lang.IllegalArgumentException
- Occurs when the object is not recognized by the factory or not
in the pool.java.lang.IllegalStateException
- Occurs when the object is not currently in use.setTimestampUsed(boolean)
public void markObjectAsInvalid(java.lang.Object object)
Object
- The object to invalidate, which must be the exact object
returned by getObjectpublic void releaseObject(java.lang.Object object)
java.lang.IllegalArgumentException
- Occurs when the object is not in this pool.public java.lang.String toString()
toString
in class java.lang.Object
public void objectClosed(PoolEvent evt)
objectClosed
in interface PoolEventListener
public void objectError(PoolEvent evt)
objectError
in interface PoolEventListener
public void objectUsed(PoolEvent evt)
objectUsed
in interface PoolEventListener
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |