4

I am new to netty and trying to understand how the channel future for writeAndFlush works. Consider the following code running on a netty client:

final ChannelFuture writeFuture = abacaChannel.writeAndFlush("Test");
writeFuture.addListener(new ChannelFutureListener() {
    @Override
    public void operationComplete(ChannelFuture future) throws Exception {
        if (writeFuture.isSuccess()) {
            LOGGER.debug("Write successful");
        } else {
            LOGGER.error("Error writing message to Abaca host");
        }
    }
});

When does this writeFuture operationComplete callback executed?

  1. After netty hands over the data to the OS send buffers (or)

  2. After the OS writes the data to the network socket. (or)

  3. After this data is actually received by the server.

TIA

mariner
  • 930
  • 3
  • 16
  • 25

1 Answers1

4
1. After netty hands over the data to the OS send buffers (or)

Listener will be notified after data is removed from ChannelOutboundBuffer (netty's send buffer)

louxiu
  • 2,830
  • 3
  • 28
  • 42
  • @loxiu - so there is no notification if the data is received by the server? What if the receiver is blocked? How can I detect that? – tsar2512 Mar 12 '17 at 16:16
  • Yes, no notification(or application level ack). If the receiver is blocked then sender's os buffer will full, then netty cant't send data and channel's writable will become false. – louxiu Mar 13 '17 at 02:07
  • Tcp send from the sender is generally throttled(slowed down) if receiver is slow or blocked. Does this impact netty sends as well? Or does the channel simply become not writable after sending data as fast as possible? – tsar2512 Mar 13 '17 at 03:05
  • I have added a SO question for some clarification perhaphs you could add answers there? http://stackoverflow.com/questions/42750075/understanding-netty-channel-buffers-and-watermarks – tsar2512 Mar 13 '17 at 03:07
  • @louxiu -- For every wirteAndFlush() operation we need to create and add a listener at runtime, is it too expensive? How to understand this? – zipper Sep 16 '21 at 07:43
  • @zipper I think a listener just for count is not expensive. Anyway you may need to profile it. – louxiu Sep 23 '21 at 03:04