Ejemplo n.º 1
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();
   }
 }