How do events and data propagate through the various channel handlers in a channel pipeline?

31 views
Skip to first unread message

L_DisplayName

unread,
Jul 20, 2016, 2:33:49 PM7/20/16
to Netty discussions
 

I am implementing a client that will receive a single file from the server. To keep it simple, I am assuming the client already knows the name of the file it is to receive. So the client will first receive a file header followed by actual file contents. The header is simple, just the length of the file encapsulated as an 8 byte long.


Overall Sequence Diagram
Server --> Length of File --> Client
Server --> FileContents --> Client


I add the following channel handlers to my client’s channel handler pipeline:


p.addLast(new msgToLongDecoder(), chunkedReadHandler());

where msgToLongDecoder extends ByteToMessageDecoder and ReadFileHandler ReadFileHandler extends SimpleChannelInboundHandler


New Overall Sequence Diagram

Server --> Length of File --> Client(MsgToLongDecoder ReadFileHandler)
Server --> FileContents --> Client(MsgToLongDecoderReadFileHandler)


After the client receives the file length (encapsulated by raw bytes) the client first uses the MsgToLongDecoder to decode the bytes ( into the file length (type Long).

Questions

  1. After decoding, is the file length automatically pushed to the next handler in the channel pipeline which will be the ReadFileHandler? if so, what method in the netty code would automatically push the file Length to the next handler?
  2. Also do I have to manually within the code handle this case, meaning within the readFileHandler methos I will have to check to see if the event/msg is an instance of ByteBuf () as in (if message instanceof ByteBuf)?
  3. When the server sends the actual file contents, based on the channel pipeline, will the client’s msgToLongDecoder first receive the file contents (ByteBuf)? if so, does the msgToLongDecoder automatically ignore the stream and pushes it to the next channelHandler within the pipeline which is the ReadFileHandler? Or do I have to manually do this?

Also, how can the ReadFileHandler accept and process ChunkedInput? The Netty API specifies that ChunkedInput is a data stream of indefinite length which is consumed by ChunkedWriteHandler?

Reply all
Reply to author
Forward
0 new messages