|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.cuni.amis.utils.future.FlagFuture<Result,FlagType>
Result
- FlagType
- public class FlagFuture<Result,FlagType>
Future implementation that is listening on a flag and when it's terminal state is set on the flag the future completes itself with result specified in the map (under the key of the flag value).
Thread-safe implementation, not as easy as it seems ;-)
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface cz.cuni.amis.utils.flag.FlagListener |
---|
FlagListener.FlagListenerNotifier<T> |
Constructor Summary | |
---|---|
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). |
Method Summary | |
---|---|
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!). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
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 FlagFuture(Flag<FlagType> waitFlag, FlagType terminalFlagValue, Result resultValue)
waitFlag
- terminalFlagValue
- resultValue
- Method Detail |
---|
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)
cancel
in interface Future<Result>
public Result get()
IFuture
get
in interface IFuture<Result>
get
in interface Future<Result>
public Result get(long timeout, TimeUnit unit)
IFuture
get
in interface IFuture<Result>
get
in interface Future<Result>
timeout
- the maximum time to waitunit
- the time unit of the timeout argument
public boolean isCancelled()
isCancelled
in interface Future<Result>
public boolean isDone()
isDone
in interface Future<Result>
public void flagChanged(FlagType changedValue)
flagChanged
in interface FlagListener<FlagType>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |