Class MessageFramer

java.lang.Object
io.grpc.internal.MessageFramer
All Implemented Interfaces:
Framer

public class MessageFramer extends Object implements Framer
Encodes gRPC messages to be delivered via the transport layer which implements MessageFramer.Sink.
  • Field Details

    • NO_MAX_OUTBOUND_MESSAGE_SIZE

      private static final int NO_MAX_OUTBOUND_MESSAGE_SIZE
      See Also:
    • HEADER_LENGTH

      private static final int HEADER_LENGTH
      See Also:
    • UNCOMPRESSED

      private static final byte UNCOMPRESSED
      See Also:
    • COMPRESSED

      private static final byte COMPRESSED
      See Also:
    • sink

      private final MessageFramer.Sink sink
    • maxOutboundMessageSize

      private int maxOutboundMessageSize
    • buffer

      private WritableBuffer buffer
    • compressor

      private Compressor compressor
    • messageCompression

      private boolean messageCompression
    • outputStreamAdapter

      private final MessageFramer.OutputStreamAdapter outputStreamAdapter
    • headerScratch

      private final ByteBuffer headerScratch
    • bufferAllocator

      private final WritableBufferAllocator bufferAllocator
    • statsTraceCtx

      private final StatsTraceContext statsTraceCtx
    • closed

      private boolean closed
    • messagesBuffered

      private int messagesBuffered
    • currentMessageSeqNo

      private int currentMessageSeqNo
    • currentMessageWireSize

      private long currentMessageWireSize
  • Constructor Details

    • MessageFramer

      public MessageFramer(MessageFramer.Sink sink, WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx)
      Creates a MessageFramer.
      Parameters:
      sink - the sink used to deliver frames to the transport
      bufferAllocator - allocates buffers that the transport can commit to the wire.
  • Method Details

    • setCompressor

      public MessageFramer setCompressor(Compressor compressor)
      Description copied from interface: Framer
      Set the compressor used for compression.
      Specified by:
      setCompressor in interface Framer
    • setMessageCompression

      public MessageFramer setMessageCompression(boolean enable)
      Description copied from interface: Framer
      Enable or disable compression.
      Specified by:
      setMessageCompression in interface Framer
    • setMaxOutboundMessageSize

      public void setMaxOutboundMessageSize(int maxSize)
      Description copied from interface: Framer
      Set a size limit for each outbound message.
      Specified by:
      setMaxOutboundMessageSize in interface Framer
    • writePayload

      public void writePayload(InputStream message)
      Writes out a payload message.
      Specified by:
      writePayload in interface Framer
      Parameters:
      message - contains the message to be written out. It will be completely consumed.
    • writeUncompressed

      private int writeUncompressed(InputStream message, int messageLength) throws IOException
      Throws:
      IOException
    • writeCompressed

      private int writeCompressed(InputStream message, int unusedMessageLength) throws IOException
      Throws:
      IOException
    • getKnownLength

      private int getKnownLength(InputStream inputStream) throws IOException
      Throws:
      IOException
    • writeKnownLengthUncompressed

      private int writeKnownLengthUncompressed(InputStream message, int messageLength) throws IOException
      Write an unserialized message with a known length, uncompressed.
      Throws:
      IOException
    • writeBufferChain

      private void writeBufferChain(MessageFramer.BufferChainOutputStream bufferChain, boolean compressed)
      Write a message that has been serialized to a sequence of buffers.
    • writeToOutputStream

      private static int writeToOutputStream(InputStream message, OutputStream outputStream) throws IOException
      Throws:
      IOException
    • writeRaw

      private void writeRaw(byte[] b, int off, int len)
    • flush

      public void flush()
      Flushes any buffered data in the framer to the sink.
      Specified by:
      flush in interface Framer
    • isClosed

      public boolean isClosed()
      Indicates whether or not this framer has been closed via a call to either close() or dispose().
      Specified by:
      isClosed in interface Framer
    • close

      public void close()
      Flushes and closes the framer and releases any buffers. After the framer is closed or disposed, additional calls to this method will have no affect.
      Specified by:
      close in interface Framer
    • dispose

      public void dispose()
      Closes the framer and releases any buffers, but does not flush. After the framer is closed or disposed, additional calls to this method will have no affect.
      Specified by:
      dispose in interface Framer
    • releaseBuffer

      private void releaseBuffer()
    • commitToSink

      private void commitToSink(boolean endOfStream, boolean flush)
    • verifyNotClosed

      private void verifyNotClosed()