Ejemplo n.º 1
0
 /** Return a {@link Status} given a canonical error {@link Code} value. */
 public static Status fromCodeValue(int codeValue) {
   if (codeValue < 0 || codeValue > STATUS_LIST.size()) {
     return UNKNOWN.withDescription("Unknown code " + codeValue);
   } else {
     return STATUS_LIST.get(codeValue);
   }
 }
Ejemplo n.º 2
0
 @Override
 public void cancel(@Nullable String message, @Nullable Throwable cause) {
   if (cancelCalled) {
     return;
   }
   cancelCalled = true;
   try {
     // Cancel is called in exception handling cases, so it may be the case that the
     // stream was never successfully created.
     if (stream != null) {
       Status status = Status.CANCELLED;
       if (message != null) {
         status = status.withDescription(message);
       }
       if (cause != null) {
         status = status.withCause(cause);
       }
       if (message == null && cause == null) {
         // TODO(zhangkun83): log a warning with this exception once cancel() has been deleted from
         // ClientCall.
         status =
             status.withCause(
                 new CancellationException("Client called cancel() without any detail"));
       }
       stream.cancel(status);
     }
   } finally {
     if (context != null) {
       context.removeListener(ClientCallImpl.this);
     }
   }
 }