Home / Class/ SuccessTestHandler Class — netty Architecture

SuccessTestHandler Class — netty Architecture

Architecture documentation for the SuccessTestHandler class in ProxyHandlerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  c8c10620_53ef_6bba_6752_82627318b2e6["SuccessTestHandler"]
  8ee69b4d_9955_829a_96d0_8c943277a68d["ProxyHandlerTest.java"]
  c8c10620_53ef_6bba_6752_82627318b2e6 -->|defined in| 8ee69b4d_9955_829a_96d0_8c943277a68d
  0598b260_b04e_542f_5c23_3c63a0ab3bfe["readIfNeeded()"]
  c8c10620_53ef_6bba_6752_82627318b2e6 -->|method| 0598b260_b04e_542f_5c23_3c63a0ab3bfe
  6318373a_af7a_d643_7bf6_992e96d0d650["channelActive()"]
  c8c10620_53ef_6bba_6752_82627318b2e6 -->|method| 6318373a_af7a_d643_7bf6_992e96d0d650
  3d5310ff_7966_4f35_3991_3dd4fbfd728c["userEventTriggered()"]
  c8c10620_53ef_6bba_6752_82627318b2e6 -->|method| 3d5310ff_7966_4f35_3991_3dd4fbfd728c
  92c96ce3_318d_d184_c1d0_3c03ba4fcf72["channelRead0()"]
  c8c10620_53ef_6bba_6752_82627318b2e6 -->|method| 92c96ce3_318d_d184_c1d0_3c03ba4fcf72
  bd5b24ca_360a_7428_64c4_f0a2778626ea["exceptionCaught()"]
  c8c10620_53ef_6bba_6752_82627318b2e6 -->|method| bd5b24ca_360a_7428_64c4_f0a2778626ea

Relationship Graph

Source Code

handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java lines 510–557

    private static final class SuccessTestHandler extends SimpleChannelInboundHandler<Object> {

        final Queue<String> received = new LinkedBlockingQueue<String>();
        final Queue<Throwable> exceptions = new LinkedBlockingQueue<Throwable>();
        volatile int eventCount;

        private static void readIfNeeded(ChannelHandlerContext ctx) {
            if (!ctx.channel().config().isAutoRead()) {
                ctx.read();
            }
        }

        @Override
        public void channelActive(ChannelHandlerContext ctx) throws Exception {
            ctx.writeAndFlush(Unpooled.copiedBuffer("A\n", CharsetUtil.US_ASCII));
            readIfNeeded(ctx);
        }

        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
            if (evt instanceof ProxyConnectionEvent) {
                eventCount ++;

                if (eventCount == 1) {
                    // Note that ProxyConnectionEvent can be triggered multiple times when there are multiple
                    // ProxyHandlers in the pipeline.  Therefore, we send the 'B' message only on the first event.
                    ctx.writeAndFlush(Unpooled.copiedBuffer("B\n", CharsetUtil.US_ASCII));
                }
                readIfNeeded(ctx);
            }
        }

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
            String str = ((ByteBuf) msg).toString(CharsetUtil.US_ASCII);
            received.add(str);
            if ("2".equals(str)) {
                ctx.writeAndFlush(Unpooled.copiedBuffer("C\n", CharsetUtil.US_ASCII));
            }
            readIfNeeded(ctx);
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            exceptions.add(cause);
            ctx.close();
        }
    }

Frequently Asked Questions

What is the SuccessTestHandler class?
SuccessTestHandler is a class in the netty codebase, defined in handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java.
Where is SuccessTestHandler defined?
SuccessTestHandler is defined in handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java at line 510.

Analyze Your Own Codebase

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

Try Supermodel Free