Java Code Examples for io.grpc.Status#asRuntimeException()

The following examples show how to use io.grpc.Status#asRuntimeException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObservableClientCall.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 2
Source File: ErrorCatchingServerInterceptor.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 3
Source File: CommonErrorCatchingServerInterceptor.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 4
Source File: Worker.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
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");
  }
}
 
Example 5
Source File: Worker.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 6
Source File: Worker.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 7
Source File: ShardWorkerInstance.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: AwaitableUnaryClientCallListener.java    From zipkin-gcp with Apache License 2.0 5 votes vote down vote up
@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();
}