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 classArmeriaMessageDeframer.DeframedMessageA deframed message.static interfaceArmeriaMessageDeframer.ListenerA listener of deframing events. -
Field Summary
Fields Modifier and Type Field Description static intNO_MAX_INBOUND_MESSAGE_SIZE -
Constructor Summary
Constructors Constructor Description ArmeriaMessageDeframer(ArmeriaMessageDeframer.Listener listener, int maxMessageSizeBytes, ByteBufAllocator alloc)Construct anArmeriaMessageDeframerfor reading messages out of a gRPC request or response. -
Method Summary
Modifier and Type Method Description voidclose()Closes this deframer and frees any resources.voidcloseWhenComplete()Requests closing this deframer when any messages currently queued have been requested and delivered.ArmeriaMessageDeframerdecompressor(Decompressor decompressor)Sets theDecompressorfor this deframer.voiddeframe(com.linecorp.armeria.common.HttpData data, boolean endOfStream)Adds the given data to this deframer and attempts delivery to the listener.booleanisClosed()Indicates whether or not this deframer has been closed.booleanisStalled()Indicates whether delivery is currently stalled, pending receipt of more data.voidrequest(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 anArmeriaMessageDeframerfor 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
public void deframe(com.linecorp.armeria.common.HttpData data, boolean endOfStream)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 thatdatais 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:
closein interfaceAutoCloseable
-
isClosed
public boolean isClosed()Indicates whether or not this deframer has been closed. -
decompressor
Sets theDecompressorfor this deframer.
-