Class MessageDeframer
java.lang.Object
io.grpc.internal.MessageDeframer
- All Implemented Interfaces:
Deframer, Closeable, AutoCloseable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA listener of deframing events.private static class(package private) static final classAnInputStreamthat enforces theMessageDeframer.SizeEnforcingInputStream.maxMessageSizelimit for compressed frames.private static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate static final intprivate booleanprivate intprivate Decompressorprivate GzipInflatingBufferprivate static final intprivate intprivate booleanprivate byte[]private intprivate MessageDeframer.Listenerprivate static final intprivate intprivate CompositeReadableBufferprivate longprivate intprivate static final intprivate MessageDeframer.Stateprivate final StatsTraceContextprivate booleanprivate final TransportTracerprivate CompositeReadableBuffer -
Constructor Summary
ConstructorsConstructorDescriptionMessageDeframer(MessageDeframer.Listener listener, Decompressor decompressor, int maxMessageSize, StatsTraceContext statsTraceCtx, TransportTracer transportTracer) Create a deframer. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this deframer and frees any resources.voidClose when any messages currently queued have been requested and delivered.voiddeframe(ReadableBuffer data) Adds the given data to this deframer and attempts delivery to the listener.private voiddeliver()Reads and delivers as many messages to the listener as possible.private InputStreamprivate InputStream(package private) booleanbooleanisClosed()Indicates whether or not this deframer has been closed.private booleanReturns true if this deframer has already been closed or scheduled to close.private booleanprivate voidProcesses the GRPC message body, which depending on frame header flags may be compressed.private voidProcesses the GRPC compression header which is composed of the compression flag and the outer frame length.private booleanAttempts to read the required bytes into nextFrame.voidrequest(int numMessages) Requests up to the given number of messages from the call.voidsetDecompressor(Decompressor decompressor) Sets the decompressor available to use.voidsetFullStreamDecompressor(GzipInflatingBuffer fullStreamDecompressor) Sets the decompressor used for full-stream decompression.(package private) voidsetListener(MessageDeframer.Listener listener) voidsetMaxInboundMessageSize(int messageSize) (package private) voidSets a flag to interrupt delivery of any currently queued messages.
-
Field Details
-
HEADER_LENGTH
private static final int HEADER_LENGTH- See Also:
-
COMPRESSED_FLAG_MASK
private static final int COMPRESSED_FLAG_MASK- See Also:
-
RESERVED_MASK
private static final int RESERVED_MASK- See Also:
-
MAX_BUFFER_SIZE
private static final int MAX_BUFFER_SIZE- See Also:
-
listener
-
maxInboundMessageSize
private int maxInboundMessageSize -
statsTraceCtx
-
transportTracer
-
decompressor
-
fullStreamDecompressor
-
inflatedBuffer
private byte[] inflatedBuffer -
inflatedIndex
private int inflatedIndex -
state
-
requiredLength
private int requiredLength -
compressedFlag
private boolean compressedFlag -
nextFrame
-
unprocessed
-
pendingDeliveries
private long pendingDeliveries -
inDelivery
private boolean inDelivery -
currentMessageSeqNo
private int currentMessageSeqNo -
inboundBodyWireSize
private int inboundBodyWireSize -
closeWhenComplete
private boolean closeWhenComplete -
stopDelivery
private volatile boolean stopDelivery
-
-
Constructor Details
-
MessageDeframer
public MessageDeframer(MessageDeframer.Listener listener, Decompressor decompressor, int maxMessageSize, StatsTraceContext statsTraceCtx, TransportTracer transportTracer) Create a deframer.- Parameters:
listener- listener for deframer events.decompressor- the compression used if a compressed frame is encountered, withNONEmeaning unsupportedmaxMessageSize- the maximum allowed size for received messages.
-
-
Method Details
-
setListener
-
setMaxInboundMessageSize
public void setMaxInboundMessageSize(int messageSize) - Specified by:
setMaxInboundMessageSizein interfaceDeframer
-
setDecompressor
Description copied from interface:DeframerSets the decompressor available to use. The message encoding for the stream comes later in time, and thus will not be available at the time of construction. This should only be set once, since the compression codec cannot change after the headers have been sent.- Specified by:
setDecompressorin interfaceDeframer- Parameters:
decompressor- the decompressing wrapper.
-
setFullStreamDecompressor
Description copied from interface:DeframerSets the decompressor used for full-stream decompression. Full-stream decompression disables any per-message decompressor set byDeframer.setDecompressor(Decompressor).- Specified by:
setFullStreamDecompressorin interfaceDeframer- Parameters:
fullStreamDecompressor- the decompressing wrapper
-
request
public void request(int numMessages) Description copied from interface:DeframerRequests up to the given number of messages from the call. No additional messages will be delivered.If
Deframer.close()has been called, this method will have no effect. -
deframe
Description copied from interface:DeframerAdds the given data to this deframer and attempts delivery to the listener. -
closeWhenComplete
public void closeWhenComplete()Description copied from interface:DeframerClose when any messages currently queued have been requested and delivered.- Specified by:
closeWhenCompletein interfaceDeframer
-
stopDelivery
void stopDelivery()Sets a flag to interrupt delivery of any currently queued messages. This may be invoked outside of the deframing thread, and must be followed by a call toclose()in the deframing thread. Without a subsequent call toclose(), the deframer may hang waiting for additional messages before noticing that thestopDeliveryflag has been set. -
hasPendingDeliveries
boolean hasPendingDeliveries() -
close
public void close()Description copied from interface:DeframerCloses this deframer and frees any resources. After this method is called, additional calls will have no effect. -
isClosed
public boolean isClosed()Indicates whether or not this deframer has been closed. -
isClosedOrScheduledToClose
private boolean isClosedOrScheduledToClose()Returns true if this deframer has already been closed or scheduled to close. -
isStalled
private boolean isStalled() -
deliver
private void deliver()Reads and delivers as many messages to the listener as possible. -
readRequiredBytes
private boolean readRequiredBytes()Attempts to read the required bytes into nextFrame.- Returns:
trueif all of the required bytes have been read.
-
processHeader
private void processHeader()Processes the GRPC compression header which is composed of the compression flag and the outer frame length. -
processBody
private void processBody()Processes the GRPC message body, which depending on frame header flags may be compressed. -
getUncompressedBody
-
getCompressedBody
-