public ByteBuf serializeRequest(I message) throws IOException { switch (requestType) { case PROTOBUF: return serializeProto((Message) message); default: final CompositeByteBuf out = alloc.compositeBuffer(); try (ByteBufOutputStream os = new ByteBufOutputStream(out)) { ByteStreams.copy(method.streamRequest(message), os); } return out; } }
final void sendMessage(final ReqT message) { State savedState = state; if (savedState.passThrough) { savedState.winningSubstream.stream.writeMessage(method.streamRequest(message)); return; } class SendMessageEntry implements BufferEntry { @Override public void runWith(Substream substream) { substream.stream.writeMessage(method.streamRequest(message)); } } delayOrExecute(new SendMessageEntry()); }
final void sendMessage(final ReqT message) { State savedState = state; if (savedState.passThrough) { savedState.winningSubstream.stream.writeMessage(method.streamRequest(message)); return; } class SendMessageEntry implements BufferEntry { @Override public void runWith(Substream substream) { substream.stream.writeMessage(method.streamRequest(message)); } } delayOrExecute(new SendMessageEntry()); }
public ByteBuf serializeRequest(I message) throws IOException { switch (requestType) { case PROTOBUF: return serializeProto((Message) message); default: final CompositeByteBuf out = alloc.compositeBuffer(); try (ByteBufOutputStream os = new ByteBufOutputStream(out)) { ByteStreams.copy(method.streamRequest(message), os); } return out; } }
@Override public void sendMessage(ReqT message) { checkState(stream != null, "Not started"); checkState(!cancelCalled, "call was cancelled"); checkState(!halfCloseCalled, "call was half-closed"); try { if (stream instanceof RetriableStream) { @SuppressWarnings("unchecked") RetriableStream<ReqT> retriableStream = (RetriableStream<ReqT>) stream; retriableStream.sendMessage(message); } else { stream.writeMessage(method.streamRequest(message)); } } catch (RuntimeException e) { stream.cancel(Status.CANCELLED.withCause(e).withDescription("Failed to stream message")); return; } catch (Error e) { stream.cancel(Status.CANCELLED.withDescription("Client sendMessage() failed with Error")); throw e; } // 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(); } }
@Override public void sendMessage(ReqT message) { checkState(stream != null, "Not started"); checkState(!cancelCalled, "call was cancelled"); checkState(!halfCloseCalled, "call was half-closed"); try { if (stream instanceof RetriableStream) { @SuppressWarnings("unchecked") RetriableStream<ReqT> retriableStream = ((RetriableStream<ReqT>) stream); retriableStream.sendMessage(message); } else { stream.writeMessage(method.streamRequest(message)); } } catch (RuntimeException e) { stream.cancel(Status.CANCELLED.withCause(e).withDescription("Failed to stream message")); return; } catch (Error e) { stream.cancel(Status.CANCELLED.withDescription("Client sendMessage() failed with Error")); throw e; } // 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(); } }