Package jadex.commons.future
Class IntermediateFuture<E>
- java.lang.Object
- 
- jadex.commons.future.Future<java.util.Collection<E>>
- 
- jadex.commons.future.IntermediateFuture<E>
 
 
- 
- All Implemented Interfaces:
- IForwardCommandFuture,- IFuture<java.util.Collection<E>>,- IIntermediateFuture<E>
 - Direct Known Subclasses:
- TerminableIntermediateDelegationFuture,- TerminableIntermediateFuture,- Tuple2Future
 
 public class IntermediateFuture<E> extends Future<java.util.Collection<E>> implements IIntermediateFuture<E> Default implementation of an intermediate future.
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface jadex.commons.future.IForwardCommandFutureIForwardCommandFuture.Type
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected java.util.Map<ISuspendable,java.lang.String>icallersThe blocked intermediate callers (caller->state).protected java.util.Map<java.lang.Thread,java.lang.Integer>indicesThe index of the next result for a thread.protected booleanintermediateFlag indicating that addIntermediateResult()has been called.protected ICommand<IResultListener<java.util.Collection<E>>>notcommandprotected java.util.List<E>resultsThe intermediate results.- 
Fields inherited from class jadex.commons.future.FutureCALLER_QUEUED, CALLER_RESUMED, CALLER_SUSPENDED, callers, creation, DEBUG, exception, first, listener, listeners, NO_STACK_COMPACTION, NONE, notifications, result, resultavailable, STACK, undone, UNSET
 - 
Fields inherited from interface jadex.commons.future.IIntermediateFutureDONE
 
- 
 - 
Constructor SummaryConstructors Constructor Description IntermediateFuture()Create a future that is already done.IntermediateFuture(java.lang.Exception exception)Create a future that is already done (failed).IntermediateFuture(java.util.Collection<E> results)Create a future that is already done.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddIntermediateResult(E result)Add an intermediate result.booleanaddIntermediateResultIfUndone(E result)Set the result.voidaddIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener)Add a functional result listener, which called on intermediate results.voidaddIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener, IFunctionalExceptionListener exceptionListener)Add a functional result listener, which called on intermediate results.voidaddIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener, IFunctionalIntermediateFinishedListener<java.lang.Void> finishedListener)Add a functional result listener, which called on intermediate results.voidaddIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener, IFunctionalIntermediateFinishedListener<java.lang.Void> finishedListener, IFunctionalExceptionListener exceptionListener)Add a functional result listener, which called on intermediate results.voidaddIntermediateResultListener(IIntermediateResultListener<E> intermediateListener)Add an result listener, which called on intermediate results.voidaddResultListener(IResultListener<java.util.Collection<E>> listener)Add a result listener.protected booleandoAddIntermediateResult(E result, boolean undone)Set the result and schedule listener notifications.protected EdoGetNextIntermediateResult(int index, long timeout, boolean realtime)Perform the get without increasing the index.protected booleandoSetFinished(boolean undone)Declare that the future is finished.protected booleandoSetResult(java.util.Collection<E> result, boolean undone)Set the result.<R> IIntermediateFuture<R>flatMapAsync(Function<E,IIntermediateFuture<R>> function)Implements async loop and applies a an async multi-function to each element.java.util.Collection<E>getIntermediateResults()Get the intermediate results that are available.EgetNextIntermediateResult()Iterate over the intermediate results in a blocking fashion.EgetNextIntermediateResult(boolean realtime)Iterate over the intermediate results in a blocking fashion.EgetNextIntermediateResult(long timeout, boolean realtime)Iterate over the intermediate results in a blocking fashion.protected ICommand<IResultListener<java.util.Collection<E>>>getNotificationCommand()Get the notification command.booleanhasNextIntermediateResult()Check if there are more results for iteration for the given caller.booleanhasNextIntermediateResult(long timeout, boolean realtime)Check if there are more results for iteration for the given caller.<R> IIntermediateFuture<R>mapAsync(Function<E,IFuture<R>> function)Implements async loop and applies a an async function to each element.<R> IIntermediateFuture<R>mapAsync(Function<E,IFuture<R>> function, java.lang.Class<?> futuretype)Implements async loop and applies a an async function to each element.protected voidnotifyIntermediateResult(IIntermediateResultListener<E> listener, E result)Notify a result listener.protected voidresume()Resume also intermediate waiters.protected voidresumeIntermediate()Resume after intermediate result.voidsetFinished()Declare that the future is finished.booleansetFinishedIfUndone()Declare that the future is finished.protected voidstoreResult(E result)Add a result.- 
Methods inherited from class jadex.commons.future.FutureabortGet, acceptEither, addResultListener, addResultListener, applyToEither, delegate, doSetException, exceptionally, exceptionally, exceptionally, executeNotification, get, get, get, get, get, getEmptyFuture, getException, getFuture, hasResultListener, isDone, notifyListener, notifyListener, scheduleNotification, scheduleNotification, scheduleNotification, sendForwardCommand, setException, setExceptionIfUndone, setResult, setResultIfUndone, startScheduledNotifications, thenAccept, thenAccept, thenApply, thenApply, thenCombine, thenCompose, thenCompose
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface jadex.commons.future.IFutureacceptEither, addResultListener, addResultListener, applyToEither, delegate, exceptionally, exceptionally, exceptionally, get, get, get, get, get, getException, isDone, thenAccept, thenAccept, thenApply, thenApply, thenCombine, thenCompose, thenCompose
 
- 
 
- 
- 
- 
Field Detail- 
resultsprotected java.util.List<E> results The intermediate results.
 - 
intermediateprotected boolean intermediate Flag indicating that addIntermediateResult()has been called.
 - 
icallersprotected java.util.Map<ISuspendable,java.lang.String> icallers The blocked intermediate callers (caller->state).
 - 
indicesprotected java.util.Map<java.lang.Thread,java.lang.Integer> indices The index of the next result for a thread.
 - 
notcommandprotected ICommand<IResultListener<java.util.Collection<E>>> notcommand 
 
- 
 - 
Constructor Detail- 
IntermediateFuturepublic IntermediateFuture() Create a future that is already done.- Parameters:
- result- The result, if any.
 
 - 
IntermediateFuturepublic IntermediateFuture(java.util.Collection<E> results) Create a future that is already done.- Parameters:
- result- The result, if any.
 
 - 
IntermediateFuturepublic IntermediateFuture(java.lang.Exception exception) Create a future that is already done (failed).- Parameters:
- exception- The exception.
 
 
- 
 - 
Method Detail- 
getIntermediateResultspublic java.util.Collection<E> getIntermediateResults() Get the intermediate results that are available.- Specified by:
- getIntermediateResultsin interface- IIntermediateFuture<E>
- Returns:
- The current intermediate results (copy of the list).
 
 - 
addIntermediateResultpublic void addIntermediateResult(E result) Add an intermediate result.
 - 
addIntermediateResultIfUndonepublic boolean addIntermediateResultIfUndone(E result) Set the result.- Parameters:
- result- The result.
- Returns:
- True if result was set.
 
 - 
doAddIntermediateResultprotected boolean doAddIntermediateResult(E result, boolean undone) Set the result and schedule listener notifications.- Returns:
- true, when the result was added (finished and undone otherwise).
 
 - 
storeResultprotected void storeResult(E result) Add a result.- Parameters:
- result- The result.
 
 - 
doSetResultprotected boolean doSetResult(java.util.Collection<E> result, boolean undone) Set the result. Listener notifications occur on calling thread of this method.- Overrides:
- doSetResultin class- Future<java.util.Collection<E>>
- Parameters:
- result- The result.
 
 - 
setFinishedpublic void setFinished() Declare that the future is finished.
 - 
setFinishedIfUndonepublic boolean setFinishedIfUndone() Declare that the future is finished.
 - 
doSetFinishedprotected boolean doSetFinished(boolean undone) Declare that the future is finished.
 - 
addResultListenerpublic void addResultListener(IResultListener<java.util.Collection<E>> listener) Add a result listener.- Specified by:
- addResultListenerin interface- IFuture<E>
- Overrides:
- addResultListenerin class- Future<java.util.Collection<E>>
- Parameters:
- listener- The listener.
 
 - 
getNotificationCommandprotected ICommand<IResultListener<java.util.Collection<E>>> getNotificationCommand() Get the notification command.- Overrides:
- getNotificationCommandin class- Future<java.util.Collection<E>>
 
 - 
addIntermediateResultListenerpublic void addIntermediateResultListener(IIntermediateResultListener<E> intermediateListener) Add an result listener, which called on intermediate results.- Specified by:
- addIntermediateResultListenerin interface- IIntermediateFuture<E>
- Parameters:
- intermediateListener- The intermediate listener.
 
 - 
addIntermediateResultListenerpublic void addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener) Add a functional result listener, which called on intermediate results. Exceptions will be logged.- Specified by:
- addIntermediateResultListenerin interface- IIntermediateFuture<E>
- Parameters:
- intermediateListener- The intermediate listener.
 
 - 
addIntermediateResultListenerpublic void addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener, IFunctionalIntermediateFinishedListener<java.lang.Void> finishedListener) Add a functional result listener, which called on intermediate results. Exceptions will be logged.- Specified by:
- addIntermediateResultListenerin interface- IIntermediateFuture<E>
- Parameters:
- intermediateListener- The intermediate listener.
- finishedListener- The finished listener, called when no more intermediate results will arrive. If- null, the finish event will be ignored.
 
 - 
addIntermediateResultListenerpublic void addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener, IFunctionalExceptionListener exceptionListener) Add a functional result listener, which called on intermediate results.- Specified by:
- addIntermediateResultListenerin interface- IIntermediateFuture<E>
- Parameters:
- intermediateListener- The intermediate listener.
- exceptionListener- The listener that is called on exceptions. Passing- nullenables default exception logging.
 
 - 
addIntermediateResultListenerpublic void addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener, IFunctionalIntermediateFinishedListener<java.lang.Void> finishedListener, IFunctionalExceptionListener exceptionListener) Add a functional result listener, which called on intermediate results.- Specified by:
- addIntermediateResultListenerin interface- IIntermediateFuture<E>
- Parameters:
- intermediateListener- The intermediate listener.
- finishedListener- The finished listener, called when no more intermediate results will arrive. If- null, the finish event will be ignored.
- exceptionListener- The listener that is called on exceptions. Passing- nullenables default exception logging.
 
 - 
hasNextIntermediateResultpublic boolean hasNextIntermediateResult() Check if there are more results for iteration for the given caller. If there are currently no unprocessed results and future is not yet finished, the caller is blocked until either new results are available and true is returned or the future is finished, thus returning false.- Specified by:
- hasNextIntermediateResultin interface- IIntermediateFuture<E>
- Returns:
- True, when there are more intermediate results for the caller.
 
 - 
hasNextIntermediateResultpublic boolean hasNextIntermediateResult(long timeout, boolean realtime)Check if there are more results for iteration for the given caller. If there are currently no unprocessed results and future is not yet finished, the caller is blocked until either new results are available and true is returned or the future is finished, thus returning false.- Specified by:
- hasNextIntermediateResultin interface- IIntermediateFuture<E>
- Parameters:
- timeout- The timeout in millis.
- realtime- Flag, if wait should be realtime (in constrast to simulation time).
- Returns:
- True, when there are more intermediate results for the caller.
 
 - 
getNextIntermediateResultpublic E getNextIntermediateResult() Iterate over the intermediate results in a blocking fashion. Manages results independently for different callers, i.e. when called from different threads, each thread receives all intermediate results. The operation is guaranteed to be non-blocking, if hasNextIntermediateResult() has returned true before for the same caller. Otherwise the caller is blocked until a result is available or the future is finished.- Specified by:
- getNextIntermediateResultin interface- IIntermediateFuture<E>
- Returns:
- The next intermediate result.
 
 - 
getNextIntermediateResultpublic E getNextIntermediateResult(boolean realtime) Iterate over the intermediate results in a blocking fashion. Manages results independently for different callers, i.e. when called from different threads, each thread receives all intermediate results. The operation is guaranteed to be non-blocking, if hasNextIntermediateResult() has returned true before for the same caller. Otherwise the caller is blocked until a result is available or the future is finished.- Returns:
- The next intermediate result.
 
 - 
getNextIntermediateResultpublic E getNextIntermediateResult(long timeout, boolean realtime) Iterate over the intermediate results in a blocking fashion. Manages results independently for different callers, i.e. when called from different threads, each thread receives all intermediate results. The operation is guaranteed to be non-blocking, if hasNextIntermediateResult() has returned true before for the same caller. Otherwise the caller is blocked until a result is available or the future is finished.- Specified by:
- getNextIntermediateResultin interface- IIntermediateFuture<E>
- Parameters:
- timeout- The timeout in millis.
- realtime- Flag, if wait should be realtime (in constrast to simulation time).
- Returns:
- The next intermediate result.
 
 - 
doGetNextIntermediateResultprotected E doGetNextIntermediateResult(int index, long timeout, boolean realtime) Perform the get without increasing the index.
 - 
notifyIntermediateResultprotected void notifyIntermediateResult(IIntermediateResultListener<E> listener, E result) Notify a result listener.- Parameters:
- listener- The listener.
 
 - 
resumeprotected void resume() Resume also intermediate waiters.
 - 
resumeIntermediateprotected void resumeIntermediate() Resume after intermediate result.
 - 
mapAsyncpublic <R> IIntermediateFuture<R> mapAsync(Function<E,IFuture<R>> function) Implements async loop and applies a an async function to each element.- Specified by:
- mapAsyncin interface- IIntermediateFuture<E>
- Parameters:
- function- The function.
- Returns:
- True result intermediate future.
 
 - 
mapAsyncpublic <R> IIntermediateFuture<R> mapAsync(Function<E,IFuture<R>> function, java.lang.Class<?> futuretype) Implements async loop and applies a an async function to each element.- Specified by:
- mapAsyncin interface- IIntermediateFuture<E>
- Parameters:
- function- The function.
- Returns:
- True result intermediate future.
 
 - 
flatMapAsyncpublic <R> IIntermediateFuture<R> flatMapAsync(Function<E,IIntermediateFuture<R>> function) Implements async loop and applies a an async multi-function to each element.- Specified by:
- flatMapAsyncin interface- IIntermediateFuture<E>
- Parameters:
- function- The function.
- Returns:
- True result intermediate future.
 
 
- 
 
-