Class ArmeriaMessageDeframer
java.lang.Object
com.linecorp.armeria.common.grpc.protocol.ArmeriaMessageDeframer
- All Implemented Interfaces:
AutoCloseable
@UnstableApi public class ArmeriaMessageDeframer extends Object implements AutoCloseable
A deframer of messages transported in the gRPC wire format. See
gRPC Wire Format
for more detail on the protocol.
The logic has been mostly copied from io.grpc.internal.MessageDeframer
, while removing the buffer
abstraction in favor of using ByteBuf
directly, and allowing the delivery of uncompressed frames as
a ByteBuf
to optimize message parsing.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ArmeriaMessageDeframer.DeframedMessage
A deframed message.static interface
ArmeriaMessageDeframer.Listener
A listener of deframing events. -
Field Summary
Fields Modifier and Type Field Description static int
NO_MAX_INBOUND_MESSAGE_SIZE
-
Constructor Summary
Constructors Constructor Description ArmeriaMessageDeframer(ArmeriaMessageDeframer.Listener listener, int maxMessageSizeBytes, ByteBufAllocator alloc)
Construct anArmeriaMessageDeframer
for reading messages out of a gRPC request or response. -
Method Summary
Modifier and Type Method Description void
close()
Closes this deframer and frees any resources.void
closeWhenComplete()
Requests closing this deframer when any messages currently queued have been requested and delivered.ArmeriaMessageDeframer
decompressor(Decompressor decompressor)
Sets theDecompressor
for this deframer.void
deframe(HttpData data, boolean endOfStream)
Adds the given data to this deframer and attempts delivery to the listener.boolean
isClosed()
Indicates whether or not this deframer has been closed.boolean
isClosing()
Indicates whether or not this deframer is closing.boolean
isStalled()
Indicates whether delivery is currently stalled, pending receipt of more data.void
request(int numMessages)
Requests up to the given number of messages from the call to be delivered toArmeriaMessageDeframer.Listener.messageRead(DeframedMessage)
.
-
Field Details
-
NO_MAX_INBOUND_MESSAGE_SIZE
public static final int NO_MAX_INBOUND_MESSAGE_SIZE- See Also:
- Constant Field Values
-
-
Constructor Details
-
ArmeriaMessageDeframer
public ArmeriaMessageDeframer(ArmeriaMessageDeframer.Listener listener, int maxMessageSizeBytes, ByteBufAllocator alloc)Construct anArmeriaMessageDeframer
for reading messages out of a gRPC request or response.
-
-
Method Details
-
request
public void request(int numMessages)Requests up to the given number of messages from the call to be delivered toArmeriaMessageDeframer.Listener.messageRead(DeframedMessage)
. No additional messages will be delivered.If
close()
has been called, this method will have no effect.- Parameters:
numMessages
- the requested number of messages to be delivered to the listener.
-
isStalled
public boolean isStalled()Indicates whether delivery is currently stalled, pending receipt of more data. This means that no additional data can be delivered to the application. -
deframe
Adds the given data to this deframer and attempts delivery to the listener.- Parameters:
data
- the raw data read from the remote endpoint. Must be non-null.endOfStream
- iftrue
, indicates thatdata
is the end of the stream from the remote endpoint. End of stream should not be used in the event of a transport error, such as a stream reset.- Throws:
IllegalStateException
- ifclose()
has been called previously or if this method has previously been called withendOfStream=true
.
-
closeWhenComplete
public void closeWhenComplete()Requests closing this deframer when any messages currently queued have been requested and delivered. -
close
public void close()Closes this deframer and frees any resources. After this method is called, additional calls will have no effect.- Specified by:
close
in interfaceAutoCloseable
-
isClosing
public boolean isClosing()Indicates whether or not this deframer is closing. -
isClosed
public boolean isClosed()Indicates whether or not this deframer has been closed. -
decompressor
Sets theDecompressor
for this deframer.
-