T - The type of the elements that are retrieved from the cached
iterator.public class CachingRemoteIterator<T> extends java.lang.Object implements RemoteIterator<java.util.List<T>>
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.| Modifier and Type | Field and Description |
|---|---|
protected int |
current
The reference to the current element which is to be retrieved next.
|
protected java.util.List<T> |
elements
The elements that have been retrieved from the underlying remote iterator
so far.
|
protected int |
last
The index of last element in case it has been reached in the result set,
-1 otherwise.
|
protected int |
lastCached
The index of the last element that is in the cache.
|
protected java.lang.Boolean |
snapshot
Whether the iterator is a snapshot.
|
protected RemoteIterator<java.util.List<T>> |
wrappedIterator
The wrapped iterator of which all elements will be cached.
|
| Constructor and Description |
|---|
CachingRemoteIterator(RemoteIterator<java.util.List<T>> wrappedIterator)
Creates a new caching remote iterator for the designated iterator.
|
| Modifier and Type | Method and Description |
|---|---|
void |
drop()
Explicitly drops this iterator which allows to release occupied memory and
resources.
|
protected void |
dropWrapped()
Drops the wrapped iterator either since it is explicitly dropped or the
cache contains all items and the wrapped iterator is no longer required.
|
java.util.List<T> |
getAll()
Gets all elements of this iterator at once.
|
java.util.List<T> |
getNext(int count)
Gets the next specified amount of elements of this iterator.
|
java.util.List<T> |
getNext(int count,
int start)
Gets the next specified amount of elements of this iterator starting at the
designated index (0-based).
|
java.util.List<T> |
getPrevious(int count)
Gets the previous specified amount of elements of this iterator.
|
long |
getRemainingAliveTime()
Gets the time in milliseconds this iterator will still be valid and does
allow access to the underlying data.
|
boolean |
isForwardOnly()
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). |
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).
|
protected RemoteIterator<java.util.List<T>> wrappedIterator
null when the wrapped iterator has been
dropped.protected java.util.List<T> elements
protected int lastCached
protected int last
protected int current
protected java.lang.Boolean snapshot
null until
first retrieved from the wrapped iterator.public CachingRemoteIterator(RemoteIterator<java.util.List<T>> wrappedIterator)
wrappedIterator - The iterator of which the elements should be cached
as soon as they are iterated (with getNext(int)).public java.util.List<T> getNext(int count) throws DataSourceException, DataConsistencyException
RemoteIteratorgetNext in interface RemoteIterator<java.util.List<T>>count - The amount of elements to retrieve in forward direction. This
has to be > 0.null will be returned.DataSourceException - If there are problems accessing the underlying
data source, a DataSourceException will be thrown.DataConsistencyException - If there are problems retrieving any of
the next elements via the identifying attribute of the elements
(for instance the primary key of a specific element identifying
the next position) is not available any more, a
DataConsistencyException will be thrown.public java.util.List<T> getNext(int count, int start) throws DataSourceException, DataConsistencyException
RemoteIteratorgetNext in interface RemoteIterator<java.util.List<T>>count - The amount of elements to retrieve in forward direction. This
has to be > 0.start - The index of the element from which to retrieve the next count
elements. 0 is the index of the first element. This has to be >= 0
and it must not be bigger than the amounts of elements in this
iterator.null will be returned.DataSourceException - If there are problems accessing the underlying
data source, a DataSourceException will be thrown.DataConsistencyException - If there are problems retrieving any of
the next elements via the identifying attribute of the elements
(for instance the primary key of a specific element identifying
the next position) is not available any more, a
DataConsistencyException will be thrown.public java.util.List<T> getPrevious(int count) throws DataSourceException, DataConsistencyException
RemoteIteratorgetPrevious in interface RemoteIterator<java.util.List<T>>count - The amount of elements to retrieve in backward direction. This
has to be > 0.null will be returned.DataSourceException - If there are problems accessing the underlying
data source, a DataSourceException will be thrown.DataConsistencyException - If there are problems retrieving any of
the previous next elements via the identifying attribute of the
elements (for instance the primary key of a specific element
identifying the next position) is not available any more or if
this iterator is forward only, a
DataConsistencyException will be thrown.public java.util.List<T> getAll() throws DataSourceException, DataConsistencyException
RemoteIteratorDataSourceException since the already returned elements may
not be retrieved any more.getAll in interface RemoteIterator<java.util.List<T>>DataSourceException - If there are problems accessing the underlying
data source or this iterator is forward only and currently not positioned before the first
element, a DataSourceException will be thrown.DataConsistencyException - If there are problems retrieving any of
the elements via the identifying attribute of the elements (for
instance the primary key of a specific element identifying the
next position) is not available any more, a
DataConsistencyException will be thrown.public boolean isSnapshot()
throws DataSourceException
RemoteIteratorisSnapshot in interface RemoteIterator<java.util.List<T>>DataSourceException - If there are problems accessing the underlying
data source, a DataSourceException will be thrown.public boolean isForwardOnly()
throws DataSourceException
RemoteIteratorRemoteIterator.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.isForwardOnly in interface RemoteIterator<java.util.List<T>>DataSourceException - If there are problems accessing the underlying
data source, a DataSourceException will be thrown.public long getRemainingAliveTime()
RemoteIteratordropped automatically to save memory and resources. kept alive. Note that this alive time does not
need to correspond to the original alive time requestedgetRemainingAliveTime in interface RemoteIterator<java.util.List<T>>dropped. Long.MIN_VALUE for an already dropped remote iterator.public long keepAlive(long aliveTime)
throws DataSourceException
RemoteIterator
A 0 or a negative value is equal to dropping this iterator.
keepAlive in interface RemoteIterator<java.util.List<T>>aliveTime - The time in milliseconds to keep this iterator alive that
is not to drop it automatically.RemoteIterator.getRemainingAliveTime() in this case whether extending
the keep alive time has been successful or not.DataSourceException - If there are problems accessing the underlying
data source, a DataSourceException will be thrown.public void drop()
throws DataSourceException
RemoteIteratordrop in interface RemoteIterator<java.util.List<T>>DataSourceException - If there are problems accessing the underlying
data source, a DataSourceException will be thrown.protected void dropWrapped()
throws DataSourceException
DataSourceException - If there are problems accessing the underlying
data source, a DataSourceException will be thrown.