This class provides an implementation of the LDAP cancel extended request as
defined in
RFC 3909. It
may be used to request that the server interrupt processing on another
operation in progress on the same connection. It behaves much like the
abandon operation, with the exception that both the cancel request and the
operation that is canceled will receive responses, whereas an abandon request
never returns a response, and the operation that is abandoned will also not
receive a response if the abandon is successful.
Example
The following example initiates an asynchronous modify operation and then
attempts to cancel it:
Modification mod = new Modification(ModificationType.REPLACE,
"description", "This is the new description.");
ModifyRequest modifyRequest =
new ModifyRequest("dc=example,dc=com", mod);
AsyncRequestID asyncRequestID =
connection.asyncModify(modifyRequest, myAsyncResultListener);
// Assume that we've waited a reasonable amount of time but the modify
// hasn't completed yet so we'll try to cancel it.
ExtendedResult cancelResult;
try
{
cancelResult = connection.processExtendedOperation(
new CancelExtendedRequest(asyncRequestID));
// This doesn't necessarily mean that the operation was successful, since
// some kinds of extended operations (like cancel) return non-success
// results under normal conditions.
}
catch (LDAPException le)
{
// For an extended operation, this generally means that a problem was
// encountered while trying to send the request or read the result.
cancelResult = new ExtendedResult(le);
}
switch (cancelResult.getResultCode().intValue())
{
case ResultCode.CANCELED_INT_VALUE:
// The modify operation was successfully canceled.
break;
case ResultCode.CANNOT_CANCEL_INT_VALUE:
// This indicates that the server isn't capable of canceling that
// type of operation. This probably won't happen for this kind of
// modify operation, but it could happen for other kinds of operations.
break;
case ResultCode.TOO_LATE_INT_VALUE:
// This indicates that the cancel request was received too late and the
// server is intending to process the operation.
break;
case ResultCode.NO_SUCH_OPERATION_INT_VALUE:
// This indicates that the server doesn't know anything about the
// operation, most likely because it has already completed.
break;
default:
// This suggests that the operation failed for some other reason.
break;
}