Package jadex.commons.future
Class TerminableFuture<E>
- java.lang.Object
-
- jadex.commons.future.Future<E>
-
- jadex.commons.future.TerminableFuture<E>
-
- All Implemented Interfaces:
IBackwardCommandFuture
,IForwardCommandFuture
,IFuture<E>
,ITerminableFuture<E>
public class TerminableFuture<E> extends Future<E> implements ITerminableFuture<E>
Future that can be terminated from caller side. A termination request leads to setException() being called with a FutureTerminatedException. The future can be supplied with a command that gets executed if terminate is called.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jadex.commons.future.IForwardCommandFuture
IForwardCommandFuture.Type
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<ICommand<java.lang.Object>,IFilter<java.lang.Object>>
bcommands
The list of backward commands.protected ITerminationCommand
terminate
The termination code.-
Fields inherited from class jadex.commons.future.Future
CALLER_QUEUED, CALLER_RESUMED, CALLER_SUSPENDED, callers, creation, DEBUG, exception, first, listeners, NO_STACK_COMPACTION, NONE, notcommand, NOTIFICATIONS, notificount, result, resultavailable, undone, UNSET
-
-
Constructor Summary
Constructors Constructor Description TerminableFuture()
Create a new future.TerminableFuture(ITerminationCommand terminate)
Create a future that is already done.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBackwardCommand(IFilter<java.lang.Object> filter, ICommand<java.lang.Object> command)
Add a backward command with a filter.void
removeBackwardCommand(ICommand<java.lang.Object> command)
Add a command with a filter.void
sendBackwardCommand(java.lang.Object info)
Send a backward command in direction of the source.void
setTerminationCommand(ITerminationCommand terminate)
Set the termination command.void
terminate()
Terminate the future.void
terminate(java.lang.Exception reason)
Terminate the future and supply a custom reason.-
Methods inherited from class jadex.commons.future.Future
abortGet, addResultListener, catchEx, catchEx, catchEx, delegate, delegateEx, doAddResultListener, doSetException, doSetResult, doStartScheduledNotifications, executeNotification, get, get, get, get, get, getEmptyFuture, getException, getFuture, getNotificationCommand, hasResultListener, isDone, resume, scheduleNotification, scheduleNotification, sendForwardCommand, setException, setExceptionIfUndone, setResult, setResultIfUndone, startScheduledNotifications, then, thenAccept, thenAccept, thenApply, thenApply, thenCombine, thenCompose, thenCompose
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jadex.commons.future.IFuture
addResultListener, catchEx, catchEx, catchEx, delegate, get, get, get, get, get, getException, isDone, then, thenApply, thenApply, thenCompose, thenCompose
-
-
-
-
Field Detail
-
terminate
protected ITerminationCommand terminate
The termination code.
-
-
Constructor Detail
-
TerminableFuture
public TerminableFuture()
Create a new future.
-
TerminableFuture
public TerminableFuture(ITerminationCommand terminate)
Create a future that is already done.- Parameters:
result
- The result, if any.
-
-
Method Detail
-
terminate
public void terminate()
Terminate the future. The exception will be set to FutureTerminatedException.- Specified by:
terminate
in interfaceITerminableFuture<E>
-
terminate
public void terminate(java.lang.Exception reason)
Terminate the future and supply a custom reason.- Specified by:
terminate
in interfaceITerminableFuture<E>
-
sendBackwardCommand
public void sendBackwardCommand(java.lang.Object info)
Send a backward command in direction of the source.- Specified by:
sendBackwardCommand
in interfaceIBackwardCommandFuture
- Parameters:
info
- The command info.
-
addBackwardCommand
public void addBackwardCommand(IFilter<java.lang.Object> filter, ICommand<java.lang.Object> command)
Add a backward command with a filter. Whenever the future receives an info it will check all registered filters.
-
removeBackwardCommand
public void removeBackwardCommand(ICommand<java.lang.Object> command)
Add a command with a filter. Whenever the future receives an info it will check all registered filters.
-
setTerminationCommand
public void setTerminationCommand(ITerminationCommand terminate)
Set the termination command.- Parameters:
terminate
- The termination command.
-
-