io.grpc.Status#asRuntimeException ( )源码实例Demo

下面列出了io.grpc.Status#asRuntimeException ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void onClose(Status status, Metadata trailers) {
    if (status.equals(Status.OK)) {
        subscriber.onCompleted();
    } else {
        StatusRuntimeException statusException = status.asRuntimeException(trailers);
        subscriber.onError(statusException);
    }
    inputSubscription.unsubscribe();
}
 
private <ReqT, RespT> void handlingException(ServerCall<ReqT, RespT> call, Exception e, boolean debug) {
    logger.info("Returning exception to the client: {}", e.getMessage(), e);
    Pair<Status, Metadata> statusAndMeta = ErrorResponses.of(e, debug);
    Status status = statusAndMeta.getLeft();
    safeClose(() -> call.close(status, statusAndMeta.getRight()));
    throw status.asRuntimeException();
}
 
private <ReqT, RespT> void handlingException(ServerCall<ReqT, RespT> call, Exception e, boolean debug) {
    logger.info("Returning exception to the client: {}", e.getMessage(), e);
    Pair<Status, Metadata> statusAndMeta = exceptionMapper.of(e, debug);
    Status status = statusAndMeta.getLeft();
    safeClose(() -> call.close(status, statusAndMeta.getRight()));
    throw status.asRuntimeException();
}
 
源代码4 项目: bazel-buildfarm   文件: Worker.java
private void removeWorker(String name) {
  try {
    backplane.removeWorker(name, "removing self prior to initialization");
  } catch (IOException e) {
    Status status = Status.fromThrowable(e);
    if (status.getCode() != Code.UNAVAILABLE && status.getCode() != Code.DEADLINE_EXCEEDED) {
      throw status.asRuntimeException();
    }
    logger.log(INFO, "backplane was unavailable or overloaded, deferring removeWorker");
  }
}
 
源代码5 项目: bazel-buildfarm   文件: Worker.java
private void addBlobsLocation(List<Digest> digests, String name) {
  while (!backplane.isStopped()) {
    try {
      backplane.addBlobsLocation(digests, name);
      return;
    } catch (IOException e) {
      Status status = Status.fromThrowable(e);
      if (status.getCode() != Code.UNAVAILABLE && status.getCode() != Code.DEADLINE_EXCEEDED) {
        throw status.asRuntimeException();
      }
    }
  }
  throw Status.UNAVAILABLE.withDescription("backplane was stopped").asRuntimeException();
}
 
源代码6 项目: bazel-buildfarm   文件: Worker.java
private void addWorker(ShardWorker worker) {
  while (!backplane.isStopped()) {
    try {
      backplane.addWorker(worker);
      return;
    } catch (IOException e) {
      Status status = Status.fromThrowable(e);
      if (status.getCode() != Code.UNAVAILABLE && status.getCode() != Code.DEADLINE_EXCEEDED) {
        throw status.asRuntimeException();
      }
    }
  }
  throw Status.UNAVAILABLE.withDescription("backplane was stopped").asRuntimeException();
}
 
源代码7 项目: bazel-buildfarm   文件: ShardWorkerInstance.java
@Override
public Operation getOperation(String name) {
  while (!backplane.isStopped()) {
    try {
      return backplane.getOperation(name);
    } catch (IOException e) {
      Status status = Status.fromThrowable(e);
      if (status.getCode() != Code.UNAVAILABLE && status.getCode() != Code.DEADLINE_EXCEEDED) {
        throw status.asRuntimeException();
      }
    }
  }
  throw Status.UNAVAILABLE.withDescription("backplane is stopped").asRuntimeException();
}
 
@Override
public synchronized void onClose(Status status, Metadata trailers) {
  if (status.isOk()) {
    if (!resultSet) {
      result =
          Status.INTERNAL
              .withDescription("No value received for unary call")
              .asRuntimeException(trailers);
    }
  } else {
    result = status.asRuntimeException(trailers);
  }
  resultSet = true;
  countDown.countDown();
}