org.apache.ratis.thirdparty.io.grpc.Status Java Examples

The following examples show how to use org.apache.ratis.thirdparty.io.grpc.Status. 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: GrpcUtil.java    From ratis with Apache License 2.0 6 votes vote down vote up
static IOException tryUnwrapException(StatusRuntimeException se) {
  final Metadata trailers = se.getTrailers();
  final Status status = se.getStatus();
  if (trailers != null && status != null) {
    final String className = trailers.get(EXCEPTION_TYPE_KEY);
    if (className != null) {
      try {
        Class<?> clazz = Class.forName(className);
        final Exception unwrapped = ReflectionUtils.instantiateException(
            clazz.asSubclass(Exception.class), status.getDescription(), se);
        return IOUtils.asIOException(unwrapped);
      } catch (Exception e) {
        se.addSuppressed(e);
        return new IOException(se);
      }
    }
  }
  return null;
}
 
Example #2
Source File: GrpcServerProtocolService.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
@Override
public void onError(Throwable t) {
  GrpcUtil.warn(LOG, () -> getId() + ": installSnapshot onError, lastRequest: " + getPreviousRequestString(), t);
  if (isClosed.compareAndSet(false, true)) {
    Status status = Status.fromThrowable(t);
    if (status != null && status.getCode() != Status.Code.CANCELLED) {
      responseObserver.onCompleted();
    }
  }
}
 
Example #3
Source File: GrpcUtil.java    From ratis with Apache License 2.0 5 votes vote down vote up
static StatusRuntimeException wrapException(Throwable t, long callId) {
  t = JavaUtils.unwrapCompletionException(t);

  Metadata trailers = new Metadata();
  trailers.put(EXCEPTION_TYPE_KEY, t.getClass().getCanonicalName());
  if (callId > 0) {
    trailers.put(CALL_ID, String.valueOf(callId));
  }
  return new StatusRuntimeException(
      Status.INTERNAL.withCause(t).withDescription(t.getMessage()), trailers);
}
 
Example #4
Source File: GrpcUtil.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
static StatusRuntimeException wrapException(Throwable t, Metadata trailers) {
  return new StatusRuntimeException(
      Status.INTERNAL.withCause(t).withDescription(t.getMessage()), trailers);
}