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 ConnectionFactory
factory
Connection factory to get a connection from.private SearchOperationHandle
handle
Search operation handle.private static int
IO_WORKER_THREADS
Number of I/O worker threads.protected 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 is received.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 boolean
receivedResult
Whether the sync repl search has received a result response.private boolean
refreshAndPersist
Controls which mode the sync repl control should use.private boolean
reloadHint
Controls 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 ExtendedOperationHandle
cancel()
Sends a cancel operation on the underlying search operation.void
close()
Closes the connection factory.static void
configureConnectionFactory(SingleConnectionFactory factory)
Configures the supplied factory for use with aSyncReplClient
.static SingleConnectionFactory
createConnectionFactory(ConnectionConfig config)
Creates a new single connection factory.private static Transport
createTransport()
Returns a transport configured to use for sync repl.ConnectionFactory
getConnectionFactory()
Returns the connection factory.boolean
isComplete()
Returns whether a search result has been received by this client.SearchOperationHandle
send(SearchRequest request)
Invokessend(SearchRequest, CookieManager)
with aDefaultCookieManager
.SearchOperationHandle
send(SearchRequest request, CookieManager manager)
Performs an async search operation with theSyncRequestControl
.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.String
toString()
-
-
-
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_THREADS
number of I/O threads andMESSAGE_WORKER_THREADS
number 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.
-
-