Class RemoteIteratorHandler<T,I extends InitialRemoteIteratorData<T>,N extends RemoteIteratorData<T>>
- java.lang.Object
-
- de.aristaflow.ilm.model.common.collection.AbstractIteratorHandler<RemoteIterator<List<T>>,I,N>
-
- de.aristaflow.ilm.model.common.collection.RemoteIteratorHandler<T,I,N>
-
- Type Parameters:
T
- The collection type of the handledRemoteIterator
s.I
- The type of the initial remote iterator data provided when requesting the remote iterator.N
- The type of the remote iterator data provided when iterating.
public class RemoteIteratorHandler<T,I extends InitialRemoteIteratorData<T>,N extends RemoteIteratorData<T>> extends AbstractIteratorHandler<RemoteIterator<List<T>>,I,N>
This class handles remote iterators by assigning IDs to them and mapping these IDs to the respective handler. This allows to use aUUID
instead of a remote iterator instance and thus simplifying interfaces not supporting Java objects, for instance web services.
All methods of this class (exceptinit(RemoteIterator, Integer)
require a UUID identifying the corresponding remote iterator. If the ID does not refer to a remote iterator, anIllegalArgumentException
will be thrown. Additionally, this handler keeps track of the alive time of known remote iterators. As soon as their alive time elapses, they will be removed from this handler.This handler tries to minimise closing effort for remote iterators. It will close them implicitly if
- all content is transferred initially,
- all content is retrieved at once (
count
isnull
), - the end of the data is reached and the iterator is forward-only, or
- the iterator contains no data at all.
null
will be returned instead ofRemoteIteratorData
if there is no content (for the current iteration). If the iterator is closed on-the-fly, aRemoteIteratorData
will be returned even if there is no content.This class is thread-safe.
-
-
Field Summary
-
Fields inherited from class de.aristaflow.ilm.model.common.collection.AbstractIteratorHandler
dataCreator, initDataCreator, iterators, iteratorTypeName, logger, removerService
-
-
Constructor Summary
Constructors Constructor Description RemoteIteratorHandler(Supplier<I> initDataCreator, Supplier<N> dataCreator, LogService logService)
Creates a new handler for remote iterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close(@NotNull UUID iteratorId)
CallsServerSideProxy.close()
on the designated iterator and removes it from this handler.N
getNext(@NotNull UUID iteratorId, @Positive Integer count, @PositiveOrZero Integer start)
CallsRemoteIterator.getNext(int)
orRemoteIterator.getNext(int, int)
on the designated iterator.protected N
getNext(UUID iteratorId, RemoteIterator<List<T>> iterator, Integer count, Integer start)
CallsRemoteIterator.getNext(int)
,RemoteIterator.getNext(int, int)
orRemoteIterator.getAll()
on the designated iterator.N
getPrevious(@NotNull UUID iteratorId, @NotNull @Positive Integer count)
CallsRemoteIterator.getPrevious(int)
on the designated iterator.I
init(@NotNull RemoteIterator<List<T>> iterator, @Positive Integer count)
Adds the designated iterator to this handler, creates an ID for it and callsgetNext(UUID, Integer, Integer)
with the designated parameters andstart
=null
.long
keepAlive(@NotNull UUID iteratorId, @NotNull Long aliveTime)
CallsRemoteIterator.keepAlive(long)
on the designated iterator.-
Methods inherited from class de.aristaflow.ilm.model.common.collection.AbstractIteratorHandler
closeOrDefer, closeOrDefer, getIterator, shutdown
-
-
-
-
Constructor Detail
-
RemoteIteratorHandler
public RemoteIteratorHandler(Supplier<I> initDataCreator, Supplier<N> dataCreator, LogService logService)
Creates a new handler for remote iterator.- Parameters:
initDataCreator
- The creator for the data provided initially when requesting the remote iterator.dataCreator
- The creator for remote iterator data provided when iterating.logService
- The log service to retrieve the logger for log messages from.
-
-
Method Detail
-
init
@Valid public I init(@NotNull @NotNull RemoteIterator<List<T>> iterator, @Positive @Positive Integer count) throws DataSourceException, DataConsistencyException
Adds the designated iterator to this handler, creates an ID for it and callsgetNext(UUID, Integer, Integer)
with the designated parameters andstart
=null
. The added iterator will be removed from this handler when its alive time elapsed. The alive time of the remote iterator will be extended in case of implicit extension. If the remote iterator is forward only, it will be closed as soon as the last entry is transferred.
Also if all entries of the iterator are retrieved now or the iterator has no entries at all, it will be closed immediately.- Parameters:
iterator
- The iterator to add to this handler.count
- The amount of elements to retrieve in forward direction. This has to be> 0
ornull
. If this isnull
, all elements of the designated iterator will be returned.- Returns:
- The initial meta data of the remote iterator and the next n elements of the designated
iterator, where n is the specified count. In case of an insufficient amount of next
elements remaining only the available elements will be returned. If there are no
elements,
null
will be returned. If nocount
orInteger.MAX_VALUE
is specified, all elements of the designated iterator will be returned at once and the iterator will be closed. - Throws:
DataSourceException
- If all elements should be retrieved (count
isnull
) but the remote iterator forward only and currently not positioned before the first element, aDataSourceException
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, aDataConsistencyException
will be thrown.IllegalArgumentException
- Ifcount
is non-positive (<= 0
), anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated iterator has been closed implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated iterator has been closed implicitly, aServiceConnectionException
will be thrown on client side.UnsupportedOperationException
- If a specific amount of elements and a start index are specified and the designated iterator is forward only, anUnsupportedOperationException
will be thrown.
-
getNext
@Valid public N getNext(@NotNull @NotNull UUID iteratorId, @Positive @Positive Integer count, @PositiveOrZero @PositiveOrZero Integer start) throws DataSourceException, DataConsistencyException
CallsRemoteIterator.getNext(int)
orRemoteIterator.getNext(int, int)
on the designated iterator. The alive time of the remote iterator will be extended in case of implicit extension. If the remote iterator is forward only, it will be closed as soon as the last entry is transferred.- Parameters:
iteratorId
- The ID of the iterator to forward the call to.count
- The amount of elements to retrieve in forward direction. This has to be> 0
ornull
. If this isnull
, all elements of the designated iterator will be returned and the iterator will be closed.start
- The index of the element from which to retrieve the next count elements when requesting a limited amount of elements (count > 0
). 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 the designated iterator. If this isnull
, the nextcount
elements will be returned.- Returns:
- Some meta data of the remote iterator and the next n elements of the designated
iterator, where n is the specified count. In case of an insufficient amount of next
elements remaining only the available elements (or no elements) will be returned. If no
count
orInteger.MAX_VALUE
is specified, all remaining elements of the designated iterator will be returned at once. If nocount
orInteger.MAX_VALUE
is specified and there are no more next elements and the forward-only iterator has been closed,null
will be returned. - Throws:
DataSourceException
- If all elements should be retrieved (count
isnull
) but the remote iterator forward only and currently not positioned before the first element, aDataSourceException
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, aDataConsistencyException
will be thrown.IllegalArgumentException
- If the designated ID does not refer to aRemoteIterator
known by this handler, anIllegalArgumentException
will be thrown.IllegalArgumentException
- Ifcount
is non-positive (<= 0
) orstart
is negative (< 0
) orstart
refers to an index that is bigger than the amount of elements of the designated iterator, anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated iterator has been closed implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated iterator has been closed implicitly, aServiceConnectionException
will be thrown on client side.UnsupportedOperationException
- If a specific amount of elements and a start index are specified and the designated iterator is forward only, anUnsupportedOperationException
will be thrown.
-
getNext
protected N getNext(UUID iteratorId, RemoteIterator<List<T>> iterator, Integer count, Integer start) throws DataSourceException, DataConsistencyException
CallsRemoteIterator.getNext(int)
,RemoteIterator.getNext(int, int)
orRemoteIterator.getAll()
on the designated iterator. The alive time of the remote iterator will be extended in case of implicit extension. If the remote iterator is forward only, it will be set to be closed as soon as the last entry is transferred. It will also be set to be closed in case all content is provided at once. The caller of this method has to close the iterator!- Parameters:
iteratorId
- The ID of the iterator to forward the call to.iterator
- The iterator to forward the call to.count
- The amount of elements to retrieve in forward direction. This has to be> 0
ornull
. If this isnull
, all elements of the designated iterator will be returned and the iterator will be closed. Thereforenull
is only allowed for the first element retrieval.start
- The index of the element from which to retrieve the next count elements when requesting a limited amount of elements (count > 0
). 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 the designated iterator. If this isnull
, the nextcount
elements will be returned.- Returns:
- Some meta data of the remote iterator and the next n elements of the designated iterator, where n is the specified count. In case of an insufficient amount of next elements remaining only the available elements (or no elements) will be returned.
- Throws:
DataSourceException
- If there are problems accessing the underlying data source or all elements should be retrieved (count
isnull
) but the remote iterator forward only and currently not positioned before the first element, aDataSourceException
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, aDataConsistencyException
will be thrown.IllegalArgumentException
- If the designated ID does not refer to aRemoteIterator
known by this handler, anIllegalArgumentException
will be thrown.IllegalArgumentException
- Ifcount
is non-positive (<= 0
) orstart
is negative (< 0
) orstart
refers to an index that is bigger than the amount of elements of the designated iterator, anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated iterator has been closed implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated iterator has been closed implicitly, aServiceConnectionException
will be thrown on client side.UnsupportedOperationException
- If a specific amount of elements and a start index are specified and the designated iterator is forward only, anUnsupportedOperationException
will be thrown.
-
getPrevious
@Valid public N getPrevious(@NotNull @NotNull UUID iteratorId, @NotNull @Positive @NotNull @Positive Integer count) throws DataSourceException, DataConsistencyException
CallsRemoteIterator.getPrevious(int)
on the designated iterator.- Parameters:
iteratorId
- The ID of the iterator to forward the call to.count
- The amount of elements to retrieve in backward direction. This has to be > 0.- Returns:
- Some meta data of the remote iterator and the previous n elements of the designated
iterator, where n is the specified count. The order corresponds to the one in the
underlying data structure, that is previous elements in the returned list are also
previous elements in the data structure. In case of an insufficient amount of previous
elements remaining only the available elements will be returned. If there are no more
previous elements,
null
will be returned as content. - Throws:
DataSourceException
- If there are problems accessing the underlying data source, aDataSourceException
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 the designated iterator is forward only, aDataConsistencyException
will be thrown.IllegalArgumentException
- If the designated ID does not refer to aRemoteIterator
known by this handler, anIllegalArgumentException
will be thrown.IllegalArgumentException
- If the designated iterator does not have any previous elements or count is non-positive (<= 0), anIllegalArgumentException
will be thrown.IllegalStateException
- If the designated iterator has been closed implicitly, anIllegalStateException
will be thrown on server side.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated iterator has been closed implicitly, aServiceConnectionException
will be thrown on client side.UnsupportedOperationException
- If the designated iterator is forward only, anUnsupportedOperationException
will be thrown.
-
keepAlive
public long keepAlive(@NotNull @NotNull UUID iteratorId, @NotNull @NotNull Long aliveTime) throws IOException
CallsRemoteIterator.keepAlive(long)
on the designated iterator.- Parameters:
iteratorId
- The ID of the iterator to forward the call to.aliveTime
- The time in milliseconds to keep the designated iterator alive that is not to close it automatically.- Returns:
- The relative time the designated 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:
IllegalArgumentException
- If the designated ID does not refer to aRemoteIterator
known by this handler, anIllegalArgumentException
will be thrown.IOException
- If there are problems accessing the underlying data source, anIOException
will be thrown.de.aristaflow.adept2.model.communication.ServiceConnectionException
- If the designated iterator has been closed implicitly, aServiceConnectionException
will be thrown on client side.
-
close
public void close(@NotNull @NotNull UUID iteratorId) throws IOException
CallsServerSideProxy.close()
on the designated iterator and removes it from this handler. This implementation handles legacy callingRemoteIterator.drop()
on proxies from old servers.- Overrides:
close
in classAbstractIteratorHandler<RemoteIterator<List<T>>,I extends InitialRemoteIteratorData<T>,N extends RemoteIteratorData<T>>
- Parameters:
iteratorId
- The ID of the iterator to close.- Throws:
IOException
- If there are problems accessing the underlying data source, anIOException
will be thrown.
-
-