|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.locomotive.util.ObjectPool
Manages a pool of objects. Will broker the objects out until there are no more to give out, whereupon it will either attempt to create a new object and send that out, or block if the maximum number of objects are already open until an object is available.
To subclass this, you'll probably want to override the return and wipe methods to do an instanceof check for your particular object type, and you may want to check the object's state in returnToPool.
Inner Class Summary | |
class |
ObjectPool.PoolEntry
The internal class to use as our Object entry. |
Field Summary | |
protected java.lang.String |
classname
This gets prepended to each logging message. |
protected int |
current_open
|
protected boolean |
isRunning
|
protected Log |
log
|
protected int |
log_level
|
protected int |
max_open
|
protected int |
min_open
|
protected java.util.Hashtable |
pe_in_use_hash
This holds objects in use. |
protected java.util.Stack |
pe_stack
the stack to use to hold the objects |
protected int |
poolentry_id_sequence
|
Constructor Summary | |
ObjectPool()
Default constructor for the object pool |
|
ObjectPool(int min_open_in,
int max_open_in)
creates a new pool, and fills it with the specified minumum number of objects |
|
ObjectPool(int min_open_in,
int max_open_in,
Log l,
int log_lvl_in)
creates a new pool, and fills it with the specified minumum number of objects |
Method Summary | |
void |
closeCurrentPoolMembers()
Closes all objects in the pool at the time of the call. |
protected abstract java.lang.Object |
createNewObject()
This is called internally whenever a new object is created and added to the pool. |
protected abstract void |
destroyObject(java.lang.Object obj)
This should be overridden in sub classes to clean up any of an object's resources before the object get's removed from the pool. |
int |
getLogLevel()
Get the log level for this object pool. |
int |
getMaxSize()
Get the maximum size of the object pool. |
int |
getMinSize()
Get the minimum size of the object pool. |
protected int |
getNextId()
Each PoolEntry has a numeric ID, this method increments it and gives it out. |
java.lang.Object |
getObject()
gets an object from the pool. |
int |
getPoolSize()
returns the current number of open db objects in the pool |
void |
initialize()
This needs to be called after the pool is created |
boolean |
isRunning()
Check if the object pool is started. |
protected void |
log(java.lang.String message)
Log a statement. |
protected void |
logError(java.lang.String message,
java.lang.Throwable t)
Log an error. |
void |
returnToPool(java.lang.Object obj)
returns this object to the pool, allowing other threads to have access to it. |
void |
setLog(Log log)
Set the log for this object pool. |
void |
setLogLevel(int logLevel)
Set the log level for this object pool. |
void |
setMaxSize(int maxSize)
Set the maximum size of the object pool. |
void |
setMinSize(int minSize)
Set the minimum size of the object pool. |
void |
startService()
Start the object pool service. |
void |
stopService()
Stop the object pool service. |
void |
wipeFromPool(java.lang.Object obj)
removes the specified object from the pool. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected java.util.Stack pe_stack
protected java.util.Hashtable pe_in_use_hash
protected int min_open
protected int max_open
protected int current_open
protected int poolentry_id_sequence
protected Log log
protected int log_level
protected boolean isRunning
protected java.lang.String classname
Constructor Detail |
public ObjectPool(int min_open_in, int max_open_in) throws InitializationException
min_open_in
- the minumum number of objects to remain
in the poolmax_open_in
- the maximum number of objects to
maintain at any given timepublic ObjectPool(int min_open_in, int max_open_in, Log l, int log_lvl_in) throws InitializationException
min_open_in
- the minumum number of objects to remain
in the poolmax_open_in
- the maximum number of objects to
maintain at any given timel
- the log to use to log any major events. Leave as null for no
logginglog_lvl_in
- the log level to use when loggingpublic ObjectPool()
Method Detail |
public void initialize() throws InitializationException
public void startService() throws ServiceException
public void stopService() throws ServiceException
public boolean isRunning()
protected abstract java.lang.Object createNewObject() throws InitializationException
protected abstract void destroyObject(java.lang.Object obj)
public java.lang.Object getObject()
public int getPoolSize()
public void returnToPool(java.lang.Object obj)
public void wipeFromPool(java.lang.Object obj)
public void closeCurrentPoolMembers()
protected int getNextId()
protected void log(java.lang.String message)
protected void logError(java.lang.String message, java.lang.Throwable t)
public void setMinSize(int minSize)
minSize
- The minimum size of the object pool.public int getMinSize()
public void setMaxSize(int maxSize)
maxSize
- The maximum size of the object pool.public int getMaxSize()
public void setLog(Log log)
log
- The log object for this connetion pool.public void setLogLevel(int logLevel)
logLevel
- The log level for this object pool.public int getLogLevel()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |