Class CachingRemoteIterator<T>
- java.lang.Object
- 
- de.aristaflow.adept2.model.common.collection.AbstractRemoteIterator<T,T>
- 
- de.aristaflow.adept2.model.common.collection.AbstractTimeTrackingRemoteIterator<T>
- 
- de.aristaflow.adept2.model.common.collection.CachingRemoteIterator<T>
 
 
 
- 
- Type Parameters:
- T- The type of the elements that are retrieved from the cached iterator.
 - All Implemented Interfaces:
- RemoteIterator<List<T>>,- de.aristaflow.adept2.model.communication.ServerSideProxy,- de.aristaflow.adept2.model.communication.TimeTrackingSsProxy,- Closeable,- AutoCloseable
 
 public class CachingRemoteIterator<T> extends AbstractTimeTrackingRemoteIterator<T> This iterator implements a cache for the underlying iterator, that is, when iterating viaAbstractRemoteIterator.getNext(int), all retrieved elements will be cached. Previous elements will always be retrieved from the cache. Note that apositioned nextwill add enough elements to the cache to fulfil the request. As soon as all elements have been retrieved, the wrapped remote iterator will be closed.
 It has an expiring alive time thus allowing to release the occupied memory even if no explicitclose()occurs. This alive time is kept in sync with the underlying iterator until all elements have been retrieved (and are thus cached).
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description protected static classCachingRemoteIterator.CachingRemoteIteratorCloseTaskThe clean-up task for closing the wrappedRemoteIterator.
 - 
Field SummaryFields Modifier and Type Field Description protected intcurrentThe reference to the current element which is to be retrieved next.protected List<T>elementsThe elements that have been retrieved from the underlying remote iterator so far.protected intlastThe index of last element in case it has been reached in the result set, -1 otherwise.protected intlastCachedThe index of the last element that is in the cache.protected RemoteIterator<List<T>>wrappedIteratorThe wrapped iterator of which all elements will be cached.- 
Fields inherited from class de.aristaflow.adept2.model.common.collection.AbstractTimeTrackingRemoteIteratorbusyThreads, snapshot
 - 
Fields inherited from class de.aristaflow.adept2.model.common.collection.AbstractRemoteIteratorcleanup, closeables, logger, transformator
 
- 
 - 
Constructor SummaryConstructors Constructor Description CachingRemoteIterator(RemoteIterator<List<T>> wrappedIterator)Deprecated, for removal: This API element is subject to removal in a future version.CachingRemoteIterator(RemoteIterator<List<T>> wrappedIterator, long aliveTime, long aliveTimeExtension, Logger logger)Creates a new caching remote iterator for the designated iterator.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Explicitly closes this iterator which allows to release occupied memory and resources.protected voidcloseWrappedDse()closeWrappedException(boolean)keeping this iterator alive and wrappingIOExceptionin aDataSourceExceptionor unwrapping aDataSourceExceptionfrom anIOExceptionif appropriate.protected voidcloseWrappedIoe(boolean keepAlive)closeWrappedException(boolean)closing this iterator implicitly and wrapping aDataSourceExceptionin aIOExceptionor unwrapping aIOExceptionfrom anDataSourceExceptionif appropriate.protected Longexit()Tracks exiting a method reentrant which is removing an invocation of the current thread to properly setAbstractTimeTrackingRemoteIterator.isBusy().protected List<T>getAllImpl()ImplementsAbstractRemoteIterator.getAll()without the need to consider result transformation, closeable and alive time tracking.protected List<T>getNextImpl(int count)ImplementsAbstractRemoteIterator.getNext(int)without the need to consider result transformation, closeable and alive time tracking.protected List<T>getNextImpl(int count, int start)ImplementsAbstractRemoteIterator.getNext(int, int)without the need to consider result transformation, closeable and alive time tracking.protected List<T>getPreviousImpl(int count)ImplementsAbstractRemoteIterator.getPrevious(int)without the need to consider result transformation, closeable and alive time tracking.longgetRemainingAliveTime()Gets the time in milliseconds this iterator will still be valid and does allow access to the underlying data.protected booleangetSnapshotImpl()Gets whether this iterator is a snapshot and therefore its contents is not subject of change while iterating.protected booleanisClosed()Gets whether this remote iterator has been closed and its data is not available any more.longkeepAlive(long aliveTime)Keeps this iterator alive for the designated time span (in milliseconds).- 
Methods inherited from class de.aristaflow.adept2.model.common.collection.AbstractTimeTrackingRemoteIteratorenter, getCloseTime, isBusy, isForwardOnly, isSnapshot, setCloseTime
 - 
Methods inherited from class de.aristaflow.adept2.model.common.collection.AbstractRemoteIteratoraboutToReturn, closeOnTraversal, getAll, getNext, getNext, getPrevious, setCloseOnTraversal
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface de.aristaflow.adept2.model.common.collection.RemoteIteratordrop
 
- 
 
- 
- 
- 
Field Detail- 
wrappedIteratorprotected RemoteIterator<List<T>> wrappedIterator The wrapped iterator of which all elements will be cached. Note that the current cursor need not correspond to the current cursor of the underlying iterator. This will benullwhen the wrapped iterator has been closed.
 - 
elementsprotected List<T> elements The elements that have been retrieved from the underlying remote iterator so far.nullindicates that this caching remote iterator has been closed.
 - 
lastCachedprotected int lastCached The index of the last element that is in the cache. This corresponds to the current index of the wrapped iterator.
 - 
lastprotected int last The index of last element in case it has been reached in the result set, -1 otherwise.
 - 
currentprotected int current The reference to the current element which is to be retrieved next.
 
- 
 - 
Constructor Detail- 
CachingRemoteIterator@Deprecated(since="15.0.0", forRemoval=true) public CachingRemoteIterator(RemoteIterator<List<T>> wrappedIterator) Deprecated, for removal: This API element is subject to removal in a future version.Creates a new caching remote iterator for the designated iterator sending no close notification for the wrapped iterator.- Parameters:
- wrappedIterator- The iterator of which the elements should be cached as soon as they are iterated (with- AbstractRemoteIterator.getNext(int)).
 
 - 
CachingRemoteIteratorpublic CachingRemoteIterator(RemoteIterator<List<T>> wrappedIterator, long aliveTime, long aliveTimeExtension, Logger logger) Creates a new caching remote iterator for the designated iterator.- Parameters:
- wrappedIterator- The iterator of which the elements should be cached as soon as they are iterated (with- AbstractRemoteIterator.getNext(int)).
- aliveTime- The time in milliseconds this remote iterator is alive.
- aliveTimeExtension- The time in milliseconds to extend the alive time when accessing this remote iterator.
- logger- The logger for logging exceptions from the wrapped remote iterator that cannot be forwarded or are irrelevant.
 
 
- 
 - 
Method Detail- 
exitprotected Long exit() Tracks exiting a method reentrant which is removing an invocation of the current thread to properly setAbstractTimeTrackingRemoteIterator.isBusy(). If the thread leaves completely, the alive time will be extended; it will not be shortened in case the extension is less than the already set close time. If this remote iterator has been closed, no extension will take place. As long as the wrapped remote iterator is alive, we need to keep it alive since we may need to retrieve data that is not in the cache yet. Otherwise going to previous elements will not extend the alive time of the wrapped iterator but extend the alive time of the caching remote iterator.- Overrides:
- exitin class- AbstractTimeTrackingRemoteIterator<T>
- Returns:
- The possibly new remaining alive time in milliseconds or nullin case the thread is still active and not exiting finally.
 
 - 
isClosedprotected boolean isClosed() Description copied from class:AbstractRemoteIteratorGets whether this remote iterator has been closed and its data is not available any more.- Specified by:
- isClosedin class- AbstractRemoteIterator<T,T>
- Returns:
- Whether this remote iterator has been closed and its data is not available any more.
 
 - 
getNextImplprotected List<T> getNextImpl(int count) throws DataSourceException, DataConsistencyException Description copied from class:AbstractRemoteIteratorImplementsAbstractRemoteIterator.getNext(int)without the need to consider result transformation, closeable and alive time tracking.- Specified by:
- getNextImplin class- AbstractRemoteIterator<T,T>
- Throws:
- DataSourceException
- DataConsistencyException
 
 - 
getNextImplprotected List<T> getNextImpl(int count, int start) throws DataSourceException, DataConsistencyException Description copied from class:AbstractRemoteIteratorImplementsAbstractRemoteIterator.getNext(int, int)without the need to consider result transformation, closeable and alive time tracking.- Specified by:
- getNextImplin class- AbstractRemoteIterator<T,T>
- Throws:
- DataSourceException
- DataConsistencyException
 
 - 
getPreviousImplprotected List<T> getPreviousImpl(int count) throws DataSourceException, DataConsistencyException Description copied from class:AbstractRemoteIteratorImplementsAbstractRemoteIterator.getPrevious(int)without the need to consider result transformation, closeable and alive time tracking.- Specified by:
- getPreviousImplin class- AbstractRemoteIterator<T,T>
- Throws:
- DataSourceException
- DataConsistencyException
 
 - 
getAllImplprotected List<T> getAllImpl() throws DataSourceException, DataConsistencyException Description copied from class:AbstractRemoteIteratorImplementsAbstractRemoteIterator.getAll()without the need to consider result transformation, closeable and alive time tracking.- Specified by:
- getAllImplin class- AbstractRemoteIterator<T,T>
- Throws:
- DataSourceException
- DataConsistencyException
 
 - 
getSnapshotImplprotected boolean getSnapshotImpl() throws DataSourceExceptionDescription copied from class:AbstractTimeTrackingRemoteIteratorGets whether this iterator is a snapshot and therefore its contents is not subject of change while iterating.
 This method will need to be overridden if the snapshot status cannot be provided when creating this instance (AbstractTimeTrackingRemoteIterator(boolean, boolean, long, long, Logger)).This implementation always throws an UnsupportedOperationException.- Overrides:
- getSnapshotImplin class- AbstractTimeTrackingRemoteIterator<T>
- Returns:
- Whether this iterator is a snapshot and therefore its contents is not subject of change while iterating.
- Throws:
- DataSourceException- If there are problems retrieving the snapshot status of this remote iterator, a- DataSourceExceptionwill be thrown.
 
 - 
getRemainingAliveTimepublic long getRemainingAliveTime() Description copied from interface:RemoteIteratorGets the time in milliseconds this iterator will still be valid and does allow access to the underlying data. Afterwards the iterator will beclosedautomatically to save memory and resources.
 A negative value indicates a closed iterator. Such an iterator cannot bekept alive. Note that this alive time does not need to correspond to the original alive time requested- Specified by:
- getRemainingAliveTimein interface- RemoteIterator<T>
- Specified by:
- getRemainingAliveTimein interface- de.aristaflow.adept2.model.communication.ServerSideProxy
- Specified by:
- getRemainingAliveTimein interface- de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
- Overrides:
- getRemainingAliveTimein class- AbstractTimeTrackingRemoteIterator<T>
- Returns:
- The time this iterator remains valid and can be used. Afterwards the iterator will be
         closed.Long.MIN_VALUEfor an already closed remote iterator.
 
 - 
keepAlivepublic long keepAlive(long aliveTime) throws IOExceptionDescription copied from interface:RemoteIteratorKeeps this iterator alive for the designated time span (in milliseconds). This allows to continue using this iterator. However, note that extending the usage time significantly impacts resource occupation.
 Note that extending the time need not be successful. The underlying iterator implementation may not be able to extend the alive time of all used resource, for instance pooled database connections.A 0 or a negative value is equal to closedthis iterator.- Specified by:
- keepAlivein interface- RemoteIterator<T>
- Specified by:
- keepAlivein interface- de.aristaflow.adept2.model.communication.ServerSideProxy
- Specified by:
- keepAlivein interface- de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
- Overrides:
- keepAlivein class- AbstractTimeTrackingRemoteIterator<T>
- Parameters:
- aliveTime- The time in milliseconds to keep this iterator alive that is not to close it automatically.
- Returns:
- The relative time this iterator will be kept alive longer. 0 indicates immediate
         closing. A negative value represents the failure of extending the alive time, check
         RemoteIterator.getRemainingAliveTime()in this case whether extending the keep alive time has been successful or not.
- Throws:
- IOException- If there are problems accessing the underlying data source, an- IOExceptionwill be thrown.
 
 - 
closepublic void close() throws IOExceptionDescription copied from interface:RemoteIteratorExplicitly closes this iterator which allows to release occupied memory and resources. Closing will be done implicitly after the alive time has elapsed.
 This method may be called several times. Implementors have to take care of this.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein interface- RemoteIterator<T>
- Specified by:
- closein interface- de.aristaflow.adept2.model.communication.ServerSideProxy
- Overrides:
- closein class- AbstractRemoteIterator<T,T>
- Throws:
- IOException- If there are problems accessing the underlying data source, an- IOExceptionwill be thrown.
 
 - 
closeWrappedIoeprotected void closeWrappedIoe(boolean keepAlive) throws IOExceptioncloseWrappedException(boolean)closing this iterator implicitly and wrapping aDataSourceExceptionin aIOExceptionor unwrapping aIOExceptionfrom anDataSourceExceptionif appropriate.- Parameters:
- keepAlive- Whether to keep this caching remote iterator alive despite the wrapped iterator being closed.
- Throws:
- IOException- If there are problems accessing the underlying data source, an- IOExceptionwill be thrown.
 
 - 
closeWrappedDseprotected void closeWrappedDse() throws DataSourceExceptioncloseWrappedException(boolean)keeping this iterator alive and wrappingIOExceptionin aDataSourceExceptionor unwrapping aDataSourceExceptionfrom anIOExceptionif appropriate.- Throws:
- DataSourceException- If there are problems accessing the underlying data source, a- DataSourceExceptionwill be thrown.
 
 
- 
 
-