Package io.pravega.shared.protocol.netty
Class CommandEncoder
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelOutboundHandlerAdapter
-
- io.netty.handler.codec.MessageToByteEncoder<I>
-
- io.pravega.shared.protocol.netty.FlushingMessageToByteEncoder<java.lang.Object>
-
- io.pravega.shared.protocol.netty.CommandEncoder
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelOutboundHandler
@NotThreadSafe public class CommandEncoder extends FlushingMessageToByteEncoder<java.lang.Object>
Encodes data so that it can go out onto the wire. For more details about the various commands @see WireCommands. The general encoding for commands is: Type - 4 byte tag Length - 4 byte length Data - Which is obtained by calling the serializer for the specific wire command. Most commands are that simple. For performance Appends however are handled differently. If the channel is free, then the Appends are written in blocks so that the server does not need to decode the contents of the block. The block identifies which stream is appending so that each event does not have to and each each event does not have to be parsed individually. Events inside the block are encoded normally (with their Type and Length). If an event does not fully fit inside of a block it can be wrapped in a PartialEvent command. In this case the fist part of the Event is written as the value of the PartialEvent and the remainder goes in the AppendBlockEnd. The AppendBlockEnd contains metadata about the block that was just appended so that it does not need to be parsed out of individual messages. Notably this includes the event number of the last event in the block, so that it can be acknowledged. If the channel is not free, then each append is enqueued to the session's pending List. This session pending list gets flushed if any of the following conditions is triggered. If the session buffer exceed the threshold (MAX_DATA_SIZE) If the total number of events per session exceeds the threshold (MAX_EVENTS) If the block timeout is triggered. Whenever the block Timeout is triggered, the assigned token to block timeout timer and current value of the token counter are compared; if they are same , then all pending session events are flushed.
-
-
Constructor Summary
Constructors Constructor Description CommandEncoder(java.util.function.Function<java.lang.Long,AppendBatchSizeTracker> appendTracker, MetricNotifier metricNotifier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidencode(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg, io.netty.buffer.ByteBuf out)-
Methods inherited from class io.pravega.shared.protocol.netty.FlushingMessageToByteEncoder
flushRequired, write
-
Methods inherited from class io.netty.handler.codec.MessageToByteEncoder
acceptOutboundMessage, allocateBuffer, isPreferDirect
-
Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharable
-
-
-
-
Constructor Detail
-
CommandEncoder
public CommandEncoder(java.util.function.Function<java.lang.Long,AppendBatchSizeTracker> appendTracker, MetricNotifier metricNotifier)
-
-