Beispiel #1
0
  /**
   * This method handles submitting and then waiting for the request from the server. It uses the
   * ClientRequest API to actually write the request and then read back the response. This
   * implementation will block for a response from the server.
   *
   * @param <T> Return type
   * @param clientRequest ClientRequest implementation used to write the request and read the
   *     response
   * @param operationName Simple string representing the type of request
   * @return Data returned by the individual requests
   */
  private <T> void requestAsync(
      ClientRequest<T> delegate,
      NonblockingStoreCallback callback,
      long timeoutMs,
      String operationName) {
    ClientRequestExecutor clientRequestExecutor = null;

    try {
      clientRequestExecutor = pool.checkout(destination);
    } catch (Exception e) {
      // If we can't check out a socket from the pool, we'll usually get
      // either an IOException (subclass) or an UnreachableStoreException
      // error. However, in the case of asynchronous calls, we want the
      // error to be reported via our callback, not returned to the caller
      // directly.
      if (!(e instanceof UnreachableStoreException))
        e = new UnreachableStoreException("Failure in " + operationName + ": " + e.getMessage(), e);

      try {
        callback.requestComplete(e, 0);
      } catch (Exception ex) {
        if (logger.isEnabledFor(Level.WARN)) logger.warn(ex, ex);
      }

      return;
    }

    NonblockingStoreCallbackClientRequest<T> clientRequest =
        new NonblockingStoreCallbackClientRequest<T>(delegate, clientRequestExecutor, callback);
    clientRequestExecutor.addClientRequest(clientRequest, timeoutMs);
  }
Beispiel #2
0
 private void invokeCallback(Object o, long requestTime) {
   if (callback != null) {
     try {
       callback.requestComplete(o, requestTime);
     } catch (Exception e) {
       if (logger.isEnabledFor(Level.WARN)) logger.warn(e, e);
     }
   }
 }