Home / Class/ ClientHandler Class — netty Architecture

ClientHandler Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  7e6cf114_b36a_90aa_093d_d8e5d1c3e413["ClientHandler"]
  bdd08ecf_67ca_c093_7826_8944cb8a89d6["TrafficShapingHandlerTest.java"]
  7e6cf114_b36a_90aa_093d_d8e5d1c3e413 -->|defined in| bdd08ecf_67ca_c093_7826_8944cb8a89d6
  d21bb16a_f424_d60b_0ea4_7b015c302b29["ClientHandler()"]
  7e6cf114_b36a_90aa_093d_d8e5d1c3e413 -->|method| d21bb16a_f424_d60b_0ea4_7b015c302b29
  4fa81c36_2634_e3dd_8a7a_50869a6d8cf7["channelActive()"]
  7e6cf114_b36a_90aa_093d_d8e5d1c3e413 -->|method| 4fa81c36_2634_e3dd_8a7a_50869a6d8cf7
  95e1288e_b36b_7855_418d_399a527d5032["channelRead0()"]
  7e6cf114_b36a_90aa_093d_d8e5d1c3e413 -->|method| 95e1288e_b36b_7855_418d_399a527d5032
  95e2723c_5787_0f0f_2e8f_0aea1fb6330f["exceptionCaught()"]
  7e6cf114_b36a_90aa_093d_d8e5d1c3e413 -->|method| 95e2723c_5787_0f0f_2e8f_0aea1fb6330f

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/TrafficShapingHandlerTest.java lines 440–508

    private static class ClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
        volatile Channel channel;
        final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
        volatile int step;
        // first message will always be validated
        private long currentLastTime = TrafficCounter.milliSecondFromNano();
        private final long[] minimalWaitBetween;
        private final int[] multipleMessage;
        private final int[] autoRead;
        final Promise<Boolean> promise;

        ClientHandler(Promise<Boolean> promise, long[] minimalWaitBetween, int[] multipleMessage,
                      int[] autoRead) {
            this.minimalWaitBetween = minimalWaitBetween;
            this.multipleMessage = Arrays.copyOf(multipleMessage, multipleMessage.length);
            this.promise = promise;
            this.autoRead = autoRead;
        }

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

        @Override
        public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
            long lastTimestamp = 0;
            loggerClient.debug("Step: " + step + " Read: " + in.readableBytes() / 8 + " blocks");
            while (in.isReadable()) {
                lastTimestamp = in.readLong();
                multipleMessage[step]--;
            }
            if (multipleMessage[step] > 0) {
                // still some message to get
                return;
            }
            long minimalWait = minimalWaitBetween != null? minimalWaitBetween[step] : 0;
            int ar = 0;
            if (autoRead != null) {
                if (step > 0 && autoRead[step - 1] != 0) {
                    ar = autoRead[step - 1];
                }
            }
            loggerClient.info("Step: " + step + " Interval: " + (lastTimestamp - currentLastTime) + " compareTo "
                              + minimalWait + " (" + ar + ')');
            assertTrue(lastTimestamp - currentLastTime >= minimalWait,
                    "The interval of time is incorrect:" + (lastTimestamp - currentLastTime) + " not> " + minimalWait);
            currentLastTime = lastTimestamp;
            step++;
            if (multipleMessage.length > step) {
                int nb = multipleMessage[step];
                for (int i = 0; i < nb; i++) {
                    channel.write(channel.alloc().buffer().writeBytes(data));
                }
                channel.flush();
            } else {
                promise.setSuccess(true);
            }
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            if (exception.compareAndSet(null, cause)) {
                cause.printStackTrace();
                promise.setFailure(cause);
                ctx.close();
            }
        }
    }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free