Esempio n. 1
0
  /** {@inheritDoc} */
  @InternalUseOnly()
  public void responseReceived(final LDAPResponse response) throws LDAPException {
    if (!responseReturned.compareAndSet(false, true)) {
      return;
    }

    final long responseTime = System.nanoTime() - createTime;

    final LDAPResult result;
    if (response instanceof ConnectionClosedResponse) {
      final ConnectionClosedResponse ccr = (ConnectionClosedResponse) response;
      final String msg = ccr.getMessage();
      if (msg == null) {
        result =
            new LDAPResult(
                asyncRequestID.getMessageID(),
                ccr.getResultCode(),
                ERR_CONN_CLOSED_WAITING_FOR_ASYNC_RESPONSE.get(),
                null,
                StaticUtils.NO_STRINGS,
                StaticUtils.NO_CONTROLS);
      } else {
        result =
            new LDAPResult(
                asyncRequestID.getMessageID(),
                ccr.getResultCode(),
                ERR_CONN_CLOSED_WAITING_FOR_ASYNC_RESPONSE_WITH_MESSAGE.get(msg),
                null,
                StaticUtils.NO_STRINGS,
                StaticUtils.NO_CONTROLS);
      }
    } else {
      result = (LDAPResult) response;
    }

    switch (operationType) {
      case ADD:
        connection.getConnectionStatistics().incrementNumAddResponses(responseTime);
        break;
      case DELETE:
        connection.getConnectionStatistics().incrementNumDeleteResponses(responseTime);
        break;
      case MODIFY:
        connection.getConnectionStatistics().incrementNumModifyResponses(responseTime);
        break;
      case MODIFY_DN:
        connection.getConnectionStatistics().incrementNumModifyDNResponses(responseTime);
        break;
    }

    resultListener.ldapResultReceived(asyncRequestID, result);
    asyncRequestID.setResult(result);
  }
Esempio n. 2
0
  /**
   * Creates a new instance of this async helper that will be used to forward decoded results to the
   * provided async result listener.
   *
   * @param connection The connection with which this async helper is associated.
   * @param operationType The operation type for the associated operation.
   * @param messageID The message ID for the associated operation.
   * @param resultListener The async result listener to be notified when the response arrives.
   * @param intermediateResponseListener The intermediate response listener to be notified of any
   *     intermediate response messages received.
   */
  @InternalUseOnly()
  AsyncHelper(
      final LDAPConnection connection,
      final OperationType operationType,
      final int messageID,
      final AsyncResultListener resultListener,
      final IntermediateResponseListener intermediateResponseListener) {
    this.connection = connection;
    this.operationType = operationType;
    this.resultListener = resultListener;
    this.intermediateResponseListener = intermediateResponseListener;

    asyncRequestID = new AsyncRequestID(messageID, connection);
    responseReturned = new AtomicBoolean(false);
    createTime = System.nanoTime();
  }