Class GoBackNArqSenderHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
org.drasyl.handler.arq.gobackn.GoBackNArqSenderHandler
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public class GoBackNArqSenderHandler extends io.netty.channel.ChannelDuplexHandler
Performs the Go-Back-N ARQ sender protocol.

It also updates the writability of the associated Channel. This update allows pending write operations 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. Aborting a promise for a message that is waiting to be acknowledged can cause the sender and receiver to no longer have the same message sequence. This occurs when the acknowledgement of a message is lost and the promise of that message was manually aborted.

This handler should be used together with GoBackNArqCodec, ByteToGoBackNArqDataCodec and GoBackNArqSenderHandler.

  ChannelPipeline p = ...;
  ...
  p.addLast("arq_codec", new GoBackNArqCodec());
  p.addLast("arq_snd_handler", new GoBackNArqSenderHandler(150, Duration.ofMillis(100)));
  p.addLast("arg_rec_handler", new GoBackNArqReceiverHandler(Duration.ofMills(100).dividedBy(10)));
  p.addLast("buf_codec", new ByteToGoBackNArqDataCodec());
  ...
  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

    Constructors
    Constructor
    Description
    GoBackNArqSenderHandler(int windowSize, Duration retryTimeout)
    Creates a new GoBackNArqHandler.
    GoBackNArqSenderHandler(int windowSize, Duration retryTimeout, boolean windowShouldAffectWritability)
    Creates a new GoBackNArqHandler.
    GoBackNArqSenderHandler(int windowSize, Duration retryTimeout, UnsignedInteger base, UnsignedInteger nextSeqNum, boolean windowShouldAffectWritability)
    Creates a new GoBackNArqHandler.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelInactive(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
     
    void
    handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
     
    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, flush, 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

    • GoBackNArqSenderHandler

      public GoBackNArqSenderHandler(int windowSize, Duration retryTimeout, UnsignedInteger base, UnsignedInteger nextSeqNum, boolean windowShouldAffectWritability)
      Creates a new GoBackNArqHandler.

      When specifying the window size, you should take the MTU in bytes, the maximum link capacity (LC) in bytes, and the RTT in ms into account. For example, a good window size could be (LC * RTT) / (MTU * 2000).

      The retry timeout should be at least twice as large as the time needed to transfer a single frame.

      Parameters:
      windowSize - the window size
      retryTimeout - the retry timeout
      base - the first unacknowledged sequence number
      nextSeqNum - the next sequence number, that was not already send
      windowShouldAffectWritability - if the window should be added to the channels pending bytes
    • GoBackNArqSenderHandler

      public GoBackNArqSenderHandler(int windowSize, Duration retryTimeout)
      Creates a new GoBackNArqHandler.

      When specifying the window size, you should take the MTU, the maximum link capacity (LC), and the RTT into account. For example, a good window size could be (LC*RTT) / (1000*MTU).

      The retry timeout should be at least twice as large as the time needed to transfer a single window.

      Parameters:
      windowSize - the window size
      retryTimeout - the retry timeout
    • GoBackNArqSenderHandler

      public GoBackNArqSenderHandler(int windowSize, Duration retryTimeout, boolean windowShouldAffectWritability)
      Creates a new GoBackNArqHandler.

      When specifying the window size, you should take the MTU, the maximum link capacity (LC), and the RTT into account. For example, a good window size could be (LC*RTT) / (1000*MTU).

      The retry timeout should be at least twice as large as the time needed to transfer a single window.

      Parameters:
      windowSize - the window size
      retryTimeout - the retry timeout
      windowShouldAffectWritability - if the window should be added to the channels pending bytes
  • Method Details

    • handlerAdded

      public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
      Specified by:
      handlerAdded in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerAdded in class io.netty.channel.ChannelHandlerAdapter
    • channelInactive

      public void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
      Specified by:
      channelInactive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelInactive in class io.netty.channel.ChannelInboundHandlerAdapter
    • channelRead

      public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
      Specified by:
      channelRead in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
    • write

      public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)
      Specified by:
      write in interface io.netty.channel.ChannelOutboundHandler
      Overrides:
      write in class io.netty.channel.ChannelDuplexHandler