Result
- FlagType
- public class FlagFuture<Result,FlagType> extends Object implements IFuture<Result>, FlagListener<FlagType>
Thread-safe implementation, not as easy as it seems ;-)
FlagListener.FlagListenerNotifier<T>
Constructor and Description |
---|
FlagFuture(Flag<FlagType> waitFlag,
FlagType terminalFlagValue,
Result resultValue)
Initializing future to wait for 'terminalFlagValue' at 'waitFlag', when that happens complete
itself with result 'resultValue'.
|
FlagFuture(Flag<FlagType> waitFlag,
Map<FlagType,Result> terminalMap)
In constructor you have to specify a flag where the future should listen at + terminal
states for the future (terminalMap).
|
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
void |
flagChanged(FlagType changedValue) |
Result |
get()
Waits if necessary for the computation to complete, and then
retrieves its result.
|
Result |
get(long timeout,
TimeUnit unit)
Waits if necessary for at most the given time for the computation
to complete, and then retrieves its result, if available.
|
boolean |
isCancelled() |
boolean |
isDone() |
void |
stop(Result result)
Stops the future (not the task it represents!).
|
public FlagFuture(Flag<FlagType> waitFlag, Map<FlagType,Result> terminalMap)
Possible flag values and the behavior of the future:
Note that the flag value is examined during the construction of the object and if the flag has value that is in the terminalMap the future is completes itself.
waitFlag
- terminalMap
- public void stop(Result result)
Note that this happened IFF !isDone(), e.g. if the future is already done this won't do anything (as latch is already raised and the result value has been determined).
Note that this is different behavior that cancel() should implement, therefore it's a different method.
public boolean cancel(boolean mayInterruptIfRunning)
public Result get()
IFuture
public Result get(long timeout, TimeUnit unit)
IFuture
public boolean isCancelled()
isCancelled
in interface Future<Result>
public void flagChanged(FlagType changedValue)
flagChanged
in interface FlagListener<FlagType>
Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.