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 java.util.Collection<E> |
results
The intermediate results.
|
protected java.util.List |
scheduled
The scheduled notifications.
|
CALLER_QUEUED, CALLER_RESUMED, CALLER_SUSPENDED, callers, creation, DEBUG, EMPTY, exception, fcommands, first, listener, listeners, NO_STACK_COMPACTION, NONE, 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(IFunctionalResultListener<E> intermediateListener)
Add a functional result listener, which called on intermediate results.
|
void |
addIntermediateResultListener(IFunctionalResultListener<E> intermediateListener,
IFunctionalResultListener<java.lang.Void> finishedListener)
Add a functional result listener, which called on intermediate results.
|
void |
addIntermediateResultListener(IFunctionalResultListener<E> intermediateListener,
IFunctionalResultListener<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.
|
protected void |
addResult(E result)
Add a result.
|
void |
addResultListener(IResultListener<java.util.Collection<E>> listener)
Add a result listener.
|
protected E |
doGetNextIntermediateResult(int index)
Perform the get without increasing the index.
|
protected void |
doNotifyListener(IResultListener<java.util.Collection<E>> listener)
Notify a result listener.
|
<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.
|
boolean |
hasNextIntermediateResult()
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 |
notifyListener(IResultListener<java.util.Collection<E>> listener)
Notify a result listener.
|
protected void |
resume()
Resume also intermediate waiters.
|
protected void |
resumeIntermediate()
Resume after intermediate result.
|
protected void |
scheduleNotification(IResultListener<java.util.Collection<E>> listener,
boolean intermediate,
java.lang.Object result)
Schedule a listener notification.
|
void |
setFinished()
Declare that the future is finished.
|
boolean |
setFinishedIfUndone()
Declare that the future is finished.
|
void |
setResult(java.util.Collection<E> result)
Set the result.
|
boolean |
setResultIfUndone(java.util.Collection<E> result)
Set the result.
|
protected void |
startScheduledNotifications()
Start scheduled listener notifications if not already running.
|
abortGet, acceptEither, addForwardCommand, addResultListener, addResultListener, applyToEither, doSetResult, doSetResultIfUndone, get, get, getEmptyFuture, getException, getFuture, hasResultListener, isDone, notifyListenerCommand, removeForwardCommand, sendForwardCommand, setException, setExceptionIfUndone, thenAccept, thenAccept, thenApply, thenApply, thenCombine, thenCompose, thenCompose
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
acceptEither, addResultListener, addResultListener, applyToEither, get, get, getException, isDone, thenAccept, thenAccept, thenApply, thenApply, thenCombine, thenCompose, thenCompose
protected java.util.Collection<E> results
protected boolean intermediate
protected java.util.List scheduled
protected java.util.Map<ISuspendable,java.lang.String> icallers
protected java.util.Map<java.lang.Thread,java.lang.Integer> indices
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)
protected void addResult(E result)
result
- The result.public boolean addIntermediateResultIfUndone(E result)
result
- The result.public void setResult(java.util.Collection<E> result)
public boolean setResultIfUndone(java.util.Collection<E> result)
setResultIfUndone
in class Future<java.util.Collection<E>>
result
- The result.public void setFinished()
public boolean setFinishedIfUndone()
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>>
listsner
- The listener.public void addIntermediateResultListener(IIntermediateResultListener<E> intermediateListener)
addIntermediateResultListener
in interface IIntermediateFuture<E>
intermediateListener
- The intermediate listener.public void addIntermediateResultListener(IFunctionalResultListener<E> intermediateListener)
addIntermediateResultListener
in interface IIntermediateFuture<E>
intermediateListener
- The intermediate listener.public void addIntermediateResultListener(IFunctionalResultListener<E> intermediateListener, IFunctionalResultListener<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(IFunctionalResultListener<E> intermediateListener, IFunctionalResultListener<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.exListener
- The listener that is called on exceptions. Passing
null
enables default exception logging.public boolean hasNextIntermediateResult()
hasNextIntermediateResult
in interface IIntermediateFuture<E>
public E getNextIntermediateResult()
getNextIntermediateResult
in interface IIntermediateFuture<E>
NoSuchElementException,
- when there are no more intermediate results and the future is finished.protected E doGetNextIntermediateResult(int index)
protected void notifyIntermediateResult(IIntermediateResultListener<E> listener, E result)
listener
- The listener.protected void notifyListener(IResultListener<java.util.Collection<E>> listener)
notifyListener
in class Future<java.util.Collection<E>>
listener
- The listener.protected void doNotifyListener(IResultListener<java.util.Collection<E>> listener)
listener
- The listener.protected void scheduleNotification(IResultListener<java.util.Collection<E>> listener, boolean intermediate, java.lang.Object result)
listener
- The listener to be notified.intermediate
- True for intermediate result, false for final results.result
- The intermediate result (if any).protected void startScheduledNotifications()
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.