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 |
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.
|
JobFactory |
getJobFactory()
The job factory.
|
String |
getName()
Returns the name of this Worker.
|
Collection<String> |
getQueues()
The queues that this Worker will poll.
|
WorkerEventEmitter |
getWorkerEventEmitter() |
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 |
removeAllQueues()
Stop polling all queues.
|
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 |
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()
public WorkerEventEmitter getWorkerEventEmitter()
getWorkerEventEmitter in interface Workerpublic void end(boolean now)
end in interface JobExecutornow - if true, an effort will be made to stop any job in progresspublic boolean isShutdown()
isShutdown in interface JobExecutorpublic boolean isPaused()
public void togglePause(boolean paused)
togglePause in interface Workerpaused - if true, the worker will not process any new jobs; if false,
the worker will process new jobspublic boolean isProcessingJob()
isProcessingJob in interface JobExecutorpublic JobFactory getJobFactory()
getJobFactory in interface JobExecutorpublic Collection<String> getQueues()
public void addQueue(String queueName)
public void removeQueue(String queueName, boolean all)
all 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()
removeAllQueues in interface Workerpublic void setQueues(Collection<String> queues)
public ExceptionHandler getExceptionHandler()
getExceptionHandler in interface JobExecutorpublic void setExceptionHandler(ExceptionHandler exceptionHandler)
setExceptionHandler in interface JobExecutorexceptionHandler - the exception handler to useCopyright © 2011-2015. All Rights Reserved.