Java Code Examples for org.apache.ratis.thirdparty.io.grpc.Metadata#get()

The following examples show how to use org.apache.ratis.thirdparty.io.grpc.Metadata#get() . 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: GrpcUtil.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
static long getCallId(Throwable t) {
  if (t instanceof StatusRuntimeException) {
    final Metadata trailers = ((StatusRuntimeException)t).getTrailers();
    String callId = trailers.get(CALL_ID);
    return callId != null ? Integer.parseInt(callId) : -1;
  }
  return -1;
}
 
Example 3
Source File: GrpcUtil.java    From ratis with Apache License 2.0 5 votes vote down vote up
static long getCallId(Throwable t) {
  if (t instanceof StatusRuntimeException) {
    final Metadata trailers = ((StatusRuntimeException)t).getTrailers();
    String callId = trailers.get(CALL_ID);
    return callId != null ? Integer.parseInt(callId) : -1;
  }
  return -1;
}