Package org.ldaptive.control.util
Class SyncReplRunner
- java.lang.Object
-
- org.ldaptive.control.util.SyncReplRunner
-
public class SyncReplRunner extends java.lang.Object
Class that executes aSyncReplClient
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.- Author:
- Middleware Services
-
-
Constructor Summary
Constructors Constructor Description SyncReplRunner(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
initialize(boolean refreshAndPersist, java.time.Duration reconnectWait)
Prepare this runner for use.boolean
isStarted()
Returns whether this runner is started.protected static SingleConnectionFactory
reconnectFactory(Transport transport, ConnectionConfig cc, java.time.Duration wait)
Creates a new single connection factory that will attempt to reconnect indefinitely.void
restartSearch()
Cancels the sync repl search and sends a new search request.void
setOnEntry(java.util.function.Consumer<LdapEntry> consumer)
Sets the onEntry consumer.void
setOnMessage(java.util.function.Consumer<SyncInfoMessage> consumer)
Sets the onMessage consumer.void
setOnResult(java.util.function.Consumer<Result> consumer)
Sets the onResult consumer.void
setOnStart(java.util.function.Supplier<java.lang.Boolean> supplier)
Sets the onStart supplier.void
start()
Starts this runner.void
stop()
Stops this runner.java.lang.String
toString()
-
-
-
Constructor Detail
-
SyncReplRunner
public SyncReplRunner(ConnectionConfig config, SearchRequest request, CookieManager manager)
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 Detail
-
setOnStart
public void setOnStart(java.util.function.Supplier<java.lang.Boolean> supplier)
Sets the onStart supplier.- Parameters:
supplier
- to invoke on start
-
setOnEntry
public void setOnEntry(java.util.function.Consumer<LdapEntry> consumer)
Sets the onEntry consumer.- Parameters:
consumer
- to invoke when an entry is received
-
setOnResult
public void setOnResult(java.util.function.Consumer<Result> consumer)
Sets the onResult consumer.- Parameters:
consumer
- to invoke when a result is received
-
setOnMessage
public void setOnMessage(java.util.function.Consumer<SyncInfoMessage> consumer)
Sets the onMessage consumer.- Parameters:
consumer
- to invoke when a sync info message is received
-
initialize
public void initialize(boolean refreshAndPersist, java.time.Duration reconnectWait)
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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
reconnectFactory
protected static SingleConnectionFactory reconnectFactory(Transport transport, ConnectionConfig cc, java.time.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
-
-