Package org.omegazero.common.event
Class DelegatingTaskQueueExecutor
java.lang.Object
org.omegazero.common.event.AbstractTaskQueueExecutor
org.omegazero.common.event.DelegatingTaskQueueExecutor
An
AbstractTaskQueueExecutor
delegating all tasks to another AbstractTaskQueueExecutor
implementation.
This class is thread-safe.
- Since:
- 2.12.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
exit
(boolean blocking) Shuts thisAbstractTaskQueueExecutor
down by gracefully stopping the worker threads.Returns the currently setAbstractTaskQueueExecutor
to delegate tasks to.void
lock()
Locks thisDelegatingTaskQueueExecutor
.boolean
Queues a task to be executed by any available worker thread.void
setDelegate
(AbstractTaskQueueExecutor delegate) Sets a newAbstractTaskQueueExecutor
to delegate tasks to.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.boolean
Removes the given task from the queue.Methods inherited from class org.omegazero.common.event.AbstractTaskQueueExecutor
exit, queue, queue, queue
-
Constructor Details
-
DelegatingTaskQueueExecutor
Creates a newDelegatingTaskQueueExecutor
.- Parameters:
delegate
- TheAbstractTaskQueueExecutor
to delegate tasks to
-
-
Method Details
-
getDelegate
Returns the currently setAbstractTaskQueueExecutor
to delegate tasks to.- Returns:
- The current delegate
-
setDelegate
Sets a newAbstractTaskQueueExecutor
to delegate tasks to.- Parameters:
delegate
- The newAbstractTaskQueueExecutor
- Throws:
IllegalStateException
- If thisDelegatingTaskQueueExecutor
was locked usinglock()
-
lock
public void lock()Locks thisDelegatingTaskQueueExecutor
. If locked, the delegate cannot be changed usingsetDelegate(AbstractTaskQueueExecutor)
anymore.- Throws:
IllegalStateException
- If thisDelegatingTaskQueueExecutor
was locked already
-
queue
Description copied from class:AbstractTaskQueueExecutor
Queues a task to be executed by any available worker thread.- Specified by:
queue
in classAbstractTaskQueueExecutor
- Parameters:
task
- The task to queue- Returns:
true
if the task was successfully queued- See Also:
-
unqueue
Description copied from class:AbstractTaskQueueExecutor
Removes the given task from the queue.- Specified by:
unqueue
in classAbstractTaskQueueExecutor
- Parameters:
task
- The task to remove- Returns:
true
if the task was queued previously and removed successfully- See Also:
-
exit
public boolean exit(boolean blocking) Description copied from class:AbstractTaskQueueExecutor
Shuts thisAbstractTaskQueueExecutor
down by gracefully stopping the worker threads.- Specified by:
exit
in classAbstractTaskQueueExecutor
- 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
Description copied from class:AbstractTaskQueueExecutor
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
.- Specified by:
setErrorHandler
in classAbstractTaskQueueExecutor
- Parameters:
errorHandler
- The error handler, ornull
to remove an existing error handler
-