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 basicAbstractRemoteIterator
by the means for alive time tracking of aRemoteIterator
as well asisSnapshot()
andisForwardOnly()
. 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 ofRemoteIterator
, 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 overridegetSnapshotImpl()
. 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 overridegetSnapshotImpl()
, since this implementation ofgetSnapshotImpl()
throws anUnsupportedOperationException
.
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Thread,AtomicInteger>
busyThreads
The threads which are currently accessing this server-side proxy (and and how often).protected Boolean
snapshot
Whether the iterator is a snapshot.-
Fields inherited from class de.aristaflow.adept2.model.common.collection.AbstractRemoteIterator
cleanup, closeables, logger, transformator
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractTimeTrackingRemoteIterator(boolean snapshot, boolean isForwardOnly, long aliveTime, long aliveTimeExtension)
Deprecated, for removal: This API element is subject to removal in a future version.protected
AbstractTimeTrackingRemoteIterator(boolean snapshot, boolean isForwardOnly, long aliveTime, long aliveTimeExtension, Logger logger)
Creates a new remote iterator with the designated attributes.protected
AbstractTimeTrackingRemoteIterator(boolean isForwardOnly, long initialAliveTime, long aliveTimeExtension)
Deprecated, for removal: This API element is subject to removal in a future version.protected
AbstractTimeTrackingRemoteIterator(boolean isForwardOnly, long initialAliveTime, long aliveTimeExtension, Logger logger)
Creates a new remote iterator with the designated attributes with the snapshot being retrieved viagetSnapshotImpl()
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
enter()
Tracks entering a method reentrant which is adding another invocation of the current thread to properly setisBusy()
.protected Long
exit()
Tracks exiting a method reentrant which is removing an invocation of the current thread to properly setisBusy()
.long
getCloseTime()
long
getRemainingAliveTime()
Gets the time in milliseconds this iterator will still be valid and does allow access to the underlying data.protected boolean
getSnapshotImpl()
Gets whether this iterator is a snapshot and therefore its contents is not subject of change while iterating.boolean
isBusy()
boolean
isForwardOnly()
Gets whether this iterator only allows iterating in forward direction, that is calls toRemoteIterator.getNext(int)
but not toRemoteIterator.getNext(int, int)
andRemoteIterator.getPrevious(int)
.boolean
isSnapshot()
Gets whether this iterator is a snapshot and therefore its contents is not subject of change while iterating.long
keepAlive(long aliveTime)
Keeps this iterator alive for the designated time span (in milliseconds).long
setCloseTime(long closeTime)
-
Methods inherited from class de.aristaflow.adept2.model.common.collection.AbstractRemoteIterator
aboutToReturn, close, closeOnTraversal, getAll, getAllImpl, getNext, getNext, getNextImpl, getNextImpl, getPrevious, getPreviousImpl, isClosed, setCloseOnTraversal
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.aristaflow.adept2.model.common.collection.RemoteIterator
drop
-
-
-
-
Field Detail
-
snapshot
protected Boolean snapshot
Whether the iterator is a snapshot. This will either be provided by the constructor or it will benull
which will set the value retrieved fromgetSnapshotImpl()
when first callingisSnapshot()
.
-
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 Detail
-
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 viagetSnapshotImpl()
. Subclasses calling this constructor need to overridegetSnapshotImpl()
.- 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 viagetSnapshotImpl()
. Subclasses calling this constructor need to overridegetSnapshotImpl()
.- 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 Detail
-
getCloseTime
public long getCloseTime()
- Specified by:
getCloseTime
in interfacede.aristaflow.adept2.model.communication.TimeTrackingSsProxy
-
setCloseTime
public long setCloseTime(long closeTime)
- Specified by:
setCloseTime
in interfacede.aristaflow.adept2.model.communication.TimeTrackingSsProxy
-
isBusy
public boolean isBusy()
- Specified by:
isBusy
in interfacede.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 beclosed
automatically 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:
getRemainingAliveTime
in interfaceRemoteIterator<T>
- Specified by:
getRemainingAliveTime
in interfacede.aristaflow.adept2.model.communication.ServerSideProxy
- Specified by:
getRemainingAliveTime
in interfacede.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 interfaceRemoteIterator<T>
- Specified by:
keepAlive
in interfacede.aristaflow.adept2.model.communication.ServerSideProxy
- Specified by:
keepAlive
in interfacede.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, anIOException
will be thrown.
-
enter
protected void enter()
Tracks entering a method reentrant which is adding another invocation of the current thread to properly setisBusy()
.- Overrides:
enter
in classAbstractRemoteIterator<T,T>
-
exit
protected Long exit()
Tracks exiting a method reentrant which is removing an invocation of the current thread to properly setisBusy()
. 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 classAbstractRemoteIterator<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, aDataSourceException
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 interfaceRemoteIterator<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, aDataSourceException
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 toRemoteIterator.getNext(int)
but not toRemoteIterator.getNext(int, int)
andRemoteIterator.getPrevious(int)
. This can be restricted by the underlying data structure, for instance aResultSet
.- Specified by:
isForwardOnly
in interfaceRemoteIterator<T>
- Returns:
- Whether this iterator only allows iterating in forward direction.
- Throws:
DataSourceException
- If there are problems accessing the underlying data source, aDataSourceException
will be thrown.
-
-