Package org.omegazero.common.event
Class DeferringTaskQueueExecutor
java.lang.Object
org.omegazero.common.event.AbstractTaskQueueExecutor
org.omegazero.common.event.DeferringTaskQueueExecutor
An
AbstractTaskQueueExecutor deferring all queued tasks until another AbstractTaskQueueExecutor implementation is available.
An object of this class should be used as a delegate for a DelegatingTaskQueueExecutor.
This class is thread-safe.
- Since:
- 2.12.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newDeferringTaskQueueExecutorwith parameter maxDeferredTasks set to 1024.DeferringTaskQueueExecutor(int maxDeferredTasks) Creates a newDeferringTaskQueueExecutor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanexit(boolean blocking) Shuts thisAbstractTaskQueueExecutordown by gracefully stopping the worker threads.booleanQueues a task to be executed by any available worker thread.voidreplaceFor(DelegatingTaskQueueExecutor parent, AbstractTaskQueueExecutor newDelegate) Transfers all deferred tasks of thisDeferringTaskQueueExecutorto a new delegate, then replaces the delegate of aDelegatingTaskQueueExecutor, where the previous delegate was this object, with this new delegate.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.voidtransferTasks(AbstractTaskQueueExecutor destination) Transfers all deferred tasks of thisDeferringTaskQueueExecutorto the givenAbstractTaskQueueExecutor.booleanRemoves the given task from the queue.Methods inherited from class org.omegazero.common.event.AbstractTaskQueueExecutor
exit, queue, queue, queue
-
Constructor Details
-
DeferringTaskQueueExecutor
public DeferringTaskQueueExecutor()Creates a newDeferringTaskQueueExecutorwith parameter maxDeferredTasks set to 1024. -
DeferringTaskQueueExecutor
public DeferringTaskQueueExecutor(int maxDeferredTasks) Creates a newDeferringTaskQueueExecutor.- Parameters:
maxDeferredTasks- The maximum number of tasks to defer before rejectingqueue(Task)calls
-
-
Method Details
-
transferTasks
Transfers all deferred tasks of thisDeferringTaskQueueExecutorto the givenAbstractTaskQueueExecutor. The defer queue is cleared and thisDeferringTaskQueueExecutorcan be used further.- Parameters:
destination- TheAbstractTaskQueueExecutorto transfer the deferred tasks to
-
replaceFor
Transfers all deferred tasks of thisDeferringTaskQueueExecutorto a new delegate, then replaces the delegate of aDelegatingTaskQueueExecutor, where the previous delegate was this object, with this new delegate.If an error handler was set for this
DeferringTaskQueueExecutor, it is also set as the error handler for the new delegate.After a call to this method, this
DeferringTaskQueueExecutormust no longer be used.- Parameters:
parent- TheDelegatingTaskQueueExecutorto set the new delegate fornewDelegate- The new delegate- See Also:
-
queue
Description copied from class:AbstractTaskQueueExecutorQueues a task to be executed by any available worker thread.- Specified by:
queuein classAbstractTaskQueueExecutor- Parameters:
task- The task to queue- Returns:
trueif the task was successfully queued- See Also:
-
unqueue
Description copied from class:AbstractTaskQueueExecutorRemoves the given task from the queue.- Specified by:
unqueuein classAbstractTaskQueueExecutor- Parameters:
task- The task to remove- Returns:
trueif the task was queued previously and removed successfully- See Also:
-
exit
public boolean exit(boolean blocking) Description copied from class:AbstractTaskQueueExecutorShuts thisAbstractTaskQueueExecutordown by gracefully stopping the worker threads.- Specified by:
exitin classAbstractTaskQueueExecutor- 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
Description copied from class:AbstractTaskQueueExecutorSets 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:
setErrorHandlerin classAbstractTaskQueueExecutor- Parameters:
errorHandler- The error handler, ornullto remove an existing error handler
-