private static <ReqT, RespT, OutputT> OutputT getBlockingResult(
     AbstractRetryingRpcListener<ReqT, RespT, OutputT> listener) {
   try {
     listener.start();
     return listener.getCompletionFuture().get();
   } catch (InterruptedException e) {
     listener.cancel();
     throw Status.CANCELLED.withCause(e).asRuntimeException();
   } catch (ExecutionException e) {
     listener.cancel();
     throw Status.fromThrowable(e).asRuntimeException();
   }
 }
Exemplo n.º 2
0
 @Override
 public void sendMessage(ReqT message) {
   Preconditions.checkState(stream != null, "Not started");
   Preconditions.checkState(!cancelCalled, "call was cancelled");
   Preconditions.checkState(!halfCloseCalled, "call was half-closed");
   try {
     // TODO(notcarl): Find out if messageIs needs to be closed.
     InputStream messageIs = method.streamRequest(message);
     stream.writeMessage(messageIs);
   } catch (Throwable e) {
     stream.cancel(Status.CANCELLED.withCause(e).withDescription("Failed to stream message"));
     return;
   }
   // For unary requests, we don't flush since we know that halfClose should be coming soon. This
   // allows us to piggy-back the END_STREAM=true on the last message frame without opening the
   // possibility of broken applications forgetting to call halfClose without noticing.
   if (!unaryRequest) {
     stream.flush();
   }
 }