Class SerializingExecutor
java.lang.Object
org.eclipse.net4j.util.event.Notifier
org.eclipse.net4j.util.lifecycle.Lifecycle
org.eclipse.net4j.util.concurrent.SerializingExecutor
- All Implemented Interfaces:
Runnable, Executor, INotifier, INotifier.INotifier2, IDeactivateable, ILifecycle, ILifecycle.DeferrableActivation
An executor that runs submitted tasks one at a time, in the order in which they are queued, using a delegate executor.
The delegate remains externally owned. Before the first activation,
execute(Runnable) and all submit
methods retain tasks until activation. After deactivation, execute(Runnable) continues to retain tasks until
a later activation, while submit rejects new tasks. Tasks that were queued when deactivation begins are
discarded, and their submitted futures are cancelled.- Since:
- 3.9
- Author:
- Eike Stepper
-
Nested Class Summary
Nested classes/interfaces inherited from class Notifier
Notifier.CancelationNested classes/interfaces inherited from interface ILifecycle
ILifecycle.DeferrableActivationNested classes/interfaces inherited from interface INotifier
INotifier.INotifier2 -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidprotected voidfinal voidExecutes the given command in queue order.final Executorprotected voidhandleFailedTask(Runnable task, Throwable failure) final voidrun()final voidsetDelegate(Executor delegate) final Future<?> Queues a task for serial execution and returns a future that completes when the task completes.final <T> Future<T> Queues a task for serial execution and returns a future that yields the given result after successful completion.final <T> Future<T> Queues a callable for serial execution and returns a future for its result or failure.Methods inherited from class Lifecycle
activate, checkActive, checkArg, checkArg, checkInactive, checkNull, checkState, checkState, deactivate, deferredActivate, doBeforeActivate, doBeforeDeactivate, doCancelActivation, dump, getLifecycleState, isActive, isDeferredActivation, toStringMethods inherited from class Notifier
addListener, addUniqueListener, fireEvent, fireEvent, fireEvent, fireThrowable, firstListenerAdded, getListeners, getNotificationService, hasListener, hasListeners, lastListenerRemoved, listenerAdded, listenerRemoved, removeListenerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface INotifier
addListener, getListeners, hasListeners, removeListener
-
Constructor Details
-
SerializingExecutor
-
SerializingExecutor
public SerializingExecutor()
-
-
Method Details
-
getDelegate
-
setDelegate
-
execute
Executes the given command in queue order. Before the first activation, and after deactivation, the command is retained until a later activation. A command queued when deactivation begins is discarded.- Specified by:
executein interfaceExecutor- Parameters:
command- the command to execute- Throws:
NullPointerException- if the command isnull
-
submit
Queues a task for serial execution and returns a future that completes when the task completes. Before the first activation, the task is retained until activation. After deactivation, this method rejects the task. If scheduling the worker is rejected, this method throws the rejection and cancels any futures that were already accepted but cannot be scheduled as a result.- Parameters:
task- the task to execute- Returns:
- the future representing the task
- Throws:
RejectedExecutionException- if this executor is deactivated or the delegate rejects the worker submissionNullPointerException- if the task isnull- Since:
- 3.31
-
submit
Queues a task for serial execution and returns a future that yields the given result after successful completion. Before the first activation, the task is retained until activation. After deactivation, this method rejects the task. Cancellation follows the standardFuturecontract.- Type Parameters:
T- the result type- Parameters:
task- the task to executeresult- the result to return after successful execution- Returns:
- the future representing the task
- Throws:
RejectedExecutionException- if this executor is deactivated or the delegate rejects the worker submissionNullPointerException- if the task isnull- Since:
- 3.31
-
submit
Queues a callable for serial execution and returns a future for its result or failure. Before the first activation, the task is retained until activation. After deactivation, this method rejects the task.- Type Parameters:
T- the result type- Parameters:
task- the callable to execute- Returns:
- the future representing the task
- Throws:
RejectedExecutionException- if this executor is deactivated or the delegate rejects the worker submissionNullPointerException- if the task isnull- Since:
- 3.31
-
run
-
handleFailedTask
-
doActivate
- Overrides:
doActivatein classLifecycle- Throws:
Exception
-
doAfterActivate
- Overrides:
doAfterActivatein classLifecycle- Throws:
Exception
-
doDeactivate
- Overrides:
doDeactivatein classLifecycle- Throws:
Exception
-