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 Promise
s 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
.
ChannelPipeline
p = ...; ... 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
ConstructorDescriptionStopAndWaitArqHandler
(int retryTimeout) StopAndWaitArqHandler
(int retryTimeout, boolean expectedInboundSequenceNo) -
Method Summary
Modifier and TypeMethodDescriptionvoid
channelInactive
(io.netty.channel.ChannelHandlerContext ctx) void
channelRead
(io.netty.channel.ChannelHandlerContext ctx, Object msg) void
flush
(io.netty.channel.ChannelHandlerContext ctx) void
handlerAdded
(io.netty.channel.ChannelHandlerContext ctx) void
setExpectedInboundSequenceNo
(boolean expectedInboundSequenceNo) Sets the sequence of the next inboundStopAndWaitArqData
message.void
setRetryTimeout
(int retryTimeout) Defines how long to wait for aStopAndWaitArqAck
message before resending it.void
write
(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, read
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerRemoved, isSharable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:
handlerAdded
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerAdded
in classio.netty.channel.ChannelHandlerAdapter
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) - Specified by:
channelInactive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelInactive
in classio.netty.channel.ChannelInboundHandlerAdapter
-
channelRead
- Specified by:
channelRead
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelRead
in classio.netty.channel.ChannelInboundHandlerAdapter
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) - Specified by:
write
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
write
in classio.netty.channel.ChannelDuplexHandler
-
flush
- Specified by:
flush
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
flush
in classio.netty.channel.ChannelDuplexHandler
- Throws:
Exception
-
setRetryTimeout
public void setRetryTimeout(int retryTimeout) Defines how long to wait for aStopAndWaitArqAck
message before resending it.StopAndWaitArqData
message is sent again. This timeout should not be smaller than the round trip time of the connection.- Parameters:
retryTimeout
- time in ms before theStopAndWaitArqData
message is sent again
-
setExpectedInboundSequenceNo
public void setExpectedInboundSequenceNo(boolean expectedInboundSequenceNo) Sets the sequence of the next inboundStopAndWaitArqData
message. This method can be used to manually synchronize the sequence number of the sender and receiver.- Parameters:
expectedInboundSequenceNo
- expected sequence number of the next inboundStopAndWaitArqData
message
-