Class RxTaskPool
java.lang.Object
org.apache.catalina.tribes.transport.RxTaskPool
A 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 ClassesModifier and TypeClassDescriptionstatic interfaceFactory interface for creating receive tasks. -
Constructor Summary
ConstructorsConstructorDescriptionRxTaskPool(int maxTasks, int minTasks, RxTaskPool.TaskCreator creator) Create a new fixed-size receive task pool. -
Method Summary
Modifier and TypeMethodDescriptionintReturn the number of idle tasks currently available in the pool.protected voidconfigureTask(AbstractRxTask task) Configure a receive task by associating it with this pool.intReturn the maximum number of tasks allowed in the pool.intReturn the minimum number of tasks maintained in the pool.Find an idle worker thread, if any.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 Details
-
RxTaskPool
Create 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:
Exception- if initialization fails
-
-
Method Details
-
configureTask
Configure a receive task by associating it with this pool.- Parameters:
task- the task to configure
-
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
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
Return the task creator factory used by this pool.- Returns:
- the task creator
-