Home / Class/ DiscardClientHandler Class — netty Architecture

DiscardClientHandler Class — netty Architecture

Architecture documentation for the DiscardClientHandler class in DiscardClientHandler.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  27307dbf_b9da_0abd_7637_6d8267cccaf7["DiscardClientHandler"]
  5a463ff0_54da_a947_5d9d_552f1d700947["DiscardClientHandler.java"]
  27307dbf_b9da_0abd_7637_6d8267cccaf7 -->|defined in| 5a463ff0_54da_a947_5d9d_552f1d700947
  a7c2ca48_0a81_94da_c9bd_9a4ba14f9d01["channelActive()"]
  27307dbf_b9da_0abd_7637_6d8267cccaf7 -->|method| a7c2ca48_0a81_94da_c9bd_9a4ba14f9d01
  b342e534_6046_f614_bd33_6fb5fff0a9ec["channelInactive()"]
  27307dbf_b9da_0abd_7637_6d8267cccaf7 -->|method| b342e534_6046_f614_bd33_6fb5fff0a9ec
  1b4c2851_38af_ab6d_ecbf_548f17dcf871["channelRead0()"]
  27307dbf_b9da_0abd_7637_6d8267cccaf7 -->|method| 1b4c2851_38af_ab6d_ecbf_548f17dcf871
  a6aba89e_dba7_87fe_a02f_1aa2ed3e62fb["exceptionCaught()"]
  27307dbf_b9da_0abd_7637_6d8267cccaf7 -->|method| a6aba89e_dba7_87fe_a02f_1aa2ed3e62fb
  4595eaf3_55a6_5788_9f24_3d3c51f2bfe0["generateTraffic()"]
  27307dbf_b9da_0abd_7637_6d8267cccaf7 -->|method| 4595eaf3_55a6_5788_9f24_3d3c51f2bfe0

Relationship Graph

Source Code

example/src/main/java/io/netty/example/discard/DiscardClientHandler.java lines 26–75

public class DiscardClientHandler extends SimpleChannelInboundHandler<Object> {

    private ByteBuf content;
    private ChannelHandlerContext ctx;

    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        this.ctx = ctx;

        // Initialize the message.
        content = ctx.alloc().directBuffer(DiscardClient.SIZE).writeZero(DiscardClient.SIZE);

        // Send the initial messages.
        generateTraffic();
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) {
        content.release();
    }

    @Override
    public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        // Server is supposed to send nothing, but if it sends something, discard it.
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        // Close the connection when an exception is raised.
        cause.printStackTrace();
        ctx.close();
    }

    long counter;

    private void generateTraffic() {
        // Flush the outbound buffer to the socket.
        // Once flushed, generate the same amount of traffic again.
        ctx.writeAndFlush(content.retainedDuplicate()).addListener(trafficGenerator);
    }

    private final ChannelFutureListener trafficGenerator = future -> {
        if (future.isSuccess()) {
            generateTraffic();
        } else {
            future.cause().printStackTrace();
            future.channel().close();
        }
    };
}

Frequently Asked Questions

What is the DiscardClientHandler class?
DiscardClientHandler is a class in the netty codebase, defined in example/src/main/java/io/netty/example/discard/DiscardClientHandler.java.
Where is DiscardClientHandler defined?
DiscardClientHandler is defined in example/src/main/java/io/netty/example/discard/DiscardClientHandler.java at line 26.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free