Home / Class/ ServerHandler Class — netty Architecture

ServerHandler Class — netty Architecture

Architecture documentation for the ServerHandler class in TrafficShapingHandlerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  a564e1e7_3954_c4e6_4213_33ab700f033a["ServerHandler"]
  bdd08ecf_67ca_c093_7826_8944cb8a89d6["TrafficShapingHandlerTest.java"]
  a564e1e7_3954_c4e6_4213_33ab700f033a -->|defined in| bdd08ecf_67ca_c093_7826_8944cb8a89d6
  0c95a3ac_3a8f_22d5_5d59_ae6ea1b0d0aa["ServerHandler()"]
  a564e1e7_3954_c4e6_4213_33ab700f033a -->|method| 0c95a3ac_3a8f_22d5_5d59_ae6ea1b0d0aa
  6db596a8_2029_33ce_86ec_bb1ce57dc344["channelActive()"]
  a564e1e7_3954_c4e6_4213_33ab700f033a -->|method| 6db596a8_2029_33ce_86ec_bb1ce57dc344
  3f6bd014_d001_c3a0_8233_056f4ad262a7["channelRead0()"]
  a564e1e7_3954_c4e6_4213_33ab700f033a -->|method| 3f6bd014_d001_c3a0_8233_056f4ad262a7
  01ef637b_bff4_995e_0f39_6616a588b6f2["exceptionCaught()"]
  a564e1e7_3954_c4e6_4213_33ab700f033a -->|method| 01ef637b_bff4_995e_0f39_6616a588b6f2

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/TrafficShapingHandlerTest.java lines 510–603

    private static class ServerHandler extends SimpleChannelInboundHandler<ByteBuf> {
        private final int[] autoRead;
        private final int[] multipleMessage;
        volatile Channel channel;
        volatile int step;
        final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();

        ServerHandler(int[] autoRead, int[] multipleMessage) {
            this.autoRead = autoRead;
            this.multipleMessage = Arrays.copyOf(multipleMessage, multipleMessage.length);
        }

        @Override
        public void channelActive(ChannelHandlerContext ctx) throws Exception {
            channel = ctx.channel();
        }

        @Override
        public void channelRead0(final ChannelHandlerContext ctx, ByteBuf in) throws Exception {
            byte[] actual = new byte[in.readableBytes()];
            int nb = actual.length / messageSize;
            loggerServer.info("Step: " + step + " Read: " + nb + " blocks");
            in.readBytes(actual);
            long timestamp = TrafficCounter.milliSecondFromNano();
            int isAutoRead = 0;
            int laststep = step;
            for (int i = 0; i < nb; i++) {
                multipleMessage[step]--;
                if (multipleMessage[step] == 0) {
                    // setAutoRead test
                    if (autoRead != null) {
                        isAutoRead = autoRead[step];
                    }
                    step++;
                }
            }
            if (laststep != step) {
                // setAutoRead test
                if (autoRead != null && isAutoRead != 2) {
                    if (isAutoRead != 0) {
                        loggerServer.info("Step: " + step + " Set AutoRead: " + (isAutoRead > 0));
                        channel.config().setAutoRead(isAutoRead > 0);
                    } else {
                        loggerServer.info("Step: " + step + " AutoRead: NO");
                    }
                }
            }
            Thread.sleep(10);
            loggerServer.debug("Step: " + step + " Write: " + nb);
            for (int i = 0; i < nb; i++) {
                channel.write(Unpooled.copyLong(timestamp));
            }
            channel.flush();
            if (laststep != step) {
                // setAutoRead test
                if (isAutoRead != 0) {
                    if (isAutoRead < 0) {
                        final int exactStep = step;
                        long wait = isAutoRead == -1? minimalms : stepms + minimalms;
                        if (isAutoRead == -3) {
                            wait = stepms * 3;
                        }
                        executor.schedule(new Runnable() {
                            @Override
                            public void run() {
                                loggerServer.info("Step: " + exactStep + " Reset AutoRead");
                                channel.config().setAutoRead(true);
                            }
                        }, wait, TimeUnit.MILLISECONDS);
                    } else {
                        if (isAutoRead > 1) {
                            loggerServer.debug("Step: " + step + " Will Set AutoRead: True");
                            final int exactStep = step;
                            executor.schedule(new Runnable() {
                                @Override
                                public void run() {
                                    loggerServer.info("Step: " + exactStep + " Set AutoRead: True");
                                    channel.config().setAutoRead(true);
                                }
                            }, stepms + minimalms, TimeUnit.MILLISECONDS);
                        }

Frequently Asked Questions

What is the ServerHandler class?
ServerHandler is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/TrafficShapingHandlerTest.java.
Where is ServerHandler defined?
ServerHandler is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/TrafficShapingHandlerTest.java at line 510.

Analyze Your Own Codebase

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

Try Supermodel Free