Package org.ldaptive.control.util
Class SyncReplRunner
- java.lang.Object
-
- org.ldaptive.control.util.SyncReplRunner
-
public final class SyncReplRunner extends 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 the connection validator fails, 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
Fields Modifier and Type Field Description private CookieManager
cookieManager
Sync repl cookie manager.private static int
IO_WORKER_THREADS
Number of I/O worker threads.private static Logger
LOGGER
Logger for this class.private static int
MESSAGE_WORKER_THREADS
Number of message worker threads.private Consumer<LdapEntry>
onEntry
Invoked when an entry is received.private Consumer<Exception>
onException
Invoked when an exception occurs.private Consumer<SyncInfoMessage>
onMessage
Invoked when a sync info message is received.private Consumer<SearchResultReference>
onReference
Invoked when a reference is received.private Consumer<Result>
onResult
Invoked when a result is received.private Supplier<Boolean>
onStart
Invoked whenstart()
begins.private SearchRequest
searchRequest
Sync repl search request.private boolean
started
Whether the sync repl search is running.private SyncReplClient
syncReplClient
Search operation handle.
-
Constructor Summary
Constructors Constructor Description SyncReplRunner(SingleConnectionFactory cf, 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 static void
configureConnectionFactory(SingleConnectionFactory factory)
Configures the supplied factory for use with aSyncReplRunner
.static SingleConnectionFactory
createConnectionFactory(ConnectionConfig config)
Creates a new single connection factory.static SingleConnectionFactory
createConnectionFactory(ConnectionConfig config, ConnectionValidator validator)
Creates a new single connection factory.static SingleConnectionFactory
createConnectionFactory(Transport transport, ConnectionConfig config, ConnectionValidator validator)
Creates a new single connection factory.private static Transport
createTransport()
Returns a transport configured to use for sync repl.void
initialize()
Prepare this runner for use.boolean
isStarted()
Returns whether this runner is started.void
restartSearch()
Cancels the sync repl search and sends a new search request.void
setOnEntry(Consumer<LdapEntry> consumer)
Sets the onEntry consumer.void
setOnException(Consumer<Exception> consumer)
Sets the onException consumer.void
setOnMessage(Consumer<SyncInfoMessage> consumer)
Sets the onMessage consumer.void
setOnReference(Consumer<SearchResultReference> consumer)
Sets the onReference 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.String
toString()
-
-
-
Field Detail
-
LOGGER
private static final Logger LOGGER
Logger for this class.
-
IO_WORKER_THREADS
private static final int IO_WORKER_THREADS
Number of I/O worker threads.- See Also:
- Constant Field Values
-
MESSAGE_WORKER_THREADS
private static final int MESSAGE_WORKER_THREADS
Number of message worker threads.- See Also:
- Constant Field Values
-
searchRequest
private final SearchRequest searchRequest
Sync repl search request.
-
cookieManager
private final CookieManager cookieManager
Sync repl cookie manager.
-
syncReplClient
private final SyncReplClient syncReplClient
Search operation handle.
-
onReference
private Consumer<SearchResultReference> onReference
Invoked when a reference 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.
-
-
Constructor Detail
-
SyncReplRunner
public SyncReplRunner(SingleConnectionFactory cf, SearchRequest request, CookieManager manager)
Creates a new sync repl runner. The supplied connection factory is modified to invokeSyncReplClient.send(SearchRequest, CookieManager)
when the connection opens andSyncReplClient.cancel()
when the connection closes.- Parameters:
cf
- to get a connection fromrequest
- sync repl search requestmanager
- sync repl cookie manager
-
-
Method Detail
-
createConnectionFactory
public static SingleConnectionFactory createConnectionFactory(ConnectionConfig config)
Creates a new single connection factory. Uses aSearchConnectionValidator
for connection validation. SeecreateTransport()
- Parameters:
config
- sync repl connection configuration- Returns:
- single connection factory for use with a sync repl runner
-
createConnectionFactory
public static SingleConnectionFactory createConnectionFactory(ConnectionConfig config, ConnectionValidator validator)
Creates a new single connection factory. SeecreateTransport()
.- Parameters:
config
- sync repl connection configurationvalidator
- connection validator- Returns:
- single connection factory for use with a sync repl runner
-
createConnectionFactory
public static SingleConnectionFactory createConnectionFactory(Transport transport, ConnectionConfig config, ConnectionValidator validator)
Creates a new single connection factory.- Parameters:
transport
- sync repl connection transportconfig
- sync repl connection configurationvalidator
- connection validator- Returns:
- single connection factory for use with a sync repl runner
-
configureConnectionFactory
public static void configureConnectionFactory(SingleConnectionFactory factory)
Configures the supplied factory for use with aSyncReplRunner
. The factory's configuration will have the following modifications:ConnectionConfig.setAutoReconnect(boolean)
to falseConnectionConfig.setAutoReplay(boolean)
to falseConnectionConfig.setAutoRead(boolean)
to falseSingleConnectionFactory.setFailFastInitialize(boolean)
to falseSingleConnectionFactory.setNonBlockingInitialize(boolean)
to falseAbstractConnectionValidator.setOnFailure(Consumer)
toSingleConnectionFactory.ReinitializeConnectionConsumer
- Parameters:
factory
- to configure
-
createTransport
private static Transport createTransport()
Returns a transport configured to use for sync repl. UseIO_WORKER_THREADS
number of I/O threads andMESSAGE_WORKER_THREADS
number of message threads. This transport is configured never to be shutdown.- 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
-
setOnReference
public void setOnReference(Consumer<SearchResultReference> consumer)
Sets the onReference consumer.- Parameters:
consumer
- to invoke when a reference 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
-
setOnException
public void setOnException(Consumer<Exception> consumer)
Sets the onException consumer.- Parameters:
consumer
- to invoke when an exception is received
-
initialize
public void initialize()
Prepare this runner for use.
-
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.
-
-