void channelClosed(Throwable ex) {
   if (ex != null) {
     RpcException e;
     if (ex instanceof RpcException) {
       e = (RpcException) ex;
     } else {
       e = new RpcException(ex);
     }
     for (RpcOutcome<?> f : map.values()) {
       f.setException(e);
     }
   }
 }
  public <V> RpcOutcome<V> getFuture(int rpcType, int coordinationId, Class<V> clazz) {
    // logger.debug("Getting future for coordinationId {} and class {}", coordinationId, clazz);
    RpcOutcome<?> rpc = removeFromMap(coordinationId);
    // logger.debug("Got rpc from map {}", rpc);
    Class<?> outcomeClass = rpc.getOutcomeType();

    if (outcomeClass != clazz) {

      throw new IllegalStateException(
          String.format(
              "RPC Engine had a submission and response configuration mismatch.  The RPC request that you submitted was defined with an expected response type of %s.  However, "
                  + "when the response returned, a call to getResponseDefaultInstance() with Rpc number %d provided an expected class of %s.  This means either your submission uses the wrong type definition"
                  + "or your getResponseDefaultInstance() method responds the wrong instance type ",
              clazz.getCanonicalName(), rpcType, outcomeClass.getCanonicalName()));
    }

    @SuppressWarnings("unchecked")
    RpcOutcome<V> crpc = (RpcOutcome<V>) rpc;

    // logger.debug("Returning casted future");
    return crpc;
  }
Ejemplo n.º 3
0
    public void run() {
      try {
        MessageLite m = getResponseDefaultInstance(rpcType);
        assert rpcConfig.checkReceive(rpcType, m.getClass());
        RpcOutcome<?> rpcFuture = queue.getFuture(rpcType, coordinationId, m.getClass());
        Parser<?> parser = m.getParserForType();
        Object value = parser.parseFrom(new ByteBufInputStream(pBody, pBody.readableBytes()));
        rpcFuture.set(value, dBody);
        if (RpcConstants.EXTRA_DEBUGGING) {
          logger.debug("Updated rpc future {} with value {}", rpcFuture, value);
        }
      } catch (Exception ex) {
        logger.error("Failure while handling response.", ex);
      } finally {
        if (pBody != null) {
          pBody.release();
        }

        if (dBody != null) {
          dBody.release();
        }
      }
    }
 public void updateFailedFuture(int coordinationId, RpcFailure failure) {
   // logger.debug("Updating failed future.");
   RpcOutcome<?> rpc = removeFromMap(coordinationId);
   rpc.setException(new RemoteRpcException(failure));
 }