Class TransformingRemoteIterator<S,T>
- java.lang.Object
-
- de.aristaflow.adept2.model.common.collection.AbstractRemoteIterator<S,T>
-
- de.aristaflow.adept2.model.common.collection.TransformingRemoteIterator<S,T>
-
- Type Parameters:
S- The type of objects that are retrieved from the wrapped remote iterator.T- The type of objects that are returned by this remote iterator.
- All Implemented Interfaces:
RemoteIterator<List<T>>,de.aristaflow.adept2.model.communication.ServerSideProxy,Closeable,AutoCloseable
public class TransformingRemoteIterator<S,T> extends AbstractRemoteIterator<S,T>
This iterator wraps a remote iterator and transforms all objects before returning them using the provided transformator. It closes elements if appropriate depending on whether the wrapped iteratorisForwardOnly().
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classTransformingRemoteIterator.TransformingRemoteIteratorCloseTaskThe clean-up task for closing the wrappedRemoteIterator.
-
Field Summary
Fields Modifier and Type Field Description protected RemoteIterator<List<S>>iteratorThe wrapped iterator providing the objects.-
Fields inherited from class de.aristaflow.adept2.model.common.collection.AbstractRemoteIterator
cleanup, closeables, logger, transformator
-
-
Constructor Summary
Constructors Constructor Description TransformingRemoteIterator(RemoteIterator<List<S>> iterator, Function<S,T> transformator)Deprecated, for removal: This API element is subject to removal in a future version.TransformingRemoteIterator(RemoteIterator<List<S>> iterator, Function<S,T> transformator, Logger logger)Creates a new remote iterator that wraps the designated remote iterator and transforms all objects before returning them using the designated transformator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Explicitly closes this iterator which allows to release occupied memory and resources.protected List<S>getAllImpl()ImplementsAbstractRemoteIterator.getAll()without the need to consider result transformation, closeable and alive time tracking.protected List<S>getNextImpl(int count)ImplementsAbstractRemoteIterator.getNext(int)without the need to consider result transformation, closeable and alive time tracking.protected List<S>getNextImpl(int count, int start)ImplementsAbstractRemoteIterator.getNext(int, int)without the need to consider result transformation, closeable and alive time tracking.protected List<S>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 booleanisClosed()Gets whether this remote iterator has been closed and its data is not available any more.booleanisForwardOnly()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).booleanisSnapshot()Gets whether this iterator is a snapshot and therefore its contents is not subject of change while iterating.longkeepAlive(long aliveTime)Keeps this iterator alive for the designated time span (in milliseconds).-
Methods inherited from class de.aristaflow.adept2.model.common.collection.AbstractRemoteIterator
aboutToReturn, closeOnTraversal, enter, exit, getAll, getNext, getNext, getPrevious, 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
-
iterator
protected final RemoteIterator<List<S>> iterator
The wrapped iterator providing the objects.
-
-
Constructor Detail
-
TransformingRemoteIterator
@Deprecated(since="15.0.0", forRemoval=true) public TransformingRemoteIterator(RemoteIterator<List<S>> iterator, Function<S,T> transformator)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a new remote iterator that wraps the designated remote iterator and transforms all objects before returning them using the designated transformator.- Parameters:
iterator- The wrapped iterator providing the objects. The RemoteIterator will be coupled to thisTransformingRemoteIterator, so do not close it; clone it if required longer than thisTransformingRemoteIterator.transformator- The transformator transforming the objects before retrieval.
-
TransformingRemoteIterator
public TransformingRemoteIterator(RemoteIterator<List<S>> iterator, Function<S,T> transformator, Logger logger)
Creates a new remote iterator that wraps the designated remote iterator and transforms all objects before returning them using the designated transformator.- Parameters:
iterator- The wrapped iterator providing the objects. The RemoteIterator will be coupled to thisTransformingRemoteIterator, so do not close it; clone it if required longer than thisTransformingRemoteIterator.transformator- The transformator transforming the objects before retrieval.logger- The logger for logging messages instead of throwing exceptions.
-
-
Method Detail
-
isClosed
protected 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 classAbstractRemoteIterator<S,T>- Returns:
- Whether this remote iterator has been closed and its data is not available any more.
-
getNextImpl
protected List<S> 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 classAbstractRemoteIterator<S,T>- Throws:
DataSourceExceptionDataConsistencyException
-
getNextImpl
protected List<S> 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 classAbstractRemoteIterator<S,T>- Throws:
DataSourceExceptionDataConsistencyException
-
getPreviousImpl
protected List<S> 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 classAbstractRemoteIterator<S,T>- Throws:
DataSourceExceptionDataConsistencyException
-
getAllImpl
protected List<S> 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 classAbstractRemoteIterator<S,T>- Throws:
DataSourceExceptionDataConsistencyException
-
isSnapshot
public boolean isSnapshot() throws DataSourceExceptionDescription copied from interface:RemoteIteratorGets 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.- Returns:
- Whether this iterator is a snapshot providing stable but maybe outdated data.
- Throws:
DataSourceException- If there are problems accessing the underlying data source, aDataSourceExceptionwill be thrown.
-
isForwardOnly
public boolean isForwardOnly() throws DataSourceExceptionDescription copied from interface:RemoteIteratorGets 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.- Returns:
- Whether this iterator only allows iterating in forward direction.
- Throws:
DataSourceException- If there are problems accessing the underlying data source, aDataSourceExceptionwill be thrown.
-
getRemainingAliveTime
public 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- 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.
-
keepAlive
public 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.- 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, anIOExceptionwill be thrown.
-
close
public 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 interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceRemoteIterator<S>- Specified by:
closein interfacede.aristaflow.adept2.model.communication.ServerSideProxy- Overrides:
closein classAbstractRemoteIterator<S,T>- Throws:
IOException- If there are problems accessing the underlying data source, anIOExceptionwill be thrown.
-
-