Class AbstractTimeTrackingRemoteIterator<T>

java.lang.Object
de.aristaflow.adept2.model.common.collection.AbstractRemoteIterator<T,T>
de.aristaflow.adept2.model.common.collection.AbstractTimeTrackingRemoteIterator<T>
Type Parameters:
T - The type of the elements that are iterated.
All Implemented Interfaces:
RemoteIterator<List<T>>, de.aristaflow.adept2.model.communication.ServerSideProxy, de.aristaflow.adept2.model.communication.TimeTrackingSsProxy, Closeable, AutoCloseable
Direct Known Subclasses:
CachingRemoteIterator, EmptyRemoteIterator, MemoryBasedCopyingRemoteIterator, ResultSetRemoteIterator

public abstract class AbstractTimeTrackingRemoteIterator<T> extends AbstractRemoteIterator<T,T> implements de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
This class extends the basic AbstractRemoteIterator by the means for alive time tracking of a RemoteIterator as well as isSnapshot() and isForwardOnly(). It also tracks busy threads to avoid closing a remote iterator while it is being accessed (and possibly its alive time being extended). It disables element transformation.
The alive time tracking is provided via the normal methods of RemoteIterator, subclasses need to provide the methods for the data ignoring the alive time tracking.

The snapshot attribute is either fix and provided via AbstractTimeTrackingRemoteIterator(boolean, boolean, long, long, Logger) or it is a complex condition which requires to override getSnapshotImpl(). In this case the value will only be retrieved when needed. It will then be cached for consecutive calls.
Subclasses need to either provide the {{boolean}} or override getSnapshotImpl(), since this implementation of getSnapshotImpl() throws an UnsupportedOperationException.

  • Field Details

    • snapshot

      protected Boolean snapshot
      Whether the iterator is a snapshot. This will either be provided by the constructor or it will be null which will set the value retrieved from getSnapshotImpl() when first calling isSnapshot().
    • busyThreads

      protected final Map<Thread,AtomicInteger> busyThreads
      The threads which are currently accessing this server-side proxy (and and how often). This is used to avoid closing a currently active server-side proxy.
  • Constructor Details

    • AbstractTimeTrackingRemoteIterator

      @Deprecated(since="15.0.0", forRemoval=true) protected AbstractTimeTrackingRemoteIterator(boolean snapshot, boolean isForwardOnly, long aliveTime, long aliveTimeExtension)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates a new remote iterator with the designated attributes.
      Parameters:
      snapshot - Whether the iterator is a snapshot.
      isForwardOnly - Whether the iterator is forward only.
      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.
    • AbstractTimeTrackingRemoteIterator

      protected AbstractTimeTrackingRemoteIterator(boolean snapshot, boolean isForwardOnly, long aliveTime, long aliveTimeExtension, Logger logger)
      Creates a new remote iterator with the designated attributes.
      Parameters:
      snapshot - Whether the iterator is a snapshot.
      isForwardOnly - Whether the iterator is forward only.
      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.
    • AbstractTimeTrackingRemoteIterator

      @Deprecated(since="15.0.0", forRemoval=true) protected AbstractTimeTrackingRemoteIterator(boolean isForwardOnly, long initialAliveTime, long aliveTimeExtension)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates a new remote iterator with the designated attributes with the snapshot being retrieved via getSnapshotImpl(). Subclasses calling this constructor need to override getSnapshotImpl().
      Parameters:
      isForwardOnly - Whether the iterator is forward only.
      initialAliveTime - The time in milliseconds this remote iterator is alive.
      aliveTimeExtension - The time in milliseconds to extend the alive time when accessing this remote iterator.
    • AbstractTimeTrackingRemoteIterator

      protected AbstractTimeTrackingRemoteIterator(boolean isForwardOnly, long initialAliveTime, long aliveTimeExtension, Logger logger)
      Creates a new remote iterator with the designated attributes with the snapshot being retrieved via getSnapshotImpl(). Subclasses calling this constructor need to override getSnapshotImpl().
      Parameters:
      isForwardOnly - Whether the iterator is forward only.
      initialAliveTime - 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 messages instead of throwing exceptions.
  • Method Details

    • getCloseTime

      public long getCloseTime()
      Specified by:
      getCloseTime in interface de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
    • setCloseTime

      public long setCloseTime(long closeTime)
      Specified by:
      setCloseTime in interface de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
    • isBusy

      public boolean isBusy()
      Specified by:
      isBusy in interface de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
    • getRemainingAliveTime

      public long getRemainingAliveTime()
      Description copied from interface: RemoteIterator
      Gets the time in milliseconds this iterator will still be valid and does allow access to the underlying data. Afterwards the iterator will be closed automatically to save memory and resources.
      A negative value indicates a closed iterator. Such an iterator cannot be kept alive. Note that this alive time does not need to correspond to the original alive time requested
      Specified by:
      getRemainingAliveTime in interface RemoteIterator<T>
      Specified by:
      getRemainingAliveTime in interface de.aristaflow.adept2.model.communication.ServerSideProxy
      Specified by:
      getRemainingAliveTime in interface de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
      Returns:
      The time this iterator remains valid and can be used. Afterwards the iterator will be closed. Long.MIN_VALUE for an already closed remote iterator.
    • keepAlive

      public long keepAlive(long aliveTime) throws IOException
      Description copied from interface: RemoteIterator
      Keeps 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 closed this iterator.

      Specified by:
      keepAlive in interface RemoteIterator<T>
      Specified by:
      keepAlive in interface de.aristaflow.adept2.model.communication.ServerSideProxy
      Specified by:
      keepAlive in interface de.aristaflow.adept2.model.communication.TimeTrackingSsProxy
      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 IOException will be thrown.
    • enter

      protected void enter()
      Tracks entering a method reentrant which is adding another invocation of the current thread to properly set isBusy().
      Overrides:
      enter in class AbstractRemoteIterator<T,T>
    • exit

      protected Long exit()
      Tracks exiting a method reentrant which is removing an invocation of the current thread to properly set 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.
      Overrides:
      exit in class AbstractRemoteIterator<T,T>
      Returns:
      The possibly new remaining alive time in milliseconds or null in case the thread is still active and not exiting finally.
    • getSnapshotImpl

      protected boolean getSnapshotImpl() throws DataSourceException
      Gets 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.

      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 DataSourceException will be thrown.
    • isSnapshot

      public final boolean isSnapshot() throws DataSourceException
      Description copied from interface: RemoteIterator
      Gets whether this iterator is a snapshot and therefore its contents is not subject of change while iterating. However, the contents may be outdated while iterating.
      Specified by:
      isSnapshot in interface RemoteIterator<T>
      Returns:
      Whether this iterator is a snapshot providing stable but maybe outdated data.
      Throws:
      DataSourceException - If there are problems accessing the underlying data source, a DataSourceException will be thrown.
    • isForwardOnly

      public final boolean isForwardOnly() throws DataSourceException
      Description copied from interface: RemoteIterator
      Gets whether this iterator only allows iterating in forward direction, that is calls to RemoteIterator.getNext(int) but not to RemoteIterator.getNext(int, int) and RemoteIterator.getPrevious(int). This can be restricted by the underlying data structure, for instance a ResultSet.
      Specified by:
      isForwardOnly in interface RemoteIterator<T>
      Returns:
      Whether this iterator only allows iterating in forward direction.
      Throws:
      DataSourceException - If there are problems accessing the underlying data source, a DataSourceException will be thrown.