Package jadex.future
Class SubscriptionIntermediateDelegationFuture<E>
java.lang.Object
jadex.future.Future<Collection<E>>
jadex.future.IntermediateFuture<E>
jadex.future.TerminableIntermediateDelegationFuture<E>
jadex.future.SubscriptionIntermediateDelegationFuture<E>
- All Implemented Interfaces:
IBackwardCommandFuture
,IForwardCommandFuture
,IFuture<Collection<E>>
,IIntermediateFuture<E>
,ISubscriptionIntermediateFuture<E>
,ITerminableFuture<Collection<E>>
,ITerminableIntermediateFuture<E>
,Supplier<Collection<E>>
- Direct Known Subclasses:
PullSubscriptionIntermediateDelegationFuture
public class SubscriptionIntermediateDelegationFuture<E>
extends TerminableIntermediateDelegationFuture<E>
implements ISubscriptionIntermediateFuture<E>
-
Nested Class Summary
Nested classes/interfaces inherited from interface jadex.future.IForwardCommandFuture
IForwardCommandFuture.Type
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe local results for a single thread.protected int
The number of results.protected boolean
Flag if results should be stored till first listener is.Fields inherited from class jadex.future.TerminableIntermediateDelegationFuture
handler
Fields inherited from class jadex.future.IntermediateFuture
icallers, indices, intermediate, maxresultcnt, notcommand, results
Fields inherited from class jadex.future.Future
CALLER_QUEUED, CALLER_RESUMED, CALLER_SUSPENDED, callers, creation, DEBUG, exception, first, listeners, NO_STACK_COMPACTION, NONE, NOTIFICATIONS, notificount, notified, result, resultavailable, undone, UNSET
Fields inherited from interface jadex.future.IIntermediateFuture
DONE
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new future.Create a new future. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addQuietListener
(IResultListener<Collection<E>> listener) Add a listener which is only informed about new results, i.e.void
addResultListener
(IResultListener<Collection<E>> listener) Add a result listener.<T> IIntermediateFuture
<E> Called on exception.Called on exception.protected E
doGetNextIntermediateResult
(int index, long timeout, boolean realtime) Perform the get without increasing the index.IIntermediateFuture
<? extends E> Called when the future is finished.Get the intermediate results that are available.getNextIntermediateResult
(long timeout, boolean realtime) Iterate over the intermediate results in a blocking fashion.protected int
Get the number of results already collected.boolean
hasNextIntermediateResult
(long timeout, boolean realtime) Check if there are more results for iteration for the given caller.IIntermediateFuture
<? extends E> Called when the maximum number of results is available.protected void
storeResult
(E result, boolean scheduled) Add a result.Methods inherited from class jadex.future.TerminableIntermediateDelegationFuture
delegateFrom, sendBackwardCommand, setTerminationSource, terminate, terminate
Methods inherited from class jadex.future.IntermediateFuture
addIntermediateResult, addIntermediateResultIfUndone, asStream, asStream, delegateEx, doAddIntermediateResult, done, doSetException, doSetFinished, doSetResult, getNextIntermediateResult, getNextIntermediateResult, getNotificationCommand, hasNextIntermediateResult, next, notifyIntermediateResult, resume, resumeIntermediate, scheduleMaxNotification, setFinished, setFinishedIfUndone, setMaxResultCount, then
Methods inherited from class jadex.future.Future
abortGet, catchEx, delegate, delegateTo, doAddResultListener, doStartScheduledNotifications, executeNotification, get, get, get, get, get, getEmptyFuture, getException, getFuture, hasResultListener, isDone, isNotified, printOnEx, scheduleNotification, scheduleNotification, sendForwardCommand, setException, setExceptionIfUndone, setResult, setResultIfUndone, startScheduledNotifications, thenAccept, thenAccept, thenApply, thenApply, thenCombine, thenCompose, thenCompose, throwException
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface jadex.future.IBackwardCommandFuture
sendBackwardCommand
Methods inherited from interface jadex.future.IFuture
catchEx, delegate, delegateTo, get, get, get, get, get, getException, isDone, printOnEx, then, thenApply, thenApply, thenCompose, thenCompose
Methods inherited from interface jadex.future.IIntermediateFuture
asStream, asStream, done, getNextIntermediateResult, hasNextIntermediateResult, next
Methods inherited from interface jadex.future.ITerminableFuture
terminate, terminate
-
Field Details
-
ownresults
The local results for a single thread. -
storeforfirst
protected boolean storeforfirstFlag if results should be stored till first listener is. -
resultssize
protected int resultssizeThe number of results.
-
-
Constructor Details
-
SubscriptionIntermediateDelegationFuture
public SubscriptionIntermediateDelegationFuture()Create a new future. -
SubscriptionIntermediateDelegationFuture
Create a new future.
-
-
Method Details
-
storeResult
Add a result.- Overrides:
storeResult
in classIntermediateFuture<E>
- Parameters:
result
- The result.scheduled
- True, if any listener notification has been scheduled for this result. (used for subscription futures to check for lost values)
-
getResultCount
protected int getResultCount()Get the number of results already collected.- Overrides:
getResultCount
in classIntermediateFuture<E>
- Returns:
- The number of results.
-
addQuietListener
Add a listener which is only informed about new results, i.e. the initial results are not posted to this listener, even if it is the first listener to be added to this future.- Specified by:
addQuietListener
in interfaceISubscriptionIntermediateFuture<E>
-
addResultListener
Add a result listener.- Specified by:
addResultListener
in interfaceIFuture<E>
- Overrides:
addResultListener
in classIntermediateFuture<E>
- Parameters:
listener
- The listener.
-
getIntermediateResults
Get the intermediate results that are available. Note: The semantics of this method is different to the normal intermediate future due to the fire-and-forget-semantics!- Specified by:
getIntermediateResults
in interfaceIIntermediateFuture<E>
- Specified by:
getIntermediateResults
in interfaceISubscriptionIntermediateFuture<E>
- Overrides:
getIntermediateResults
in classIntermediateFuture<E>
- Returns:
- 1) Non-blocking access only: An empty collection, unless if the future is in "store-for-first" mode (default)
and no listeners has yet been added, in which case the results until now are returned.
2) Also blocking access from same thread: All results since the first blocking access that have not yet been consumed by getNextIntermediateResult().
-
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:
getNextIntermediateResult
in interfaceIIntermediateFuture<E>
- Overrides:
getNextIntermediateResult
in classIntermediateFuture<E>
- Parameters:
timeout
- The timeout in millis.realtime
- Flag, if wait should be realtime (in constrast to simulation time).- Returns:
- The next intermediate result.
- Throws:
NoSuchElementException
- when there are no more intermediate results and the future is finished.
-
hasNextIntermediateResult
public 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:
hasNextIntermediateResult
in interfaceIIntermediateFuture<E>
- Overrides:
hasNextIntermediateResult
in classIntermediateFuture<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.
-
doGetNextIntermediateResult
Perform the get without increasing the index.- Overrides:
doGetNextIntermediateResult
in classIntermediateFuture<E>
-
catchEx
Called on exception. -
catchEx
Called on exception. -
max
Called when the maximum number of results is available.- Specified by:
max
in interfaceIIntermediateFuture<E>
- Overrides:
max
in classIntermediateFuture<E>
- Parameters:
function
- Called when max value arrives.- Returns:
- The future for chaining.
-
finished
Called when the future is finished.- Specified by:
finished
in interfaceIIntermediateFuture<E>
- Overrides:
finished
in classIntermediateFuture<E>
- Parameters:
function
- Called when max value arrives.- Returns:
- The future for chaining.
-