Package org.ldaptive.control.util
Class SyncReplRunner
- java.lang.Object
-
- org.ldaptive.control.util.SyncReplRunner
-
public final class SyncReplRunner extends Object
Class that executes aSyncReplClientand 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 CookieManagercookieManagerSync repl cookie manager.private static intIO_WORKER_THREADSNumber of I/O worker threads.private static LoggerLOGGERLogger for this class.private static intMESSAGE_WORKER_THREADSNumber of message worker threads.private Consumer<LdapEntry>onEntryInvoked when an entry is received.private Consumer<Exception>onExceptionInvoked when an exception occurs.private Consumer<SyncInfoMessage>onMessageInvoked when a sync info message is received.private Consumer<SearchResultReference>onReferenceInvoked when a reference is received.private Consumer<Result>onResultInvoked when a result is received.private Supplier<Boolean>onStartInvoked whenstart()begins.private SearchRequestsearchRequestSync repl search request.private booleanstartedWhether the sync repl search is running.private SyncReplClientsyncReplClientSearch 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 voidconfigureConnectionFactory(SingleConnectionFactory factory)Configures the supplied factory for use with aSyncReplRunner.static SingleConnectionFactorycreateConnectionFactory(ConnectionConfig config)Creates a new single connection factory.static SingleConnectionFactorycreateConnectionFactory(ConnectionConfig config, ConnectionValidator validator)Creates a new single connection factory.static SingleConnectionFactorycreateConnectionFactory(Transport transport, ConnectionConfig config, ConnectionValidator validator)Creates a new single connection factory.private static TransportcreateTransport()Returns a transport configured to use for sync repl.voidinitialize()Prepare this runner for use.booleanisStarted()Returns whether this runner is started.voidrestartSearch()Cancels the sync repl search and sends a new search request.voidsetOnEntry(Consumer<LdapEntry> consumer)Sets the onEntry consumer.voidsetOnException(Consumer<Exception> consumer)Sets the onException consumer.voidsetOnMessage(Consumer<SyncInfoMessage> consumer)Sets the onMessage consumer.voidsetOnReference(Consumer<SearchResultReference> consumer)Sets the onReference 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.StringtoString()
-
-
-
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 aSearchConnectionValidatorfor 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_THREADSnumber of I/O threads andMESSAGE_WORKER_THREADSnumber 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.
-
-