Package org.ldaptive.control.util
Class SyncReplRunner
java.lang.Object
org.ldaptive.control.util.SyncReplRunner
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final ConnectionConfigConnection configuration.private final TransportConnection transport.private final CookieManagerSync repl cookie manager.private AtomicBooleanPrevent multiple invocations of onException.private static final intNumber of I/O worker threads.private static final org.slf4j.LoggerLogger for this class.private static final intNumber of message worker threads.Invoked when an entry is received.Invoked when an exception is received.private Consumer<SyncInfoMessage>Invoked when a sync info message is received.Invoked when a result is received.Invoked whenstart()begins.private final SearchRequestSync repl search request.private booleanWhether the sync repl search is running.private SyncReplClientSearch operation handle. -
Constructor Summary
ConstructorsConstructorDescriptionSyncReplRunner(ConnectionConfig config, SearchRequest request, CookieManager manager) Creates a new sync repl runner.SyncReplRunner(Transport transport, ConnectionConfig config, SearchRequest request, CookieManager manager) Creates a new sync repl runner. -
Method Summary
Modifier and TypeMethodDescriptionprivate static TransportReturns a transport configured to use for sync repl.voidinitialize(boolean refreshAndPersist, Duration reconnectWait) Prepare this runner for use.booleanReturns whether this runner is started.protected static SingleConnectionFactoryreconnectFactory(Transport transport, ConnectionConfig cc, Duration wait) Creates a new single connection factory that will attempt to reconnect indefinitely.voidCancels the sync repl search and sends a new search request.voidsetOnEntry(Consumer<LdapEntry> consumer) Sets the onEntry consumer.voidsetOnMessage(Consumer<SyncInfoMessage> consumer) Sets the onMessage consumer.voidsetOnResult(Consumer<Result> consumer) Sets the onResult consumer.voidsetOnStart(Supplier<Boolean> supplier) Sets the onStart supplier.voidstart()Starts this runner.voidstop()Stops this runner.toString()
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGERLogger for this class. -
IO_WORKER_THREADS
private static final int IO_WORKER_THREADSNumber of I/O worker threads.- See Also:
-
MESSAGE_WORKER_THREADS
private static final int MESSAGE_WORKER_THREADSNumber of message worker threads.- See Also:
-
connectionTransport
Connection transport. -
connectionConfig
Connection configuration. -
searchRequest
Sync repl search request. -
cookieManager
Sync repl cookie manager. -
onException
Invoked when an exception is received. -
syncReplClient
Search operation handle. -
onStart
Invoked whenstart()begins. -
onEntry
Invoked when an entry is received. -
onResult
Invoked when a result is received. -
onMessage
Invoked when a sync info message is received. -
started
private boolean startedWhether the sync repl search is running. -
handlingException
Prevent multiple invocations of onException.
-
-
Constructor Details
-
SyncReplRunner
Creates a new sync repl runner. Uses a customConnectionFactoryTransportfor processing I/O and messages.- Parameters:
config- sync repl connection configurationrequest- sync repl search requestmanager- 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 transportconfig- sync repl connection configurationrequest- sync repl search requestmanager- sync repl cookie manager
-
-
Method Details
-
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
Sets the onStart supplier.- Parameters:
supplier- to invoke on start
-
setOnEntry
Sets the onEntry consumer.- Parameters:
consumer- to invoke when an entry is received
-
setOnResult
Sets the onResult consumer.- Parameters:
consumer- to invoke when a result is received
-
setOnMessage
Sets the onMessage consumer.- Parameters:
consumer- to invoke when a sync info message is received
-
initialize
Prepare this runner for use.- Parameters:
refreshAndPersist- whether to refresh and persist or just refreshreconnectWait- 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
-
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:ConnectionConfig.setAutoReconnect(boolean)to trueConnectionConfig.setAutoReconnectCondition(Predicate)to sleep and return true for InitialRetryMetadataConnectionConfig.setAutoReplay(boolean)to false
- Parameters:
transport- connection transportcc- connection configurationwait- length of time to wait between consecutive calls to open- Returns:
- single connection factory
-