Class SyncReplRunner

java.lang.Object
org.ldaptive.control.util.SyncReplRunner

public class SyncReplRunner extends Object
Class that executes a SyncReplClient and expects to run continuously, reconnecting if the server is unavailable. Consumers must be registered to handle entries, results, and messages as they are returned from the server. If a consumer throws an exception, the runner will be stopped and started, then the sync repl search will execute again. Consumers cannot execute blocking LDAP operations on the same connection because the next incoming message is not read until the consumer has completed.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
      Logger for this class.
    • IO_WORKER_THREADS

      private static final int IO_WORKER_THREADS
      Number of I/O worker threads.
      See Also:
    • MESSAGE_WORKER_THREADS

      private static final int MESSAGE_WORKER_THREADS
      Number of message worker threads.
      See Also:
    • connectionTransport

      private final Transport connectionTransport
      Connection transport.
    • connectionConfig

      private final ConnectionConfig connectionConfig
      Connection configuration.
    • searchRequest

      private final SearchRequest searchRequest
      Sync repl search request.
    • cookieManager

      private final CookieManager cookieManager
      Sync repl cookie manager.
    • onException

      private final Consumer<Exception> onException
      Invoked when an exception is received.
    • syncReplClient

      private SyncReplClient syncReplClient
      Search operation handle.
    • onStart

      private Supplier<Boolean> onStart
      Invoked when start() begins.
    • onEntry

      private Consumer<LdapEntry> onEntry
      Invoked when an entry is received.
    • onResult

      private Consumer<Result> onResult
      Invoked when a result is received.
    • onMessage

      private Consumer<SyncInfoMessage> onMessage
      Invoked when a sync info message is received.
    • started

      private boolean started
      Whether the sync repl search is running.
    • handlingException

      private AtomicBoolean handlingException
      Prevent multiple invocations of onException.
  • Constructor Details

    • SyncReplRunner

      public SyncReplRunner(ConnectionConfig config, SearchRequest request, CookieManager manager)
      Creates a new sync repl runner. Uses a custom ConnectionFactoryTransport for processing I/O and messages.
      Parameters:
      config - sync repl connection configuration
      request - sync repl search request
      manager - sync repl cookie manager
    • SyncReplRunner

      public SyncReplRunner(Transport transport, ConnectionConfig config, SearchRequest request, CookieManager manager)
      Creates a new sync repl runner.
      Parameters:
      transport - sync repl connection transport
      config - sync repl connection configuration
      request - sync repl search request
      manager - sync repl cookie manager
  • Method Details

    • createTransport

      private static Transport createTransport()
      Returns a transport configured to use for sync repl. Uses it's own event loop groups with auto_read set to false. Detects whether Epoll or KQueue transports are available, otherwise uses NIO.
      Returns:
      transport
    • setOnStart

      public void setOnStart(Supplier<Boolean> supplier)
      Sets the onStart supplier.
      Parameters:
      supplier - to invoke on start
    • setOnEntry

      public void setOnEntry(Consumer<LdapEntry> consumer)
      Sets the onEntry consumer.
      Parameters:
      consumer - to invoke when an entry is received
    • setOnResult

      public void setOnResult(Consumer<Result> consumer)
      Sets the onResult consumer.
      Parameters:
      consumer - to invoke when a result is received
    • setOnMessage

      public void setOnMessage(Consumer<SyncInfoMessage> consumer)
      Sets the onMessage consumer.
      Parameters:
      consumer - to invoke when a sync info message is received
    • initialize

      public void initialize(boolean refreshAndPersist, Duration reconnectWait)
      Prepare this runner for use.
      Parameters:
      refreshAndPersist - whether to refresh and persist or just refresh
      reconnectWait - time to wait between open attempts
    • start

      public void start()
      Starts this runner.
    • stop

      public void stop()
      Stops this runner.
    • isStarted

      public boolean isStarted()
      Returns whether this runner is started.
      Returns:
      whether this runner is started
    • restartSearch

      public void restartSearch()
      Cancels the sync repl search and sends a new search request.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • reconnectFactory

      protected static SingleConnectionFactory reconnectFactory(Transport transport, ConnectionConfig cc, Duration wait)
      Creates a new single connection factory that will attempt to reconnect indefinitely. This method creates a copy of the supplied config makes the following modifications:
      Parameters:
      transport - connection transport
      cc - connection configuration
      wait - length of time to wait between consecutive calls to open
      Returns:
      single connection factory