Package de.aristaflow.ilm.model.common
Class AbstractIteratorHandler<T extends de.aristaflow.adept2.model.communication.ServerSideProxy,I,N>
java.lang.Object
de.aristaflow.ilm.model.common.AbstractIteratorHandler<T,I,N>
- Type Parameters:
T- The type of the handled iterators.I- The type of the initial data provided when requesting the iterator.N- The type of the data when iterating.
- Direct Known Subclasses:
IncWorklistHandler,IncWorklistUpdateHandler,RemoteIteratorHandler,ServerStreamStringHandler
public class AbstractIteratorHandler<T extends de.aristaflow.adept2.model.communication.ServerSideProxy,I,N>
extends Object
This class handles provides the basic means for handling iterators. This includes the data
structure containing the iterators, runnables for removing iterators from the data structure and
closing them as well as the corresponding scheduled executor service.
Iterators and their handling classes are generic classes whereas the generic type specifies the
elements of the iterator. However, Java's type system may become a problem for other languages.
Therefore the ILM removes the generic type and makes it explicit. At runtime this handler needs
to create and provide the concrete types without generics, so instantiation is delegated to
suppliers provided when instantiating this handler.
Due to the API of iterators being rather specific, this class is a mere sketch and a lot of logic has to happen in subclasses.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe creator for data provided when iterating.The creator for data provided initially when requesting the iterator.The map containing iterators while they are active.protected final StringThe name of the iterator type (for logging close problems).protected final LoggerThe logger for logging problems, e. g.protected final LoggingScheduledThreadPoolExecutorThe scheduler service which closes and removes all registered iterators after their alive time has elapsed from this handler. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractIteratorHandler(Supplier<I> initDataCreator, Supplier<N> dataCreator, String iteratorTypeName, String executorName, LogService logService) Creates a new iteration handler. -
Method Summary
Modifier and TypeMethodDescriptionvoidCallsServerSideProxy.close()on the designated iterator and removes it from this handler.protected voidcloseOrDefer(boolean close, UUID iteratorId, T iterator) Closes the designated iterator immediately or registers for close notification so that the iterator will be removed fromiterators.protected voidcloseOrDefer(boolean close, UUID iteratorId, T iterator, de.aristaflow.adept2.model.communication.ServerSideProxy.LegacySspCloser legacyCloser) Deprecated, for removal: This API element is subject to removal in a future version.protected TgetIterator(UUID iteratorId) Gets the iterator (with metadata) with the designated ID.voidshutdown()Shuts the executor service down and waits for the termination of running threads.
-
Field Details
-
logger
The logger for logging problems, e. g. when implicitly closing after retrieving all data. -
iteratorTypeName
The name of the iterator type (for logging close problems). -
iterators
protected final Map<UUID,T extends de.aristaflow.adept2.model.communication.ServerSideProxy> iteratorsThe map containing iterators while they are active. The key is a random UUID identifying the iterator.
The server-side proxies will either be explicitly closed, time out viaremoverServiceor being forcibly closed via running the remaining removers after shutting down the remover service. -
removerService
The scheduler service which closes and removes all registered iterators after their alive time has elapsed from this handler. -
initDataCreator
The creator for data provided initially when requesting the iterator. -
dataCreator
The creator for data provided when iterating.
-
-
Constructor Details
-
AbstractIteratorHandler
public AbstractIteratorHandler(Supplier<I> initDataCreator, Supplier<N> dataCreator, String iteratorTypeName, String executorName, LogService logService) Creates a new iteration handler.- Parameters:
initDataCreator- The creator for data provided initially when requesting the iterator.dataCreator- The creator for data provided when iterating.iteratorTypeName- The name of the iterator type (for logging close problems).executorName- The name for the executor.logService- The log service to retrieve the logger for log messages from.
-
-
Method Details
-
shutdown
public void shutdown()Shuts the executor service down and waits for the termination of running threads. -
closeOrDefer
Closes the designated iterator immediately or registers for close notification so that the iterator will be removed fromiterators.- Parameters:
close- Whether to close the designated iterator immediately.iteratorId- The ID of the designated iterator for logging purpose.iterator- The iterator which to close or which to remove later.
-
closeOrDefer
@Deprecated(since="15.0.0", forRemoval=true) protected void closeOrDefer(boolean close, UUID iteratorId, T iterator, de.aristaflow.adept2.model.communication.ServerSideProxy.LegacySspCloser legacyCloser) Deprecated, for removal: This API element is subject to removal in a future version.UsecloseOrDefer(boolean, UUID, ServerSideProxy)instead unless having a proxy object of which the server-side object does not haveServerSideProxy.close()yet.Closes the designated iterator immediately or registers for close notification so that the iterator will be removed fromiterators. In case of anUndeclaredThrowableExceptionor aNoSuchMethodError, the designatedLegacySspCloserwill be called allowing to call the old method for closing instead ofServerSideProxy.close(). This is required for proxies stemming from servers before 15.0.0 where the server-side object does not implementServerSideProxy.close().- Parameters:
close- Whether to close the designated iterator immediately.iteratorId- The ID of the designated iterator for logging purpose.iterator- The iterator which to close or which to remove later.legacyCloser- The methods for closing theServerSideProxywith legacy methods instead ofServerSideProxy.close()ornullto only use the standardServerSideProxy.close().
-
getIterator
Gets the iterator (with metadata) with the designated ID.- Parameters:
iteratorId- The ID of the iterator with metadata to retrieve.- Returns:
- The iterator (with metadata) with the designated ID.
- Throws:
IllegalArgumentException- If the designated ID does not refer to an iterator known by this handler, anIllegalArgumentExceptionwill be thrown.
-
close
CallsServerSideProxy.close()on the designated iterator and removes it from this handler.- Parameters:
iteratorId- The ID of the iterator to close.- Throws:
IllegalArgumentException- If the designated ID does not refer to aServerSideProxyknown by this handler, anIllegalArgumentExceptionwill be thrown.IOException- If there are problems accessing the underlying data source, anIOExceptionwill be thrown.de.aristaflow.adept2.model.communication.ServiceConnectionException- If the designated server-side proxy has been closed implicitly, aServiceConnectionExceptionwill be thrown on client side.
-
closeOrDefer(boolean, UUID, ServerSideProxy)instead unless having a proxy object of which the server-side object does not haveServerSideProxy.close()yet.