Class CancelExtendedRequest

java.lang.Object
com.unboundid.ldap.sdk.LDAPRequest
com.unboundid.ldap.sdk.ExtendedRequest
com.unboundid.ldap.sdk.extensions.CancelExtendedRequest
All Implemented Interfaces:
ProtocolOp, ReadOnlyLDAPRequest, Serializable

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;
 }
 
See Also:
  • Field Details

  • Constructor Details

    • CancelExtendedRequest

      Creates a new cancel extended request that will cancel the request with the specified async request ID.
      Parameters:
      requestID - The async request ID of the request to cancel. It must not be null.
    • CancelExtendedRequest

      public CancelExtendedRequest(int targetMessageID)
      Creates a new cancel extended request that will cancel the request with the specified message ID.
      Parameters:
      targetMessageID - The message ID of the request to cancel.
    • CancelExtendedRequest

      Creates a new cancel extended request that will cancel the request with the specified request ID.
      Parameters:
      requestID - The async request ID of the request to cancel. It must not be null.
      controls - The set of controls to include in the request.
    • CancelExtendedRequest

      public CancelExtendedRequest(int targetMessageID, @Nullable Control[] controls)
      Creates a new cancel extended request that will cancel the request with the specified message ID.
      Parameters:
      targetMessageID - The message ID of the request to cancel.
      controls - The set of controls to include in the request.
    • CancelExtendedRequest

      Creates a new cancel extended request from the provided generic extended request.
      Parameters:
      extendedRequest - The generic extended request to use to create this cancel extended request.
      Throws:
      LDAPException - If a problem occurs while decoding the request.
  • Method Details

    • process

      @NotNull protected ExtendedResult process(@NotNull LDAPConnection connection, int depth) throws LDAPException
      Sends this extended request to the directory server over the provided connection and returns the associated response.
      Overrides:
      process in class ExtendedRequest
      Parameters:
      connection - The connection to use to communicate with the directory server.
      depth - The current referral depth for this request. It should always be one for the initial request, and should only be incremented when following referrals.
      Returns:
      An LDAP result object that provides information about the result of the extended operation processing.
      Throws:
      LDAPException - If a problem occurs while sending the request or reading the response.
    • getTargetMessageID

      public int getTargetMessageID()
      Retrieves the message ID of the request to cancel.
      Returns:
      The message ID of the request to cancel.
    • duplicate

      Creates a new instance of this LDAP request that may be modified without impacting this request.. Subclasses should override this method to return a duplicate of the appropriate type.
      Specified by:
      duplicate in interface ReadOnlyLDAPRequest
      Overrides:
      duplicate in class ExtendedRequest
      Returns:
      A new instance of this LDAP request that may be modified without impacting this request.
    • duplicate

      Creates a new instance of this LDAP request that may be modified without impacting this request. The provided controls will be used for the new request instead of duplicating the controls from this request.. Subclasses should override this method to return a duplicate of the appropriate type.
      Specified by:
      duplicate in interface ReadOnlyLDAPRequest
      Overrides:
      duplicate in class ExtendedRequest
      Parameters:
      controls - The set of controls to include in the duplicate request.
      Returns:
      A new instance of this LDAP request that may be modified without impacting this request.
    • getExtendedRequestName

      Retrieves the user-friendly name for the extended request, if available. If no user-friendly name has been defined, then the OID will be returned.
      Overrides:
      getExtendedRequestName in class ExtendedRequest
      Returns:
      The user-friendly name for this extended request, or the OID if no user-friendly name is available.
    • toString

      public void toString(@NotNull StringBuilder buffer)
      Appends a string representation of this request to the provided buffer.
      Specified by:
      toString in interface ProtocolOp
      Specified by:
      toString in interface ReadOnlyLDAPRequest
      Overrides:
      toString in class ExtendedRequest
      Parameters:
      buffer - The buffer to which to append a string representation of this request.