T
- type of read request@NotThreadSafe public abstract class AbstractReadHandler<T extends ReadRequest> extends io.netty.channel.ChannelInboundHandlerAdapter
Protocol.ReadRequest
s.
Protocol: Check NettyDataReader
for additional information.
1. Once a read request is received, the handler creates a AbstractReadHandler.PacketReader
which reads
packets from the block worker and pushes them to the buffer.
2. The AbstractReadHandler.PacketReader
pauses if there are too many packets in flight, and resumes if there
is room available.
3. The channel is closed if there is any exception during the packet read/write.
Threading model:
Only two threads are involved at a given point of time: netty I/O thread, packet reader thread.
1. The netty I/O thread accepts the read request, handles write callbacks. If any exception
occurs (e.g. failed to read from netty or write to netty) or the read request is cancelled by
the client, the netty I/O thread notifies the packet reader thread.
2. The packet reader thread keeps reading from the file and writes to netty. Before reading a
new packet, it checks whether there are notifications (e.g. cancel, error), if
there is, handle them properly. See more information about the notifications in the javadoc
of ReadRequestContext
.Modifier and Type | Class and Description |
---|---|
static interface |
AbstractReadHandler.PacketReader<T extends ReadRequest>
A runnable that reads packets and writes them to the channel.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractReadHandler(ExecutorService executorService,
io.netty.channel.Channel channel,
Class<T> requestType,
AbstractReadHandler.PacketReader.Factory<T,? extends AbstractReadHandler.PacketReader<T>> packetReaderFactory)
Creates an instance of
AbstractReadHandler . |
Modifier and Type | Method and Description |
---|---|
protected boolean |
acceptMessage(Object object)
Checks whether this object should be processed by this handler.
|
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object object) |
void |
channelRegistered(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelUnregistered(io.netty.channel.ChannelHandlerContext ctx) |
protected abstract T |
createReadRequest(Protocol.ReadRequest request) |
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
channelActive, channelInactive, channelReadComplete, channelWritabilityChanged, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
protected AbstractReadHandler(ExecutorService executorService, io.netty.channel.Channel channel, Class<T> requestType, AbstractReadHandler.PacketReader.Factory<T,? extends AbstractReadHandler.PacketReader<T>> packetReaderFactory)
AbstractReadHandler
.executorService
- the executor service to run AbstractReadHandler.PacketReader
spublic void channelRegistered(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelRegistered
in interface io.netty.channel.ChannelInboundHandler
channelRegistered
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void channelUnregistered(io.netty.channel.ChannelHandlerContext ctx)
channelUnregistered
in interface io.netty.channel.ChannelInboundHandler
channelUnregistered
in class io.netty.channel.ChannelInboundHandlerAdapter
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object object) throws Exception
channelRead
in interface io.netty.channel.ChannelInboundHandler
channelRead
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
protected boolean acceptMessage(Object object)
object
- the objectprotected abstract T createReadRequest(Protocol.ReadRequest request)
request
- the block read requestCopyright © 2023. All Rights Reserved.