Package org.omegazero.common.event
Class AbstractTaskQueueExecutor
java.lang.Object
org.omegazero.common.event.AbstractTaskQueueExecutor
- Direct Known Subclasses:
DeferringTaskQueueExecutor,DelegatingTaskQueueExecutor,SynchronousTaskQueueExecutor,TaskQueueExecutor
Used for queuing and running
Tasks. The base class for a TaskQueueExecutor.
This class is thread-safe.
- Since:
- 2.12.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexit()Shuts thisAbstractTaskQueueExecutordown by gracefully stopping the worker threads.abstract booleanexit(boolean blocking) Shuts thisAbstractTaskQueueExecutordown by gracefully stopping the worker threads.booleanCreates a newReflectTaskinstance and adds it to the event queue usingqueue(Task).booleanCreates a newRunnableTaskinstance and adds it to the event queue usingqueue(Task).booleanCreates a newLambdaTaskinstance and adds it to the event queue usingqueue(Task).abstract booleanQueues a task to be executed by any available worker thread.abstract voidsetErrorHandler(Consumer<Throwable> errorHandler) Sets the error handler that will be called when an error occurs while executing a task in any of the worker threads.abstract booleanRemoves the given task from the queue.
-
Constructor Details
-
AbstractTaskQueueExecutor
public AbstractTaskQueueExecutor()
-
-
Method Details
-
queue
Queues a task to be executed by any available worker thread.- Parameters:
task- The task to queue- Returns:
trueif the task was successfully queued- See Also:
-
unqueue
Removes the given task from the queue.- Parameters:
task- The task to remove- Returns:
trueif the task was queued previously and removed successfully- See Also:
-
exit
public abstract boolean exit(boolean blocking) Shuts thisAbstractTaskQueueExecutordown by gracefully stopping the worker threads.- Parameters:
blocking-trueto wait for all worker threads to exit- Returns:
trueif the calling thread was interrupted while waiting for the worker threads to exit
-
setErrorHandler
Sets the error handler that will be called when an error occurs while executing a task in any of the worker threads.If this handler is not set, the error will be printed to
stderr.- Parameters:
errorHandler- The error handler, ornullto remove an existing error handler
-
queue
Creates a newReflectTaskinstance and adds it to the event queue usingqueue(Task).- Parameters:
method- The task handler methodcallerInstance- The instance to call the method with. May benullif the method is staticpriority- The priority of this task. May be ignored if the backing queue does not support prioritizationargs- The arguments to pass to the task handler when this task is executed- Returns:
trueif the task was successfully queued- See Also:
-
queue
Creates a newRunnableTaskinstance and adds it to the event queue usingqueue(Task).- Parameters:
handler- The task handlerpriority- The priority of this task. May be ignored if the backing queue does not support prioritization- Returns:
trueif the task was successfully queued- Since:
- 2.9
- See Also:
-
queue
Creates a newLambdaTaskinstance and adds it to the event queue usingqueue(Task).- Parameters:
handler- The task handlerpriority- The priority of this task. May be ignored if the backing queue does not support prioritizationargs- The arguments to pass to the task handler when this task is executed- Returns:
trueif the task was successfully queued- See Also:
-
exit
public void exit()Shuts thisAbstractTaskQueueExecutordown by gracefully stopping the worker threads.Equivalent to a call to:
exit(false)
-