Class ArmeriaMessageDeframer
- java.lang.Object
-
- com.linecorp.armeria.common.grpc.protocol.ArmeriaMessageDeframer
-
- All Implemented Interfaces:
AutoCloseable
public class ArmeriaMessageDeframer extends Object implements AutoCloseable
A deframer of messages transported in the gRPC wire format. See gRPC Wire Protocol 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 usingByteBufdirectly, and allowing the delivery of uncompressed frames as aByteBufto optimize message parsing.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classArmeriaMessageDeframer.ByteBufOrStreamA deframed message.static interfaceArmeriaMessageDeframer.ListenerA listener of deframing events.
-
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
All Methods Instance Methods Concrete Methods 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(ByteBufOrStream).
-
-
-
Constructor Detail
-
ArmeriaMessageDeframer
public ArmeriaMessageDeframer(ArmeriaMessageDeframer.Listener listener, int maxMessageSizeBytes, ByteBufAllocator alloc)
Construct anArmeriaMessageDeframerfor reading messages out of a gRPC request or response.
-
-
Method Detail
-
request
public void request(int numMessages)
Requests up to the given number of messages from the call to be delivered toArmeriaMessageDeframer.Listener.messageRead(ByteBufOrStream). 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
public ArmeriaMessageDeframer decompressor(@Nullable Decompressor decompressor)
Sets theDecompressorfor this deframer.
-
-