Class StopAndWaitArqHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler
It also updates the writability of the associated Channel, so that the pending write operations are also considered to determine the writability.
This handler changes the behavior of the Promises returned by
ChannelOutboundInvoker.write(Object): The promise is not complemented
until the message's recipient has acknowledged arrival of the message. If you abort the promise,
this handler will discard the message.
Keep in mind that this ARQ protocol is originally intended to be used in connection-oriented communication. Therefore, it may happen (e.g. due to a restart of one of the two peers) that the expected sequence number of the next message is no longer synchronized. This leads to the loss of the first message. To avoid this, a NOOP message should be sent once at the beginning of the communication.
This handler should be used together with ByteToStopAndWaitArqDataCodec and StopAndWaitArqCodec.
ChannelPipelinep = ...; ... p.addLast("arq_codec", newStopAndWaitArqCodec()); p.addLast("arq_handler", newStopAndWaitArqHandler(500, 100)); p.addLast("buf_codec", newByteToStopAndWaitArqDataCodec()); ... p.addLast("handler", new HttpRequestHandler());
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionStopAndWaitArqHandler(int retryTimeout) StopAndWaitArqHandler(int retryTimeout, boolean expectedInboundSequenceNo) -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) voidflush(io.netty.channel.ChannelHandlerContext ctx) voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx) voidsetExpectedInboundSequenceNo(boolean expectedInboundSequenceNo) Sets the sequence of the next inboundStopAndWaitArqDatamessage.voidsetRetryTimeout(int retryTimeout) Defines how long to wait for aStopAndWaitArqAckmessage before resending it.voidwrite(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, readMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerRemoved
-
Constructor Details
-
StopAndWaitArqHandler
public StopAndWaitArqHandler(int retryTimeout, boolean expectedInboundSequenceNo) - Parameters:
retryTimeout- seesetRetryTimeout(int)expectedInboundSequenceNo- seesetExpectedInboundSequenceNo(boolean)
-
StopAndWaitArqHandler
public StopAndWaitArqHandler(int retryTimeout) - Parameters:
retryTimeout- seesetRetryTimeout(int)
-
-
Method Details
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) - Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) - Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter
-
channelRead
- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) - Specified by:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein classio.netty.channel.ChannelDuplexHandler
-
flush
- Specified by:
flushin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
flushin classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
setRetryTimeout
public void setRetryTimeout(int retryTimeout) Defines how long to wait for aStopAndWaitArqAckmessage before resending it.StopAndWaitArqDatamessage is sent again. This timeout should not be smaller than the round trip time of the connection.- Parameters:
retryTimeout- time in ms before theStopAndWaitArqDatamessage is sent again
-
setExpectedInboundSequenceNo
public void setExpectedInboundSequenceNo(boolean expectedInboundSequenceNo) Sets the sequence of the next inboundStopAndWaitArqDatamessage. This method can be used to manually synchronize the sequence number of the sender and receiver.- Parameters:
expectedInboundSequenceNo- expected sequence number of the next inboundStopAndWaitArqDatamessage
-