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 class
TransformingRemoteIterator.TransformingRemoteIteratorCloseTask
The clean-up task for closing the wrappedRemoteIterator
.
-
Field Summary
Fields Modifier and Type Field Description protected RemoteIterator<List<S>>
iterator
The 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 void
close()
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.long
getRemainingAliveTime()
Gets the time in milliseconds this iterator will still be valid and does allow access to the underlying data.protected boolean
isClosed()
Gets whether this remote iterator has been closed and its data is not available any more.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).-
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:AbstractRemoteIterator
Gets whether this remote iterator has been closed and its data is not available any more.- Specified by:
isClosed
in 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:AbstractRemoteIterator
ImplementsAbstractRemoteIterator.getNext(int)
without the need to consider result transformation, closeable and alive time tracking.- Specified by:
getNextImpl
in classAbstractRemoteIterator<S,T>
- Throws:
DataSourceException
DataConsistencyException
-
getNextImpl
protected List<S> getNextImpl(int count, int start) throws DataSourceException, DataConsistencyException
Description copied from class:AbstractRemoteIterator
ImplementsAbstractRemoteIterator.getNext(int, int)
without the need to consider result transformation, closeable and alive time tracking.- Specified by:
getNextImpl
in classAbstractRemoteIterator<S,T>
- Throws:
DataSourceException
DataConsistencyException
-
getPreviousImpl
protected List<S> getPreviousImpl(int count) throws DataSourceException, DataConsistencyException
Description copied from class:AbstractRemoteIterator
ImplementsAbstractRemoteIterator.getPrevious(int)
without the need to consider result transformation, closeable and alive time tracking.- Specified by:
getPreviousImpl
in classAbstractRemoteIterator<S,T>
- Throws:
DataSourceException
DataConsistencyException
-
getAllImpl
protected List<S> getAllImpl() throws DataSourceException, DataConsistencyException
Description copied from class:AbstractRemoteIterator
ImplementsAbstractRemoteIterator.getAll()
without the need to consider result transformation, closeable and alive time tracking.- Specified by:
getAllImpl
in classAbstractRemoteIterator<S,T>
- Throws:
DataSourceException
DataConsistencyException
-
isSnapshot
public 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.- 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 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
.- 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.
-
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- 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.- 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.
-
close
public void close() throws IOException
Description copied from interface:RemoteIterator
Explicitly 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceRemoteIterator<S>
- Specified by:
close
in interfacede.aristaflow.adept2.model.communication.ServerSideProxy
- Overrides:
close
in classAbstractRemoteIterator<S,T>
- Throws:
IOException
- If there are problems accessing the underlying data source, anIOException
will be thrown.
-
-