public class IntermediateFuture<E> extends Future<java.util.Collection<E>> implements IIntermediateFuture<E>
IForwardCommandFuture.Type
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<ISuspendable,java.lang.String> |
icallers
The blocked intermediate callers (caller->state).
|
protected java.util.Map<java.lang.Thread,java.lang.Integer> |
indices
The index of the next result for a thread.
|
protected boolean |
intermediate
Flag indicating that addIntermediateResult()has been called.
|
protected ICommand<IResultListener<java.util.Collection<E>>> |
notcommand |
protected java.util.List<E> |
results
The intermediate results.
|
CALLER_QUEUED, CALLER_RESUMED, CALLER_SUSPENDED, callers, creation, DEBUG, exception, first, listener, listeners, NO_STACK_COMPACTION, NONE, notifications, result, resultavailable, STACK, undone, UNSET
DONE
Constructor and Description |
---|
IntermediateFuture()
Create a future that is already done.
|
IntermediateFuture(java.util.Collection<E> results)
Create a future that is already done.
|
IntermediateFuture(java.lang.Exception exception)
Create a future that is already done (failed).
|
Modifier and Type | Method and Description |
---|---|
void |
addIntermediateResult(E result)
Add an intermediate result.
|
boolean |
addIntermediateResultIfUndone(E result)
Set the result.
|
void |
addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener)
Add a functional result listener, which called on intermediate results.
|
void |
addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener,
IFunctionalExceptionListener exceptionListener)
Add a functional result listener, which called on intermediate results.
|
void |
addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener,
IFunctionalIntermediateFinishedListener<java.lang.Void> finishedListener)
Add a functional result listener, which called on intermediate results.
|
void |
addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener,
IFunctionalIntermediateFinishedListener<java.lang.Void> finishedListener,
IFunctionalExceptionListener exceptionListener)
Add a functional result listener, which called on intermediate results.
|
void |
addIntermediateResultListener(IIntermediateResultListener<E> intermediateListener)
Add an result listener, which called on intermediate results.
|
void |
addResultListener(IResultListener<java.util.Collection<E>> listener)
Add a result listener.
|
protected boolean |
doAddIntermediateResult(E result,
boolean undone)
Set the result and schedule listener notifications.
|
protected E |
doGetNextIntermediateResult(int index,
long timeout,
boolean realtime)
Perform the get without increasing the index.
|
protected boolean |
doSetFinished(boolean undone)
Declare that the future is finished.
|
protected boolean |
doSetResult(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.
|
E |
getNextIntermediateResult()
Iterate over the intermediate results in a blocking fashion.
|
E |
getNextIntermediateResult(boolean realtime)
Iterate over the intermediate results in a blocking fashion.
|
E |
getNextIntermediateResult(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.
|
boolean |
hasNextIntermediateResult()
Check if there are more results for iteration for the given caller.
|
boolean |
hasNextIntermediateResult(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 void |
notifyIntermediateResult(IIntermediateResultListener<E> listener,
E result)
Notify a result listener.
|
protected void |
resume()
Resume also intermediate waiters.
|
protected void |
resumeIntermediate()
Resume after intermediate result.
|
void |
setFinished()
Declare that the future is finished.
|
boolean |
setFinishedIfUndone()
Declare that the future is finished.
|
protected void |
storeResult(E result)
Add a result.
|
abortGet, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
acceptEither, addResultListener, addResultListener, applyToEither, delegate, exceptionally, exceptionally, exceptionally, get, get, get, get, get, getException, isDone, thenAccept, thenAccept, thenApply, thenApply, thenCombine, thenCompose, thenCompose
protected java.util.List<E> results
protected boolean intermediate
protected java.util.Map<ISuspendable,java.lang.String> icallers
protected java.util.Map<java.lang.Thread,java.lang.Integer> indices
protected ICommand<IResultListener<java.util.Collection<E>>> notcommand
public IntermediateFuture()
result
- The result, if any.public IntermediateFuture(java.util.Collection<E> results)
result
- The result, if any.public IntermediateFuture(java.lang.Exception exception)
exception
- The exception.public java.util.Collection<E> getIntermediateResults()
getIntermediateResults
in interface IIntermediateFuture<E>
public void addIntermediateResult(E result)
public boolean addIntermediateResultIfUndone(E result)
result
- The result.protected boolean doAddIntermediateResult(E result, boolean undone)
protected void storeResult(E result)
result
- The result.protected boolean doSetResult(java.util.Collection<E> result, boolean undone)
doSetResult
in class Future<java.util.Collection<E>>
result
- The result.public void setFinished()
public boolean setFinishedIfUndone()
protected boolean doSetFinished(boolean undone)
public void addResultListener(IResultListener<java.util.Collection<E>> listener)
addResultListener
in interface IFuture<java.util.Collection<E>>
addResultListener
in class Future<java.util.Collection<E>>
listener
- The listener.protected ICommand<IResultListener<java.util.Collection<E>>> getNotificationCommand()
getNotificationCommand
in class Future<java.util.Collection<E>>
public void addIntermediateResultListener(IIntermediateResultListener<E> intermediateListener)
addIntermediateResultListener
in interface IIntermediateFuture<E>
intermediateListener
- The intermediate listener.public void addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener)
addIntermediateResultListener
in interface IIntermediateFuture<E>
intermediateListener
- The intermediate listener.public void addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener, IFunctionalIntermediateFinishedListener<java.lang.Void> finishedListener)
addIntermediateResultListener
in interface IIntermediateFuture<E>
intermediateListener
- The intermediate listener.finishedListener
- The finished listener, called when no more
intermediate results will arrive. If null
, the finish
event will be ignored.public void addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener, IFunctionalExceptionListener exceptionListener)
addIntermediateResultListener
in interface IIntermediateFuture<E>
intermediateListener
- The intermediate listener.exceptionListener
- The listener that is called on exceptions. Passing
null
enables default exception logging.public void addIntermediateResultListener(IFunctionalIntermediateResultListener<E> intermediateListener, IFunctionalIntermediateFinishedListener<java.lang.Void> finishedListener, IFunctionalExceptionListener exceptionListener)
addIntermediateResultListener
in interface IIntermediateFuture<E>
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
null
enables default exception logging.public boolean hasNextIntermediateResult()
hasNextIntermediateResult
in interface IIntermediateFuture<E>
public boolean hasNextIntermediateResult(long timeout, boolean realtime)
hasNextIntermediateResult
in interface IIntermediateFuture<E>
timeout
- The timeout in millis.realtime
- Flag, if wait should be realtime (in constrast to simulation time).public E getNextIntermediateResult()
getNextIntermediateResult
in interface IIntermediateFuture<E>
NoSuchElementException,
- when there are no more intermediate results and the future is finished.public E getNextIntermediateResult(boolean realtime)
NoSuchElementException,
- when there are no more intermediate results and the future is finished.public E getNextIntermediateResult(long timeout, boolean realtime)
getNextIntermediateResult
in interface IIntermediateFuture<E>
timeout
- The timeout in millis.realtime
- Flag, if wait should be realtime (in constrast to simulation time).NoSuchElementException,
- when there are no more intermediate results and the future is finished.protected E doGetNextIntermediateResult(int index, long timeout, boolean realtime)
protected void notifyIntermediateResult(IIntermediateResultListener<E> listener, E result)
listener
- The listener.protected void resume()
protected void resumeIntermediate()
public <R> IIntermediateFuture<R> mapAsync(Function<E,IFuture<R>> function)
mapAsync
in interface IIntermediateFuture<E>
function
- The function.public <R> IIntermediateFuture<R> mapAsync(Function<E,IFuture<R>> function, java.lang.Class<?> futuretype)
mapAsync
in interface IIntermediateFuture<E>
function
- The function.public <R> IIntermediateFuture<R> flatMapAsync(Function<E,IIntermediateFuture<R>> function)
flatMapAsync
in interface IIntermediateFuture<E>
function
- The function.