Package jadex.commons.future
Class SubscriptionIntermediateFuture<E>
- java.lang.Object
-
- jadex.commons.future.Future<java.util.Collection<E>>
-
- jadex.commons.future.IntermediateFuture<E>
-
- jadex.commons.future.TerminableIntermediateFuture<E>
-
- jadex.commons.future.SubscriptionIntermediateFuture<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:
PullSubscriptionIntermediateFuture
public class SubscriptionIntermediateFuture<E> extends TerminableIntermediateFuture<E> implements ISubscriptionIntermediateFuture<E>
Implementation of the subscription intermediate future.
-
-
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 int
resultssize
The number of results.protected boolean
storeforfirst
Flag if results should be stored till first listener is added.-
Fields inherited from class jadex.commons.future.TerminableIntermediateFuture
bcommands, terminate
-
Fields inherited from class jadex.commons.future.IntermediateFuture
icallers, indices, intermediate, maxresultcnt, notcommand, results
-
Fields inherited from class jadex.commons.future.Future
CALLER_QUEUED, CALLER_RESUMED, CALLER_SUSPENDED, callers, creation, DEBUG, exception, first, listeners, NO_STACK_COMPACTION, NONE, NOTIFICATIONS, notificount, result, resultavailable, undone, UNSET
-
Fields inherited from interface jadex.commons.future.IIntermediateFuture
DONE
-
-
Constructor Summary
Constructors Constructor Description SubscriptionIntermediateFuture()
Create a new future.SubscriptionIntermediateFuture(ITerminationCommand terminate)
Create a new future.SubscriptionIntermediateFuture(ITerminationCommand terminate, boolean storeforfirst)
Create a new future.SubscriptionIntermediateFuture(java.lang.Exception exception)
Create a future that is already done (failed).
-
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.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.protected int
getResultCount()
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.void
setMaxResultCount(int max)
Unsupported for subscriptions.protected void
storeResult(E result, boolean scheduled)
Add a result.-
Methods inherited from class jadex.commons.future.TerminableIntermediateFuture
addBackwardCommand, getTerminationCommand, removeBackwardCommand, sendBackwardCommand, setTerminationCommand, terminate, terminate
-
Methods inherited from class jadex.commons.future.IntermediateFuture
addIntermediateResult, addIntermediateResultIfUndone, addIntermediateResultListener, catchErr, doAddIntermediateResult, doSetException, doSetFinished, doSetResult, finished, flatMapAsync, getNextIntermediateResult, getNextIntermediateResult, getNotificationCommand, hasNextIntermediateResult, mapAsync, mapAsync, max, next, notifyIntermediateResult, resume, resumeIntermediate, scheduleMaxNotification, setFinished, setFinishedIfUndone
-
Methods inherited from class jadex.commons.future.Future
abortGet, catchErr, catchErr, delegate, doAddResultListener, doStartScheduledNotifications, executeNotification, get, get, get, get, get, getEmptyFuture, getException, getFuture, hasResultListener, isDone, scheduleNotification, scheduleNotification, sendForwardCommand, setException, setExceptionIfUndone, setResult, setResultIfUndone, startScheduledNotifications, then, 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
catchErr, catchErr, catchErr, delegate, get, get, get, get, get, getException, isDone, then, thenApply, thenApply, thenCompose, thenCompose
-
Methods inherited from interface jadex.commons.future.IIntermediateFuture
finished, flatMapAsync, getNextIntermediateResult, hasNextIntermediateResult, mapAsync, mapAsync, max, next
-
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 added.
-
resultssize
protected int resultssize
The number of results.
-
-
Constructor Detail
-
SubscriptionIntermediateFuture
public SubscriptionIntermediateFuture()
Create a new future.
-
SubscriptionIntermediateFuture
public SubscriptionIntermediateFuture(java.lang.Exception exception)
Create a future that is already done (failed).- Parameters:
exception
- The exception.
-
SubscriptionIntermediateFuture
public SubscriptionIntermediateFuture(ITerminationCommand terminate)
Create a new future.- Parameters:
terminate
- The code to be executed in case of termination.
-
SubscriptionIntermediateFuture
public SubscriptionIntermediateFuture(ITerminationCommand terminate, boolean storeforfirst)
Create a new future.- Parameters:
terminate
- The code to be executed in case of termination.
-
-
Method Detail
-
setMaxResultCount
public void setMaxResultCount(int max)
Unsupported for subscriptions.- Overrides:
setMaxResultCount
in classIntermediateFuture<E>
- Parameters:
max
- The maximum number of results.
-
storeResult
protected void storeResult(E result, boolean scheduled)
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
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:
listsner
- 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>
-
-