Operations

Operations provide the core functionality for interacting with LDAP servers. Ldaptive provides the following operation implementations:

The operation interface looks like:

public interface Operation<Q extends Request, S extends Result>
{
  OperationHandle<Q, S> send(Q request) throws LdapException;

  S execute(Q request) throws LdapException;
}

Usage

Synchronous calls

Ldaptive is asynchronous at its core but provides an execute to wait for operations to complete.

try {
  DeleteOperation.builder()
    .factory(new DefaultConnectionFactory("ldap://directory.ldaptive.org"))
    .throwIf(ResultPredicate.NOT_SUCCESS)
    .build()
    .execute(DeleteRequest.builder()
      .dn("cn=myentry,dc=ldaptive,dc=org")
      .build());
} catch (LdapException e) {
  // delete operation was not successful
}

Note that the throwIf function is only applicable for synchronous usage when it is desirable to raise an exception for certain server responses in a try-catch block. It will not invoke the onException function. By default non-success responses are not considered exceptional.

Asynchronous calls

For asynchronous usage use the send method and process results in the onResult function.

DeleteOperation.builder()
  .factory(new DefaultConnectionFactory("ldap://directory.ldaptive.org"))
  .onResult(result -> {
    if (!result.equals(ResultCode.SUCCESS)) {
      // delete operation was not successful
    }
  })
  .build()
  .send(DeleteRequest.builder()
    .dn("cn=myentry,dc=ldaptive,dc=org")
    .build());