|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread org.sadun.util.pool2.BasePassivationManager
A Passivation thread is associated to one or more ObjectPool
s
and triggers the activation/passivation state of a Pooled object.
This class is abstract. Each subclass may define alternative passivation strategies.
Field Summary | |
protected java.io.PrintStream |
logStream
|
protected java.util.Set |
monitoredPools
The set of pools monitored by this thread (contained org.sadun.util.pool2.ObjectPool). |
protected boolean |
rotatePools
Controls which pools are checked on a service cycle |
protected int |
rotationRate
|
protected int |
sleepTime
The sleep time |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
protected |
BasePassivationManager(ObjectPool pool,
java.lang.String name,
int sleepTime)
Build a passivation thread monitoring the given pool, with the given thread name and having the given sleep time. |
protected |
BasePassivationManager(java.lang.String name)
|
protected |
BasePassivationManager(java.lang.String name,
int sleepTime)
|
Method Summary | |
void |
addPool(ObjectPool pool)
Add an ObjectPool to monitor. |
boolean |
canPassivate(java.lang.Class cls)
Method canPassivate. |
int |
countPools()
Count the monitored pools |
protected abstract void |
createState(ObjectPool pool,
PooledObject obj)
Used by a subclass to define an state information for a certain object belonging to a certain pool when a pool is added to the monitored set |
int |
getRotationRate()
Returns the rotationRate. |
int |
getSleepTime()
Returns the sleepTime. |
protected abstract void |
handleAcquired(ObjectPool pool,
PooledObject obj)
This method is used by the subclass to determine what to do when a pooled object is aquired. |
protected abstract void |
handleInvoked(ObjectPool pool,
PooledObject obj)
This method is is used by the subclass to determine what to do when a pooled object is actually invoked. |
protected abstract void |
handleReleased(ObjectPool pool,
PooledObject obj)
This method is invoked by the pool when a pooled object is released. |
boolean |
isRotatePools()
Returns the rotatePools. |
boolean |
isShuttingDown()
Return true if a shutdown has been requested. |
protected abstract boolean |
isToPassivate(ObjectPool pool,
PooledObject obj,
java.lang.Object preparationResult)
This method is invoked to check whether an object is to passivate or not. |
protected abstract java.lang.Object |
prepareForPassivationCheck(ObjectPool pool)
This method is invoked just before a pool is checked for passivation, and therefore before any isToPassivate()
is invoked.
|
void |
removePool(ObjectPool pool)
Remove an ObjectPool from monitoring. |
protected abstract void |
removeState(ObjectPool pool,
PooledObject obj)
Used by a subclass to remove the state information for a certain object belonging to a certain pool when a pool is removed from the monitored set |
void |
run()
The passivation thread main loop. |
void |
setLogStream(java.io.PrintStream logStream)
Method setLogStream. |
void |
setRotatePools(boolean rotatePools)
Sets the rotatePools. |
void |
setRotationRate(int rotationRate)
Sets the rotationRate. |
void |
setSleepTime(int sleepTime)
Sets the sleepTime. |
void |
shutdown()
Unconditionally requests a shutdown. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.io.PrintStream logStream
protected java.util.Set monitoredPools
protected int sleepTime
protected boolean rotatePools
protected int rotationRate
Constructor Detail |
protected BasePassivationManager(ObjectPool pool, java.lang.String name, int sleepTime)
pool
- the pool to monitor. Additional pools can be monitored by the same
passivation thread by using addPool()
name
- the thread nameprotected BasePassivationManager(java.lang.String name, int sleepTime)
protected BasePassivationManager(java.lang.String name)
Method Detail |
public void addPool(ObjectPool pool)
ObjectPool
to monitor.
pool
- the pool to addpublic boolean canPassivate(java.lang.Class cls)
protected abstract void createState(ObjectPool pool, PooledObject obj)
obj
- the objectpool
- the pool the object belongs toprotected abstract void removeState(ObjectPool pool, PooledObject obj)
obj
- the objectpool
- the pool the object belongs topublic void removePool(ObjectPool pool)
ObjectPool
from monitoring.
pool
- the pool to removepublic int countPools()
public final void run()
The thread awakes any sleepTime
milliseconds
and runs a service cycle, by verifying the passivability of all
the objects in all or some of the monitored pools (see rotatePools
).
The method isToPassivate()
is invoked on every object. If the method returns true the corresponding object
is passivated.
run
in interface java.lang.Runnable
protected abstract java.lang.Object prepareForPassivationCheck(ObjectPool pool)
isToPassivate()
is invoked.
A subclass may execute some preparation before the pool's
object are actually scanned, and return an object as result.
Such object is the passed to each subsequent isToPassivate()
invocation.
pool
- protected abstract boolean isToPassivate(ObjectPool pool, PooledObject obj, java.lang.Object preparationResult)
protected abstract void handleInvoked(ObjectPool pool, PooledObject obj)
The passivation thread may collect this information to implements its passivation policy.
obj
- the PooledObject which is being invokedprotected abstract void handleAcquired(ObjectPool pool, PooledObject obj)
The passivation thread may collect this information to implements its passivation policy.
obj
- the PooledObject which is being acquiredprotected abstract void handleReleased(ObjectPool pool, PooledObject obj)
The passivation thread may collect this information to implements its passivation policy.
obj
- the PooledObject which is being releasedpublic boolean isShuttingDown()
Terminable
isShuttingDown
in interface Terminable
Terminable.isShuttingDown()
public void shutdown()
Terminable
shutdown
in interface Terminable
Terminable.shutdown()
public int getSleepTime()
public void setSleepTime(int sleepTime)
sleepTime
- The sleepTime to setpublic boolean isRotatePools()
public void setRotatePools(boolean rotatePools)
rotatePools
- The rotatePools to setpublic int getRotationRate()
public void setRotationRate(int rotationRate)
rotationRate
- The rotationRate to setpublic void setLogStream(java.io.PrintStream logStream)
logStream
-
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |