Class 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 via AbstractRemoteIterator.getNext(int), all retrieved elements will be cached. Previous elements will always be retrieved from the cache. Note that a positioned next will 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 explicit close() occurs. This alive time is kept in sync with the underlying iterator until all elements have been retrieved (and are thus cached).
    • Field Detail

      • wrappedIterator

        protected 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 be null when the wrapped iterator has been closed.
      • elements

        protected List<T> elements
        The elements that have been retrieved from the underlying remote iterator so far. null indicates that this caching remote iterator has been closed.
      • lastCached

        protected int lastCached
        The index of the last element that is in the cache. This corresponds to the current index of the wrapped iterator.
      • last

        protected int last
        The index of last element in case it has been reached in the result set, -1 otherwise.
      • current

        protected int current
        The reference to the current element which is to be retrieved next.
    • Constructor Detail

      • CachingRemoteIterator

        public 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.