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.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Supplier<N>
    The creator for data provided when iterating.
    protected final Supplier<I>
    The creator for data provided initially when requesting the iterator.
    protected final Map<UUID,T>
    The map containing iterators while they are active.
    protected final String
    The name of the iterator type (for logging close problems).
    protected final Logger
    The logger for logging problems, e. g.
    The scheduler service which closes and removes all registered iterators after their alive time has elapsed from this handler.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractIteratorHandler(Supplier<I> initDataCreator, Supplier<N> dataCreator, String iteratorTypeName, String executorName, LogService logService)
    Creates a new iteration handler.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    close(@NotNull UUID iteratorId)
    Calls ServerSideProxy.close() on the designated iterator and removes it from this handler.
    protected void
    closeOrDefer(boolean close, UUID iteratorId, T iterator)
    Closes the designated iterator immediately or registers for close notification so that the iterator will be removed from iterators.
    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.
    Use closeOrDefer(boolean, UUID, ServerSideProxy) instead unless having a proxy object of which the server-side object does not have ServerSideProxy.close() yet.
    protected T
    getIterator(UUID iteratorId)
    Gets the iterator (with metadata) with the designated ID.
    void
    Shuts the executor service down and waits for the termination of running threads.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      protected final Logger logger
      The logger for logging problems, e. g. when implicitly closing after retrieving all data.
    • iteratorTypeName

      protected final String iteratorTypeName
      The name of the iterator type (for logging close problems).
    • iterators

      protected final Map<UUID,T extends de.aristaflow.adept2.model.communication.ServerSideProxy> iterators
      The 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 via removerService or being forcibly closed via running the remaining removers after shutting down the remover service.
    • removerService

      protected final LoggingScheduledThreadPoolExecutor removerService
      The scheduler service which closes and removes all registered iterators after their alive time has elapsed from this handler.
    • initDataCreator

      protected final Supplier<I> initDataCreator
      The creator for data provided initially when requesting the iterator.
    • dataCreator

      protected final Supplier<N> 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

      protected void closeOrDefer(boolean close, UUID iteratorId, T iterator)
      Closes the designated iterator immediately or registers for close notification so that the iterator will be removed from iterators.
      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.
      Use closeOrDefer(boolean, UUID, ServerSideProxy) instead unless having a proxy object of which the server-side object does not have ServerSideProxy.close() yet.
      Closes the designated iterator immediately or registers for close notification so that the iterator will be removed from iterators. In case of an UndeclaredThrowableException or a NoSuchMethodError, the designated LegacySspCloser will be called allowing to call the old method for closing instead of ServerSideProxy.close(). This is required for proxies stemming from servers before 15.0.0 where the server-side object does not implement ServerSideProxy.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 the ServerSideProxy with legacy methods instead of ServerSideProxy.close() or null to only use the standard ServerSideProxy.close().
    • getIterator

      protected T getIterator(UUID iteratorId)
      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, an IllegalArgumentException will be thrown.
    • close

      public void close(@NotNull @NotNull UUID iteratorId) throws IOException
      Calls ServerSideProxy.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 a ServerSideProxy known by this handler, an IllegalArgumentException will be thrown.
      IOException - If there are problems accessing the underlying data source, an IOException will be thrown.
      de.aristaflow.adept2.model.communication.ServiceConnectionException - If the designated server-side proxy has been closed implicitly, a ServiceConnectionException will be thrown on client side.