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 ConnectionConfig
Connection configuration.private final Transport
Connection transport.private final CookieManager
Sync repl cookie manager.private AtomicBoolean
Prevent multiple invocations of onException.private static final int
Number of I/O worker threads.private static final org.slf4j.Logger
Logger for this class.private static final int
Number 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 SearchRequest
Sync repl search request.private boolean
Whether the sync repl search is running.private SyncReplClient
Search 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 Transport
Returns a transport configured to use for sync repl.void
initialize
(boolean refreshAndPersist, Duration reconnectWait) Prepare this runner for use.boolean
Returns whether this runner is started.protected static SingleConnectionFactory
reconnectFactory
(Transport transport, ConnectionConfig cc, Duration wait) Creates a new single connection factory that will attempt to reconnect indefinitely.void
Cancels the sync repl search and sends a new search request.void
setOnEntry
(Consumer<LdapEntry> consumer) Sets the onEntry consumer.void
setOnMessage
(Consumer<SyncInfoMessage> consumer) Sets the onMessage consumer.void
setOnResult
(Consumer<Result> consumer) Sets the onResult consumer.void
setOnStart
(Supplier<Boolean> supplier) Sets the onStart supplier.void
start()
Starts this runner.void
stop()
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 customConnectionFactoryTransport
for 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
-