public class WorkerPool extends Object implements Worker
Workers, each on a
separate Thread.JobExecutor.StateALL_QUEUES| Constructor and Description |
|---|
WorkerPool(Callable<? extends Worker> workerFactory,
int numWorkers)
Create a WorkerPool with the given number of Workers and the
default
ThreadFactory. |
WorkerPool(Callable<? extends Worker> workerFactory,
int numWorkers,
ThreadFactory threadFactory)
Create a WorkerPool with the given number of Workers and the
given
ThreadFactory. |
| Modifier and Type | Method and Description |
|---|---|
void |
addJobType(String jobName,
Class<?> jobType)
Allow the given job type to be executed.
|
void |
addListener(WorkerListener listener)
Register a WorkerListener for all WorkerEvents.
|
void |
addListener(WorkerListener listener,
WorkerEvent... events)
Register a WorkerListener for the specified WorkerEvents.
|
void |
addQueue(String queueName)
Poll the given queue.
|
void |
end(boolean now)
Shutdown this JobExecutor.
|
void |
endAndJoin(boolean now,
long millis)
Shutdown this pool and wait millis time per thread or until all threads are finished if millis is 0.
|
ExceptionHandler |
getExceptionHandler()
The current exception handler.
|
Map<String,Class<?>> |
getJobTypes()
The allowed job names and types that this JobExecutor will execute.
|
String |
getName()
Returns the name of this Worker.
|
Collection<String> |
getQueues()
The queues that this Worker will poll.
|
boolean |
isPaused()
Returns whether this worker is paused.
|
boolean |
isProcessingJob()
Returns whether this JobExecutor is currently processing a job.
|
boolean |
isShutdown()
Returns whether this JobExecutor is either shutdown or in the process of shutting down.
|
void |
join(long millis)
Join to internal threads and wait millis time per thread or until all threads are finished if millis is 0.
|
void |
removeAllListeners()
Unregister all WorkerListeners for all WorkerEvents.
|
void |
removeAllListeners(WorkerEvent... events)
Unregister all WorkerListeners for the specified WorkerEvents.
|
void |
removeAllQueues()
Stop polling all queues.
|
void |
removeJobName(String jobName)
Disallow the job name from being executed.
|
void |
removeJobType(Class<?> jobType)
Disallow the job type from being executed.
|
void |
removeListener(WorkerListener listener)
Unregister a WorkerListener for all WorkerEvents.
|
void |
removeListener(WorkerListener listener,
WorkerEvent... events)
Unregister a WorkerListener for the specified WorkerEvents.
|
void |
removeQueue(String queueName,
boolean all)
Stop polling the given queue.
|
void |
run() |
void |
setExceptionHandler(ExceptionHandler exceptionHandler)
Set this JobExecutor's exception handler to the given handler.
|
void |
setJobTypes(Map<String,? extends Class<?>> jobTypes)
Clear any current allowed job types and use the given set.
|
void |
setQueues(Collection<String> queues)
Clear any current queues and poll the given queues.
|
void |
togglePause(boolean paused)
Toggle whether this worker will process any new jobs.
|
public WorkerPool(Callable<? extends Worker> workerFactory, int numWorkers)
ThreadFactory.workerFactory - a Callable that returns an implementation of WorkernumWorkers - the number of Workers to createpublic WorkerPool(Callable<? extends Worker> workerFactory, int numWorkers, ThreadFactory threadFactory)
ThreadFactory.workerFactory - a Callable that returns an implementation of WorkernumWorkers - the number of Workers to createthreadFactory - the factory to create pre-configured Threadspublic void endAndJoin(boolean now,
long millis)
throws InterruptedException
now - if true, an effort will be made to stop any jobs in progressmillis - the time to wait in milliseconds for the threads to join;
a timeout of 0 means to wait forever.InterruptedException - if any thread has interrupted the current thread.
The interrupted status of the current thread is cleared when this exception is thrown.public void join(long millis)
throws InterruptedException
join in interface JobExecutormillis - the time to wait in milliseconds for the threads to join;
a timeout of 0 means to wait forever.InterruptedException - if any thread has interrupted the current thread.
The interrupted status of the current thread is cleared when this exception is thrown.public String getName()
Workerpublic void addListener(WorkerListener listener)
WorkerEventEmitteraddListener in interface WorkerEventEmitterlistener - the WorkerListener to registerpublic void addListener(WorkerListener listener, WorkerEvent... events)
WorkerEventEmitteraddListener in interface WorkerEventEmitterlistener - the WorkerListener to registerevents - the WorkerEvents to be notified ofpublic void removeListener(WorkerListener listener)
WorkerEventEmitterremoveListener in interface WorkerEventEmitterlistener - the WorkerListener to unregisterpublic void removeListener(WorkerListener listener, WorkerEvent... events)
WorkerEventEmitterremoveListener in interface WorkerEventEmitterlistener - the WorkerListener to unregisterevents - the WorkerEvents to no longer be notified ofpublic void removeAllListeners()
WorkerEventEmitterremoveAllListeners in interface WorkerEventEmitterpublic void removeAllListeners(WorkerEvent... events)
WorkerEventEmitterremoveAllListeners in interface WorkerEventEmitterevents - the WorkerEvents to no longer be notified ofpublic void end(boolean now)
JobExecutorend in interface JobExecutornow - if true, an effort will be made to stop any job in progresspublic boolean isShutdown()
JobExecutorisShutdown in interface JobExecutorpublic boolean isPaused()
Workerpublic void togglePause(boolean paused)
WorkertogglePause in interface Workerpaused - if true, the worker will not process any new jobs;
if false, the worker will process new jobspublic boolean isProcessingJob()
JobExecutorisProcessingJob in interface JobExecutorpublic Collection<String> getQueues()
Workerpublic void addQueue(String queueName)
Workerpublic void removeQueue(String queueName, boolean all)
Workerall argument is
true, all instances of the queue will be removed, otherwise, only
one instance is removed.removeQueue in interface WorkerqueueName - the queue to stop pollingall - whether to remove all or only one of the instancespublic void removeAllQueues()
WorkerremoveAllQueues in interface Workerpublic void setQueues(Collection<String> queues)
Workerpublic Map<String,Class<?>> getJobTypes()
JobExecutorgetJobTypes in interface JobExecutorpublic void addJobType(String jobName, Class<?> jobType)
JobExecutoraddJobType in interface JobExecutorjobName - the job name as seenjobType - the job type to allowpublic void removeJobType(Class<?> jobType)
JobExecutorremoveJobType in interface JobExecutorjobType - the job type to disallowpublic void removeJobName(String jobName)
JobExecutorremoveJobName in interface JobExecutorjobName - the job name to disallowpublic void setJobTypes(Map<String,? extends Class<?>> jobTypes)
JobExecutorsetJobTypes in interface JobExecutorjobTypes - the job types to allowpublic ExceptionHandler getExceptionHandler()
JobExecutorgetExceptionHandler in interface JobExecutorpublic void setExceptionHandler(ExceptionHandler exceptionHandler)
JobExecutorsetExceptionHandler in interface JobExecutorexceptionHandler - the exception handler to useCopyright © 2011-2013. All Rights Reserved.