|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.resilientedge.util.workerPool.WorkerPool
Provides a pool of daemon threads (workers). The minimum and maximum pool sizes are set during initialization. If a request is made and there are no available workers, the requestor is put into stasis until a worker becomes available. The worker pool is thread safe, and may be shared among multiple threads. A FIFO queueing process is used for multiple requestors waiting on a worker to become available from the pool.
An optional listener may be specified for the pool. The listener, an instance of WorkerPoolListener, is notified when events are generated by the pool. These events, instances of WorkerPoolEvent, include a call-back when a unit of work has completed on one of the workers in the pool. The listener may defined during worker pool initialization or changed at anytime during execution. Only one listener may registered.
Example Usage: create a pool with 2 min workers, 5 max workers, the
given worker class, and no listener WorkerPool workerPool = new
WorkerPool(); workerPool.init("A Worker
Pool",2,5,QueueOutWorker.class,null);
Constructor Summary | |
WorkerPool()
Default constructor. |
Method Summary | |
protected void |
addToQueue(int cnt)
Add the specified number of threads to the queue. |
protected boolean |
createEvent(int id)
If there is a listener, create an event and notify the listener of the event. |
protected boolean |
createEvent(int id,
java.lang.Object obj)
If there is a listener, create an event and notify the listener of the event. |
protected com.resilientedge.util.workerPool.WorkerPool.PoolThread |
createWorker()
Create a new thread and add it to the thread-pool. |
void |
dispose()
The Worker pool is cleared. |
void |
doWork(java.lang.Object data)
Request a work to be done on a thread from the worker pool. |
WorkerPoolListener |
getListener()
|
int |
getMaxSize()
|
int |
getMinSize()
|
WaitQStats |
getWaitStats()
|
protected java.lang.Class |
getWorkClass()
|
protected com.resilientedge.util.workerPool.WorkerPool.PoolThread |
getWorker()
Get a thread from the pool. |
protected java.lang.String |
getWorkerId()
The thread identifier prefix is based on the pool name. |
java.lang.String |
getWorkerPoolName()
|
void |
init(java.lang.String nm,
int min,
int max,
java.lang.Class cls,
WorkerPoolListener lstnr)
Initialize the pool, this should only be called once. |
void |
setListener(WorkerPoolListener lstnr)
|
protected void |
setMaxSize(int sz)
If the requested maximum size is less than the minimum size, the minimum size is used. |
protected void |
setMinSize(int sz)
|
protected void |
setWorkClass(java.lang.Class cls)
|
protected void |
setWorkerPoolName(java.lang.String nm)
Save the name of the pool, and create the prefix for the thread identifiers, which is based on the pool name. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public WorkerPool()
Method Detail |
public void setListener(WorkerPoolListener lstnr)
lstnr
- the thread pool listener or null if no listenerpublic int getMinSize()
public int getMaxSize()
public WaitQStats getWaitStats()
public java.lang.String getWorkerPoolName()
public WorkerPoolListener getListener()
public void init(java.lang.String nm, int min, int max, java.lang.Class cls, WorkerPoolListener lstnr)
nm
- the name of the pool, this name is used in each worker that
is created for the pool and in the wait queue statistics associated
associated with the poolmin
- the minimum number of pool entriesmax
- the maximum number of pool entries, if less than minimum,
minimum is usedcls
- the class that implements the Worker interfacelstnr
- a listener that is to receive pool events, may be nullpublic void dispose()
If subsequent requests are made of the worker pool, new workers will be created, up to the maximum specified during initialization.
public void doWork(java.lang.Object data)
data
- Parameter Descriptionprotected void setMinSize(int sz)
sz
- the minimum pool sizeprotected void setMaxSize(int sz)
sz
- the maximum pool sizeprotected void setWorkClass(java.lang.Class cls)
cls
- the class that implements the Work interfaceprotected void setWorkerPoolName(java.lang.String nm)
nm
- the name of the thread poolprotected com.resilientedge.util.workerPool.WorkerPool.PoolThread getWorker()
protected java.lang.Class getWorkClass()
protected java.lang.String getWorkerId()
protected void addToQueue(int cnt)
cnt
- the number of entries to be created in the poolprotected com.resilientedge.util.workerPool.WorkerPool.PoolThread createWorker()
protected boolean createEvent(int id)
id
- the event identifierprotected boolean createEvent(int id, java.lang.Object obj)
id
- the event identifierobj
- an object that is passed to the listener, the type of object
is event dependent
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |