Package jadex.commons.future
Class SubscriptionIntermediateDelegationFuture<E>
- java.lang.Object
-
- jadex.commons.future.Future<java.util.Collection<E>>
-
- jadex.commons.future.IntermediateFuture<E>
-
- jadex.commons.future.TerminableIntermediateDelegationFuture<E>
-
- jadex.commons.future.SubscriptionIntermediateDelegationFuture<E>
-
- All Implemented Interfaces:
IBackwardCommandFuture
,IForwardCommandFuture
,IFuture<java.util.Collection<E>>
,IIntermediateFuture<E>
,ISubscriptionIntermediateFuture<E>
,ITerminableFuture<java.util.Collection<E>>
,ITerminableIntermediateFuture<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.commons.future.IForwardCommandFuture
IForwardCommandFuture.Type
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.Thread,java.util.List<E>>
ownresults
The local results for a single thread.protected boolean
storeforfirst
Flag if results should be stored till first listener is.-
Fields inherited from class jadex.commons.future.TerminableIntermediateDelegationFuture
notified, notify, reason, src, storedinfos
-
Fields inherited from class jadex.commons.future.IntermediateFuture
icallers, indices, intermediate, notcommand, results
-
Fields inherited from class jadex.commons.future.Future
CALLER_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.IIntermediateFuture
DONE
-
-
Constructor Summary
Constructors Constructor Description SubscriptionIntermediateDelegationFuture()
Create a new future.SubscriptionIntermediateDelegationFuture(ITerminableIntermediateFuture<?> src)
Create a new future.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addQuietListener(IResultListener<java.util.Collection<E>> listener)
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.void
addResultListener(IResultListener<java.util.Collection<E>> listener)
Add a result listener.protected E
doGetNextIntermediateResult(int index, long timeout, boolean realtime)
Perform the get without increasing the index.java.util.Collection<E>
getIntermediateResults()
Get the intermediate results that are available.E
getNextIntermediateResult(long timeout, boolean realtime)
Iterate over the intermediate results in a blocking fashion.boolean
hasNextIntermediateResult(long timeout, boolean realtime)
Check if there are more results for iteration for the given caller.protected void
storeResult(E result)
Add a result.-
Methods inherited from class jadex.commons.future.TerminableIntermediateDelegationFuture
doNotify, getSource, sendBackwardCommand, setSource, terminate, terminate
-
Methods inherited from class jadex.commons.future.IntermediateFuture
addIntermediateResult, addIntermediateResultIfUndone, addIntermediateResultListener, addIntermediateResultListener, addIntermediateResultListener, addIntermediateResultListener, addIntermediateResultListener, doAddIntermediateResult, doSetFinished, doSetResult, flatMapAsync, getNextIntermediateResult, getNextIntermediateResult, getNotificationCommand, hasNextIntermediateResult, mapAsync, mapAsync, notifyIntermediateResult, resume, resumeIntermediate, setFinished, setFinishedIfUndone
-
Methods inherited from class jadex.commons.future.Future
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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jadex.commons.future.IBackwardCommandFuture
sendBackwardCommand
-
Methods inherited from interface jadex.commons.future.IFuture
acceptEither, addResultListener, addResultListener, applyToEither, delegate, exceptionally, exceptionally, exceptionally, get, get, get, get, get, getException, isDone, thenAccept, thenAccept, thenApply, thenApply, thenCombine, thenCompose, thenCompose
-
Methods inherited from interface jadex.commons.future.IIntermediateFuture
addIntermediateResultListener, addIntermediateResultListener, addIntermediateResultListener, addIntermediateResultListener, addIntermediateResultListener, flatMapAsync, getNextIntermediateResult, hasNextIntermediateResult, mapAsync, mapAsync
-
Methods inherited from interface jadex.commons.future.ITerminableFuture
terminate, terminate
-
-
-
-
Field Detail
-
ownresults
protected java.util.Map<java.lang.Thread,java.util.List<E>> ownresults
The local results for a single thread.
-
storeforfirst
protected boolean storeforfirst
Flag if results should be stored till first listener is.
-
-
Constructor Detail
-
SubscriptionIntermediateDelegationFuture
public SubscriptionIntermediateDelegationFuture()
Create a new future.
-
SubscriptionIntermediateDelegationFuture
public SubscriptionIntermediateDelegationFuture(ITerminableIntermediateFuture<?> src)
Create a new future.
-
-
Method Detail
-
storeResult
protected void storeResult(E result)
Add a result.- Overrides:
storeResult
in classIntermediateFuture<E>
- Parameters:
result
- The result.
-
addQuietListener
public void addQuietListener(IResultListener<java.util.Collection<E>> listener)
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
public void addResultListener(IResultListener<java.util.Collection<E>> listener)
Add a result listener.- Specified by:
addResultListener
in interfaceIFuture<E>
- Overrides:
addResultListener
in classIntermediateFuture<E>
- Parameters:
listener
- The listener.
-
getIntermediateResults
public java.util.Collection<E> 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)
-
getNextIntermediateResult
public 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:
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.
-
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
protected E doGetNextIntermediateResult(int index, long timeout, boolean realtime)
Perform the get without increasing the index.- Overrides:
doGetNextIntermediateResult
in classIntermediateFuture<E>
-
-