Class RxTaskPool
- java.lang.Object
-
- org.apache.catalina.tribes.transport.RxTaskPool
-
public class RxTaskPool extends java.lang.ObjectA very simple thread pool class. The pool size is set at construction time and remains fixed. Threads are cycled through a FIFO idle queue.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRxTaskPool.TaskCreatorFactory interface for creating receive tasks.
-
Constructor Summary
Constructors Constructor Description RxTaskPool(int maxTasks, int minTasks, RxTaskPool.TaskCreator creator)Create a new fixed-size receive task pool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Return the number of idle tasks currently available in the pool.protected voidconfigureTask(AbstractRxTask task)Configure a receive task by associating it with this pool.intgetMaxThreads()Return the maximum number of tasks allowed in the pool.intgetMinThreads()Return the minimum number of tasks maintained in the pool.AbstractRxTaskgetRxTask()Find an idle worker thread, if any.RxTaskPool.TaskCreatorgetTaskCreator()Return the task creator factory used by this pool.voidreturnWorker(AbstractRxTask worker)Called by the worker thread to return itself to the idle pool.voidsetMaxTasks(int maxThreads)Set the maximum number of tasks allowed in the pool.voidsetMinTasks(int minThreads)Set the minimum number of tasks maintained in the pool.voidstop()Stop the pool, closing all idle tasks and preventing new tasks from being acquired.
-
-
-
Constructor Detail
-
RxTaskPool
public RxTaskPool(int maxTasks, int minTasks, RxTaskPool.TaskCreator creator) throws java.lang.ExceptionCreate a new fixed-size receive task pool.- Parameters:
maxTasks- maximum number of tasks in the poolminTasks- minimum number of tasks in the poolcreator- factory for creating new receive tasks- Throws:
java.lang.Exception- if initialization fails
-
-
Method Detail
-
configureTask
protected void configureTask(AbstractRxTask task)
Configure a receive task by associating it with this pool.- Parameters:
task- the task to configure
-
getRxTask
public AbstractRxTask getRxTask()
Find an idle worker thread, if any. Could return null.- Returns:
- a worker
-
available
public int available()
Return the number of idle tasks currently available in the pool.- Returns:
- count of idle tasks
-
returnWorker
public void returnWorker(AbstractRxTask worker)
Called by the worker thread to return itself to the idle pool.- Parameters:
worker- The worker
-
getMaxThreads
public int getMaxThreads()
Return the maximum number of tasks allowed in the pool.- Returns:
- maximum task count
-
getMinThreads
public int getMinThreads()
Return the minimum number of tasks maintained in the pool.- Returns:
- minimum task count
-
stop
public void stop()
Stop the pool, closing all idle tasks and preventing new tasks from being acquired.
-
setMaxTasks
public void setMaxTasks(int maxThreads)
Set the maximum number of tasks allowed in the pool.- Parameters:
maxThreads- maximum task count
-
setMinTasks
public void setMinTasks(int minThreads)
Set the minimum number of tasks maintained in the pool.- Parameters:
minThreads- minimum task count
-
getTaskCreator
public RxTaskPool.TaskCreator getTaskCreator()
Return the task creator factory used by this pool.- Returns:
- the task creator
-
-