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
Task
s. The base class for a TaskQueueExecutor
.
This class is thread-safe.
- Since:
- 2.12.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
exit()
Shuts thisAbstractTaskQueueExecutor
down by gracefully stopping the worker threads.abstract boolean
exit
(boolean blocking) Shuts thisAbstractTaskQueueExecutor
down by gracefully stopping the worker threads.boolean
Creates a newReflectTask
instance and adds it to the event queue usingqueue(Task)
.boolean
Creates a newRunnableTask
instance and adds it to the event queue usingqueue(Task)
.boolean
Creates a newLambdaTask
instance and adds it to the event queue usingqueue(Task)
.abstract boolean
Queues a task to be executed by any available worker thread.abstract void
setErrorHandler
(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 boolean
Removes 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:
true
if the task was successfully queued- See Also:
-
unqueue
Removes the given task from the queue.- Parameters:
task
- The task to remove- Returns:
true
if the task was queued previously and removed successfully- See Also:
-
exit
public abstract boolean exit(boolean blocking) Shuts thisAbstractTaskQueueExecutor
down by gracefully stopping the worker threads.- Parameters:
blocking
-true
to wait for all worker threads to exit- Returns:
true
if 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, ornull
to remove an existing error handler
-
queue
Creates a newReflectTask
instance and adds it to the event queue usingqueue(Task)
.- Parameters:
method
- The task handler methodcallerInstance
- The instance to call the method with. May benull
if the method is staticargs
- The arguments to pass to the task handler when this task is executedpriority
- The priority of this task. May be ignored if the backing queue does not support prioritization- Returns:
true
if the task was successfully queued- See Also:
-
queue
Creates a newRunnableTask
instance 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:
true
if the task was successfully queued- Since:
- 2.9
- See Also:
-
queue
Creates a newLambdaTask
instance and adds it to the event queue usingqueue(Task)
.- Parameters:
handler
- The task handlerargs
- The arguments to pass to the task handler when this task is executedpriority
- The priority of this task. May be ignored if the backing queue does not support prioritization- Returns:
true
if the task was successfully queued- See Also:
-
exit
public void exit()Shuts thisAbstractTaskQueueExecutor
down by gracefully stopping the worker threads.Equivalent to a call to:
exit
(false)
-