Interface Connection
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Implementing Classes:
AbstractAsynchronousConnection
,AbstractConnection
,AbstractConnectionWrapper
,AbstractSynchronousConnection
Operation processing
Operations may be performed synchronously or asynchronously depending on the
method chosen. Asynchronous methods can be identified by their Async
suffix.
Performing operations synchronously
Synchronous methods block until a response is received from the Directory
Server, at which point an appropriate Result
object is returned if
the operation succeeded, or thrown as an LdapException
if the
operation failed.
Since synchronous operations block the calling thread, the only way to
abandon a long running operation is to interrupt the calling thread from
another thread. This will cause the calling thread unblock and throw a
CancelledResultException
whose cause is the underlying
InterruptedException
.
Performing operations asynchronously
Asynchronous methods, identified by their Async
suffix, are
non-blocking, returning a LdapPromise
or sub-type thereof which can
be used for retrieving the result using the Promise.get()
method.
Operation failures, for whatever reason, are signaled by the
Promise.get()
method throwing an LdapException
.
In addition to returning a LdapPromise
, all asynchronous methods
accept a LdapResultHandler
which will be notified upon completion of the
operation.
Synchronous operations are easily simulated by immediately getting the result:
Connection connection = ...; AddRequest request = ...; // Will block until operation completes, and // throws exception on failure. connection.add(request).get();Operations can be performed in parallel while taking advantage of the simplicity of a synchronous application design:
Connection connection1 = ...; Connection connection2 = ...; AddRequest request = ...; // Add the entry to the first server (don't block). LdapPromise promise1 = connection1.add(request); // Add the entry to the second server (in parallel). LdapPromise promise2 = connection2.add(request); // Total time = is O(1) instead of O(n). promise1.get(); promise2.get();More complex client applications can take advantage of a fully asynchronous event driven design using
LdapResultHandler
s:
Connection connection = ...; SearchRequest request = ...; // Process results in the search result handler // in a separate thread. SearchResponseHandler handle = ...; connection.search(request, handler);
Closing connections
Applications must ensure that a connection is closed by calling
close()
even if a fatal error occurs on the connection. Once a
connection has been closed by the client application, any attempts to
continue to use the connection will result in an
IllegalStateException
being thrown. Note that, if a fatal error is
encountered on the connection, then the application can continue to use the
connection. In this case all requests subsequent to the failure will fail
with an appropriate LdapException
when their result is
retrieved.
Event notification
Applications can choose to be notified when a connection is closed by the
application, receives an unsolicited notification, or experiences a fatal
error by registering a ConnectionEventListener
with the connection
using the addConnectionEventListener(org.forgerock.opendj.ldap.ConnectionEventListener)
method.
-
Method Summary
Modifier and TypeMethodDescriptionabandonAsync
(AbandonRequest request) Abandons the unfinished operation identified in the provided abandon request.Adds an entry to the Directory Server using the provided lines of LDIF.Adds the provided entry to the Directory Server.add
(AddRequest request) Adds an entry to the Directory Server using the provided add request.addAsync
(AddRequest request) Asynchronously adds an entry to the Directory Server using the provided add request.addAsync
(AddRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously adds an entry to the Directory Server using the provided add request.void
Registers the provided connection event listener so that it will be notified when this connection is closed by the application, receives an unsolicited notification, or experiences a fatal error.applyChange
(ChangeRecord request) Applies the provided change request to the Directory Server.applyChangeAsync
(ChangeRecord request) Asynchronously applies the provided change request to the Directory Server.applyChangeAsync
(ChangeRecord request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously applies the provided change request to the Directory Server.Authenticates to the Directory Server using simple authentication and the provided user name and password.bind
(BindRequest request) Authenticates to the Directory Server using the provided bind request.bindAsync
(BindRequest request) Asynchronously authenticates to the Directory Server using the provided bind request.bindAsync
(BindRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously authenticates to the Directory Server using the provided bind request.void
close()
Releases any resources associated with this connection.void
close
(UnbindRequest request, String reason) Releases any resources associated with this connection.Compares the named entry in the Directory Server against the provided attribute value assertion.compare
(CompareRequest request) Compares an entry in the Directory Server using the provided compare request.compareAsync
(CompareRequest request) Asynchronously compares an entry in the Directory Server using the provided compare request.compareAsync
(CompareRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously compares an entry in the Directory Server using the provided compare request.Deletes the named entry from the Directory Server.default Result
Deletes the named entry from the Directory Server.delete
(DeleteRequest request) Deletes an entry from the Directory Server using the provided delete request.deleteAsync
(DeleteRequest request) Asynchronously deletes an entry from the Directory Server using the provided delete request.deleteAsync
(DeleteRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously deletes an entry from the Directory Server using the provided delete request.deleteSubtree
(String name) Deletes the named entry and all of its subordinates from the Directory Server.extendedRequest
(String requestName, ByteString requestValue) Requests that the Directory Server performs the provided extended request.<R extends ExtendedResult>
RextendedRequest
(ExtendedRequest<R> request) Requests that the Directory Server performs the provided extended request.<R extends ExtendedResult>
RextendedRequest
(ExtendedRequest<R> request, IntermediateResponseHandler handler) Requests that the Directory Server performs the provided extended request, optionally listening for any intermediate responses.<R extends ExtendedResult>
LdapPromise<R>extendedRequestAsync
(ExtendedRequest<R> request) Asynchronously performs the provided extended request in the Directory Server.<R extends ExtendedResult>
LdapPromise<R>extendedRequestAsync
(ExtendedRequest<R> request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously performs the provided extended request in the Directory Server.boolean
isClosed()
Indicates whether this connection has been explicitly closed by callingclose
.boolean
isValid()
Returnstrue
if this connection has not been closed and no fatal errors have been detected.Modifies an entry in the Directory Server using the provided lines of LDIF.modify
(ModifyRequest request) Modifies an entry in the Directory Server using the provided modify request.modifyAsync
(ModifyRequest request) Asynchronously modifies an entry in the Directory Server using the provided modify request.modifyAsync
(ModifyRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously modifies an entry in the Directory Server using the provided modify request.Renames the named entry in the Directory Server using the provided new RDN.modifyDn
(ModifyDnRequest request) Renames an entry in the Directory Server using the provided modify DN request.modifyDnAsync
(ModifyDnRequest request) Asynchronously renames an entry in the Directory Server using the provided modify DN request.modifyDnAsync
(ModifyDnRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously renames an entry in the Directory Server using the provided modify DN request.Reads the named entry from the Directory Server.Reads the named entry from the Directory Server.readEntryAsync
(Dn name, Collection<String> attributeDescriptions) Asynchronously reads the named entry from the Directory Server.void
Removes the provided connection event listener from this connection so that it will no longer be notified when this connection is closed by the application, receives an unsolicited notification, or experiences a fatal error.search
(String baseObject, SearchScope scope, String filter, String... attributeDescriptions) Searches the Directory Server using the provided search parameters.search
(SearchRequest request) Searches the Directory Server using the provided search parameters.search
(SearchRequest request, Collection<? super SearchResultEntry> entries) Searches the Directory Server using the provided search request.search
(SearchRequest request, Collection<? super SearchResultEntry> entries, Collection<? super SearchResultReference> references) Searches the Directory Server using the provided search request.search
(SearchRequest request, SearchResultHandler handler) Searches the Directory Server using the provided search request.searchAsync
(SearchRequest request, IntermediateResponseHandler intermediateResponseHandler, SearchResultHandler entryHandler) Asynchronously searches the Directory Server using the provided search request.searchAsync
(SearchRequest request, SearchResultHandler entryHandler) Asynchronously searches the Directory Server using the provided search request.searchSingleEntry
(String baseObject, SearchScope scope, String filter, String... attributeDescriptions) Searches the Directory Server for a single entry using the provided search parameters.searchSingleEntry
(SearchRequest request) Searches the Directory Server for a single entry using the provided search request.searchSingleEntryAsync
(SearchRequest request) Asynchronously searches the Directory Server for a single entry using the provided search request.
-
Method Details
-
abandonAsync
Abandons the unfinished operation identified in the provided abandon request.Abandon requests do not have a response, so invoking the method get() on the returned promise will not block, nor return anything (it is Void), but may throw an exception if a problem occurred while sending the abandon request. In addition the returned promise may be used in order to determine the message ID of the abandon request.
Note: a more convenient approach to abandoning unfinished asynchronous operations is provided via the
Promise.cancel(boolean)
method.- Parameters:
request
- The request identifying the operation to be abandoned.- Returns:
- A promise whose result is Void.
- Throws:
UnsupportedOperationException
- If this connection does not support abandon operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
add
Adds an entry to the Directory Server using the provided add request.- Parameters:
request
- The add request.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support add operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
add
Adds the provided entry to the Directory Server.This method is equivalent to the following code:
AddRequest request = new AddRequest(entry); connection.add(request);
- Parameters:
entry
- The entry to be added.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support add operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifentry
wasnull
.
-
add
Adds an entry to the Directory Server using the provided lines of LDIF.This method is equivalent to the following code:
AddRequest request = new AddRequest(ldifLines); connection.add(request);
- Parameters:
ldifLines
- Lines of LDIF containing the an LDIF add change record or an LDIF entry record.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support add operations.LocalizedIllegalArgumentException
- IfldifLines
was empty, or contained invalid LDIF, or could not be decoded using the default schema.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- IfldifLines
wasnull
.
-
addAsync
Asynchronously adds an entry to the Directory Server using the provided add request.- Parameters:
request
- The add request.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support add operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
addAsync
LdapPromise<Result> addAsync(AddRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously adds an entry to the Directory Server using the provided add request.- Parameters:
request
- The add request.intermediateResponseHandler
- An intermediate response handler which can be used to process any intermediate responses as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support add operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
addConnectionEventListener
Registers the provided connection event listener so that it will be notified when this connection is closed by the application, receives an unsolicited notification, or experiences a fatal error.- Parameters:
listener
- The listener which wants to be notified when events occur on this connection.- Throws:
IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- If thelistener
wasnull
.
-
applyChange
Applies the provided change request to the Directory Server.- Parameters:
request
- The change request.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support the provided change request.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
applyChangeAsync
Asynchronously applies the provided change request to the Directory Server.- Parameters:
request
- The change request.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support the provided change request.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
applyChangeAsync
LdapPromise<Result> applyChangeAsync(ChangeRecord request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously applies the provided change request to the Directory Server.- Parameters:
request
- The change request.intermediateResponseHandler
- An intermediate response handler which can be used to process any intermediate responses as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support the provided change request.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
bind
Authenticates to the Directory Server using the provided bind request.- Parameters:
request
- The bind request.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support bind operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
bind
Authenticates to the Directory Server using simple authentication and the provided user name and password.This method is equivalent to the following code:
BindRequest request = new SimpleBindRequest(name, password); connection.bind(request);
- Parameters:
name
- The distinguished name of the Directory object that the client wishes to bind as, which may be empty.password
- The password of the Directory object that the client wishes to bind as, which may be empty.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.LocalizedIllegalArgumentException
- Ifname
could not be decoded using the default schema.UnsupportedOperationException
- If this connection does not support bind operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifname
orpassword
wasnull
.
-
bindAsync
Asynchronously authenticates to the Directory Server using the provided bind request.- Parameters:
request
- The bind request.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support bind operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
bindAsync
LdapPromise<BindResult> bindAsync(BindRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously authenticates to the Directory Server using the provided bind request.- Parameters:
request
- The bind request.intermediateResponseHandler
- An intermediate response handler which can be used to process any intermediate responses as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support bind operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
close
void close()Releases any resources associated with this connection. For physical connections to a Directory Server this will mean that an unbind request is sent and the underlying socket is closed.Other connection implementations may behave differently, and may choose not to send an unbind request if its use is inappropriate (for example a pooled connection will be released and returned to its connection pool without ever issuing an unbind request).
This method is equivalent to the following code:
UnbindRequest request = new UnbindRequest(); connection.close(request);
Callingclose
on a connection that is already closed has no effect.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- See Also:
-
close
Releases any resources associated with this connection. For physical connections to a Directory Server this will mean that the provided unbind request is sent and the underlying socket is closed.Other connection implementations may behave differently, and may choose to ignore the provided unbind request if its use is inappropriate (for example a pooled connection will be released and returned to its connection pool without ever issuing an unbind request).
Calling
close
on a connection that is already closed has no effect.- Parameters:
request
- The unbind request to use in the case where a physical connection is closed.reason
- A reason describing why the connection was closed.- Throws:
NullPointerException
- Ifrequest
wasnull
.
-
compare
Compares an entry in the Directory Server using the provided compare request.- Parameters:
request
- The compare request.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support compare operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
compare
CompareResult compare(String name, String attributeDescription, String assertionValue) throws LdapException Compares the named entry in the Directory Server against the provided attribute value assertion.This method is equivalent to the following code:
CompareRequest request = new CompareRequest(name, attributeDescription, assertionValue); connection.compare(request);
- Parameters:
name
- The distinguished name of the entry to be compared.attributeDescription
- The name of the attribute to be compared.assertionValue
- The assertion value to be compared.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.LocalizedIllegalArgumentException
- Ifname
orAttributeDescription
could not be decoded using the default schema.UnsupportedOperationException
- If this connection does not support compare operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifname
,attributeDescription
, orassertionValue
wasnull
.
-
compareAsync
Asynchronously compares an entry in the Directory Server using the provided compare request.- Parameters:
request
- The compare request.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support compare operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
compareAsync
LdapPromise<CompareResult> compareAsync(CompareRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously compares an entry in the Directory Server using the provided compare request.- Parameters:
request
- The compare request.intermediateResponseHandler
- An intermediate response handler which can be used to process any intermediate responses as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support compare operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
delete
Deletes an entry from the Directory Server using the provided delete request.- Parameters:
request
- The delete request.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support delete operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
delete
Deletes the named entry from the Directory Server.This method is equivalent to the following code:
DeleteRequest request = new DeleteRequest(name); connection.delete(request);
- Parameters:
name
- The distinguished name of the entry to be deleted.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.LocalizedIllegalArgumentException
- Ifname
could not be decoded using the default schema.UnsupportedOperationException
- If this connection does not support delete operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifname
wasnull
.
-
delete
Deletes the named entry from the Directory Server.This method is equivalent to the following code:
DeleteRequest request = new DeleteRequest(name); connection.delete(request);
- Parameters:
name
- The distinguished name of the entry to be deleted.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.LocalizedIllegalArgumentException
- Ifname
could not be decoded using the default schema.UnsupportedOperationException
- If this connection does not support delete operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifname
wasnull
.
-
deleteSubtree
Deletes the named entry and all of its subordinates from the Directory Server.This method is equivalent to the following code:
DeleteRequest request = new DeleteRequest(name).addControl( connection.delete(request);
- Parameters:
name
- The distinguished name of the subtree base entry to be deleted.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.LocalizedIllegalArgumentException
- Ifname
could not be decoded using the default schema.UnsupportedOperationException
- If this connection does not support delete operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifname
wasnull
.
-
deleteAsync
Asynchronously deletes an entry from the Directory Server using the provided delete request.- Parameters:
request
- The delete request.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support delete operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
deleteAsync
LdapPromise<Result> deleteAsync(DeleteRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously deletes an entry from the Directory Server using the provided delete request.- Parameters:
request
- The delete request.intermediateResponseHandler
- An intermediate response handler which can be used to process any intermediate responses as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support delete operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
extendedRequest
Requests that the Directory Server performs the provided extended request.- Type Parameters:
R
- The type of result returned by the extended request.- Parameters:
request
- The extended request.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support extended operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
extendedRequest
<R extends ExtendedResult> R extendedRequest(ExtendedRequest<R> request, IntermediateResponseHandler handler) throws LdapException Requests that the Directory Server performs the provided extended request, optionally listening for any intermediate responses.- Type Parameters:
R
- The type of result returned by the extended request.- Parameters:
request
- The extended request.handler
- An intermediate response handler which can be used to process any intermediate responses as they are received, may benull
.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support extended operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
extendedRequest
GenericExtendedResult extendedRequest(String requestName, ByteString requestValue) throws LdapException Requests that the Directory Server performs the provided extended request.This method is equivalent to the following code:
GenericExtendedRequest request = new GenericExtendedRequest(requestName, requestValue); connection.extendedRequest(request);
- Parameters:
requestName
- The dotted-decimal representation of the unique OID corresponding to the extended request.requestValue
- The content of the extended request in a form defined by the extended operation, ornull
if there is no content.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support extended operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- IfrequestName
wasnull
.
-
extendedRequestAsync
Asynchronously performs the provided extended request in the Directory Server.- Type Parameters:
R
- The type of result returned by the extended request.- Parameters:
request
- The extended request.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support extended operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
extendedRequestAsync
<R extends ExtendedResult> LdapPromise<R> extendedRequestAsync(ExtendedRequest<R> request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously performs the provided extended request in the Directory Server.- Type Parameters:
R
- The type of result returned by the extended request.- Parameters:
request
- The extended request.intermediateResponseHandler
- An intermediate response handler which can be used to process any intermediate responses as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support extended operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
isClosed
boolean isClosed()Indicates whether this connection has been explicitly closed by callingclose
. This method will not returntrue
if a fatal error has occurred on the connection unlessclose
has been called.- Returns:
true
if this connection has been explicitly closed by callingclose
, orfalse
otherwise.
-
isValid
boolean isValid()Returnstrue
if this connection has not been closed and no fatal errors have been detected. This method is guaranteed to returnfalse
only when it is called after the methodclose
has been called.- Returns:
true
if this connection is valid,false
otherwise.
-
modify
Modifies an entry in the Directory Server using the provided modify request.- Parameters:
request
- The modify request.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support modify operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
modify
Modifies an entry in the Directory Server using the provided lines of LDIF.This method is equivalent to the following code:
ModifyRequest request = new ModifyRequest(name, ldifChanges); connection.modify(request);
- Parameters:
ldifLines
- Lines of LDIF containing the a single LDIF modify change record.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support modify operations.LocalizedIllegalArgumentException
- IfldifLines
was empty, or contained invalid LDIF, or could not be decoded using the default schema.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- IfldifLines
wasnull
.
-
modifyAsync
Asynchronously modifies an entry in the Directory Server using the provided modify request.- Parameters:
request
- The modify request.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support modify operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
modifyAsync
LdapPromise<Result> modifyAsync(ModifyRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously modifies an entry in the Directory Server using the provided modify request.- Parameters:
request
- The modify request.intermediateResponseHandler
- An intermediate response handler which can be used to process any intermediate responses as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support modify operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
modifyDn
Renames an entry in the Directory Server using the provided modify DN request.- Parameters:
request
- The modify DN request.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support modify DN operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
modifyDn
Renames the named entry in the Directory Server using the provided new RDN.This method is equivalent to the following code:
ModifyDNRequest request = new ModifyDNRequest(name, newRDN); connection.modifyDN(request);
- Parameters:
name
- The distinguished name of the entry to be renamed.newRDN
- The new RDN of the entry.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.LocalizedIllegalArgumentException
- Ifname
ornewRDN
could not be decoded using the default schema.UnsupportedOperationException
- If this connection does not support modify DN operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifname
ornewRDN
wasnull
.
-
modifyDnAsync
Asynchronously renames an entry in the Directory Server using the provided modify DN request.- Parameters:
request
- The modify DN request.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support modify DN operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
modifyDnAsync
LdapPromise<Result> modifyDnAsync(ModifyDnRequest request, IntermediateResponseHandler intermediateResponseHandler) Asynchronously renames an entry in the Directory Server using the provided modify DN request.- Parameters:
request
- The modify DN request.intermediateResponseHandler
- An intermediate response handler which can be used to process any intermediate responses as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support modify DN operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
readEntry
Reads the named entry from the Directory Server.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, this method will never returnnull
.This method is equivalent to the following code:
SearchRequest request = new SearchRequest(name, SearchScope.BASE_OBJECT, "(objectClass=*)", attributeDescriptions); connection.searchSingleEntry(request);
- Parameters:
name
- The distinguished name of the entry to be read.attributeDescriptions
- The names of the attributes to be included with the entry, which may benull
or empty indicating that all user attributes should be returned.- Returns:
- The single search result entry returned from the search.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- If thename
wasnull
.
-
readEntry
Reads the named entry from the Directory Server.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, this method will never returnnull
.This method is equivalent to the following code:
SearchRequest request = new SearchRequest(name, SearchScope.BASE_OBJECT, "(objectClass=*)", attributeDescriptions); connection.searchSingleEntry(request);
- Parameters:
name
- The distinguished name of the entry to be read.attributeDescriptions
- The names of the attributes to be included with the entry.- Returns:
- The single search result entry returned from the search.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.LocalizedIllegalArgumentException
- IfbaseObject
could not be decoded using the default schema.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- If thename
wasnull
.
-
readEntryAsync
Asynchronously reads the named entry from the Directory Server.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, the returned promise will never returnnull
.This method is equivalent to the following code:
SearchRequest request = new SearchRequest(name, SearchScope.BASE_OBJECT, "(objectClass=*)", attributeDescriptions); connection.searchSingleEntryAsync(request, resultHandler, p);
- Parameters:
name
- The distinguished name of the entry to be read.attributeDescriptions
- The names of the attributes to be included with the entry, which may benull
or empty indicating that all user attributes should be returned.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- If thename
wasnull
.
-
removeConnectionEventListener
Removes the provided connection event listener from this connection so that it will no longer be notified when this connection is closed by the application, receives an unsolicited notification, or experiences a fatal error.- Parameters:
listener
- The listener which no longer wants to be notified when events occur on this connection.- Throws:
NullPointerException
- If thelistener
wasnull
.
-
search
Searches the Directory Server using the provided search parameters. Any matching entries returned by the search will be exposed through the returnedConnectionEntryReader
.Unless otherwise specified, calling this method is equivalent to:
ConnectionEntryReader reader = new ConnectionEntryReader(this, request);
- Parameters:
request
- The search request.- Returns:
- The result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
orentries
wasnull
.
-
search
Result search(SearchRequest request, Collection<? super SearchResultEntry> entries) throws LdapException Searches the Directory Server using the provided search request. Any matching entries returned by the search will be added toentries
, even if the final search result indicates that the search failed. Search result references will be discarded.Warning: Usage of this method is discouraged if the search request is expected to yield a large number of search results since the entire set of results will be stored in memory, potentially causing an
OutOfMemoryError
.This method is equivalent to the following code:
connection.search(request, entries, null);
- Parameters:
request
- The search request.entries
- The collection to which matching entries should be added.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
orentries
wasnull
.
-
search
Result search(SearchRequest request, Collection<? super SearchResultEntry> entries, Collection<? super SearchResultReference> references) throws LdapException Searches the Directory Server using the provided search request. Any matching entries returned by the search will be added toentries
, even if the final search result indicates that the search failed. Similarly, search result references returned by the search will be added toreferences
.Warning: Usage of this method is discouraged if the search request is expected to yield a large number of search results since the entire set of results will be stored in memory, potentially causing an
OutOfMemoryError
.- Parameters:
request
- The search request.entries
- The collection to which matching entries should be added.references
- The collection to which search result references should be added, ornull
if references are to be discarded.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
orentries
wasnull
.
-
search
Searches the Directory Server using the provided search request. Any matching entries returned by the search as well as any search result references will be passed to the provided search result handler.- Parameters:
request
- The search request.handler
- A search result handler which can be used to process the search result entries and references as they are received, may benull
.- Returns:
- The result of the operation.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
search
ConnectionEntryReader search(String baseObject, SearchScope scope, String filter, String... attributeDescriptions) Searches the Directory Server using the provided search parameters. Any matching entries returned by the search will be exposed through theEntryReader
interface.Warning: When using a queue with an optional capacity bound, the connection will stop reading responses and wait if necessary for space to become available.
This method is equivalent to the following code:
SearchRequest request = new SearchRequest(baseDN, scope, filter, attributeDescriptions); connection.search(request, new LinkedBlockingQueue<Response>());
- Parameters:
baseObject
- The distinguished name of the base entry relative to which the search is to be performed.scope
- The scope of the search.filter
- The filter that defines the conditions that must be fulfilled in order for an entry to be returned.attributeDescriptions
- The names of the attributes to be included with each entry.- Returns:
- An entry reader exposing the returned entries.
- Throws:
UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- If thebaseObject
,scope
, orfilter
werenull
.
-
searchAsync
Asynchronously searches the Directory Server using the provided search request.- Parameters:
request
- The search request.entryHandler
- A search result handler which can be used to asynchronously process the search result entries and references as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
searchAsync
LdapPromise<Result> searchAsync(SearchRequest request, IntermediateResponseHandler intermediateResponseHandler, SearchResultHandler entryHandler) Asynchronously searches the Directory Server using the provided search request.- Parameters:
request
- The search request.intermediateResponseHandler
- An intermediate response handler which can be used to process any intermediate responses as they are received, may benull
.entryHandler
- A search result handler which can be used to asynchronously process the search result entries and references as they are received, may benull
.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- Ifrequest
wasnull
.
-
searchSingleEntry
Searches the Directory Server for a single entry using the provided search request.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, this method will never returnnull
. If multiple matching entries are returned by the Directory Server then the request will fail with anMultipleEntriesFoundException
.- Parameters:
request
- The search request.- Returns:
- The single search result entry returned from the search.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- If therequest
wasnull
.
-
searchSingleEntry
SearchResultEntry searchSingleEntry(String baseObject, SearchScope scope, String filter, String... attributeDescriptions) throws LdapException Searches the Directory Server for a single entry using the provided search parameters.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, this method will never returnnull
. If multiple matching entries are returned by the Directory Server then the request will fail with anMultipleEntriesFoundException
.This method is equivalent to the following code:
SearchRequest request = new SearchRequest(baseObject, scope, filter, attributeDescriptions); connection.searchSingleEntry(request);
- Parameters:
baseObject
- The distinguished name of the base entry relative to which the search is to be performed.scope
- The scope of the search.filter
- The filter that defines the conditions that must be fulfilled in order for an entry to be returned.attributeDescriptions
- The names of the attributes to be included with each entry.- Returns:
- The single search result entry returned from the search.
- Throws:
LdapException
- If the result code indicates that the request failed for some reason.LocalizedIllegalArgumentException
- IfbaseObject
could not be decoded using the default schema or iffilter
is not a valid LDAP string representation of a filter.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- If thebaseObject
,scope
, orfilter
werenull
.
-
searchSingleEntryAsync
Asynchronously searches the Directory Server for a single entry using the provided search request.If the requested entry is not returned by the Directory Server then the request will fail with an
EntryNotFoundException
. More specifically, the returned promise will never returnnull
. If multiple matching entries are returned by the Directory Server then the request will fail with anMultipleEntriesFoundException
.- Parameters:
request
- The search request.- Returns:
- A promise representing the result of the operation.
- Throws:
UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. ifisClosed() == true
.NullPointerException
- If therequest
wasnull
.
-