Package org.ldaptive.control.util
Class SyncReplClient
- java.lang.Object
-
- org.ldaptive.control.util.SyncReplClient
-
public class SyncReplClient extends Object
Client that simplifies using the sync repl control.
-
-
Field Summary
Fields Modifier and Type Field Description private ConnectionFactoryfactoryConnection factory to get a connection from.private SearchOperationHandlehandleSearch operation handle.private static intIO_WORKER_THREADSNumber of I/O worker threads.protected 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 is received.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 booleanreceivedResultWhether the sync repl search has received a result response.private booleanrefreshAndPersistControls which mode the sync repl control should use.private booleanreloadHintControls the sync repl request reload hint.
-
Constructor Summary
Constructors Constructor Description SyncReplClient(ConnectionFactory cf, boolean persist)Creates a new sync repl client.SyncReplClient(ConnectionFactory cf, boolean persist, boolean hint)Creates a new sync repl client.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private RequestControl[]appendRequestControls(SearchRequest request, CookieManager manager)Creates a new array of request controls which includes the sync request control.ExtendedOperationHandlecancel()Sends a cancel operation on the underlying search operation.voidclose()Closes the connection factory.static voidconfigureConnectionFactory(SingleConnectionFactory factory)Configures the supplied factory for use with aSyncReplClient.static SingleConnectionFactorycreateConnectionFactory(ConnectionConfig config)Creates a new single connection factory.private static TransportcreateTransport()Returns a transport configured to use for sync repl.ConnectionFactorygetConnectionFactory()Returns the connection factory.booleanisComplete()Returns whether a search result has been received by this client.SearchOperationHandlesend(SearchRequest request)Invokessend(SearchRequest, CookieManager)with aDefaultCookieManager.SearchOperationHandlesend(SearchRequest request, CookieManager manager)Performs an async search operation with theSyncRequestControl.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.StringtoString()
-
-
-
Field Detail
-
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
-
logger
protected final Logger logger
Logger for this class.
-
factory
private final ConnectionFactory factory
Connection factory to get a connection from.
-
refreshAndPersist
private final boolean refreshAndPersist
Controls which mode the sync repl control should use.
-
reloadHint
private final boolean reloadHint
Controls the sync repl request reload hint.
-
handle
private SearchOperationHandle handle
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.
-
receivedResult
private boolean receivedResult
Whether the sync repl search has received a result response.
-
-
Constructor Detail
-
SyncReplClient
public SyncReplClient(ConnectionFactory cf, boolean persist)
Creates a new sync repl client.- Parameters:
cf- to get a connection frompersist- whether to refresh and persist or just refresh
-
SyncReplClient
public SyncReplClient(ConnectionFactory cf, boolean persist, boolean hint)
Creates a new sync repl client.- Parameters:
cf- to get a connection frompersist- whether to refresh and persist or just refreshhint- sync repl request reload hint
-
-
Method Detail
-
createConnectionFactory
public static SingleConnectionFactory createConnectionFactory(ConnectionConfig config)
Creates a new single connection factory. SeecreateTransport().- Parameters:
config- sync repl connection configuration- Returns:
- single connection factory for use with a sync repl client
-
configureConnectionFactory
public static void configureConnectionFactory(SingleConnectionFactory factory)
Configures the supplied factory for use with aSyncReplClient. The factory's configuration will have the following modifications:- 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 to be shutdown when the connection factory closes.- Returns:
- transport
-
getConnectionFactory
public ConnectionFactory getConnectionFactory()
Returns the connection factory.- Returns:
- connection factory
-
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 a sync info message is received
-
send
public SearchOperationHandle send(SearchRequest request) throws LdapException
Invokessend(SearchRequest, CookieManager)with aDefaultCookieManager.- Parameters:
request- search request to execute- Returns:
- search operation handle
- Throws:
LdapException- if the search fails
-
send
public SearchOperationHandle send(SearchRequest request, CookieManager manager) throws LdapException
Performs an async search operation with theSyncRequestControl. The supplied request is modified in the following way:AbstractRequestMessage.setControls( org.ldaptive.control.RequestControl...)is invoked withSyncRequestControl
The search request object should not be reused for any other search operations.
- Parameters:
request- search request to executemanager- for reading and writing cookies- Returns:
- search operation handle
- Throws:
LdapException- if the search fails
-
isComplete
public boolean isComplete()
Returns whether a search result has been received by this client.- Returns:
- whether a search result has been received
-
cancel
public ExtendedOperationHandle cancel()
Sends a cancel operation on the underlying search operation. SeeDefaultOperationHandle.cancel().- Returns:
- cancel operation result
-
close
public void close()
Closes the connection factory.
-
appendRequestControls
private RequestControl[] appendRequestControls(SearchRequest request, CookieManager manager)
Creates a new array of request controls which includes the sync request control. Any other request controls are included.- Parameters:
request- to read controls frommanager- to read the cookie from- Returns:
- array of request controls ready to be used in a search operation
-
-