Home / Class/ TerminalHandler Class — netty Architecture

TerminalHandler Class — netty Architecture

Architecture documentation for the TerminalHandler class in ProxyServer.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  f2dc5bef_5555_e698_c0cb_7f1263aedb4d["TerminalHandler"]
  db43fe47_37b6_43cd_123c_8899d4fb6e75["ProxyServer.java"]
  f2dc5bef_5555_e698_c0cb_7f1263aedb4d -->|defined in| db43fe47_37b6_43cd_123c_8899d4fb6e75
  d35cb1df_dc40_6945_08a5_a25b55513228["channelRead0()"]
  f2dc5bef_5555_e698_c0cb_7f1263aedb4d -->|method| d35cb1df_dc40_6945_08a5_a25b55513228
  221bd122_a42a_6d66_cdfe_3d2578d8a303["handleProxyProtocol()"]
  f2dc5bef_5555_e698_c0cb_7f1263aedb4d -->|method| 221bd122_a42a_6d66_cdfe_3d2578d8a303
  880e159f_ea0a_5b39_6044_35166c009715["channelReadComplete()"]
  f2dc5bef_5555_e698_c0cb_7f1263aedb4d -->|method| 880e159f_ea0a_5b39_6044_35166c009715
  428ec2e3_a038_7466_3e2c_ee83c0b7eb68["exceptionCaught()"]
  f2dc5bef_5555_e698_c0cb_7f1263aedb4d -->|method| 428ec2e3_a038_7466_3e2c_ee83c0b7eb68

Relationship Graph

Source Code

handler-proxy/src/test/java/io/netty/handler/proxy/ProxyServer.java lines 263–302

    protected abstract class TerminalHandler extends SimpleChannelInboundHandler<Object> {

        private boolean finished;

        @Override
        protected final void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
            if (finished) {
                String str = ((ByteBuf) msg).toString(CharsetUtil.US_ASCII);
                if ("A\n".equals(str)) {
                    ctx.write(Unpooled.copiedBuffer("1\n", CharsetUtil.US_ASCII));
                } else if ("B\n".equals(str)) {
                    ctx.write(Unpooled.copiedBuffer("2\n", CharsetUtil.US_ASCII));
                } else if ("C\n".equals(str)) {
                    ctx.write(Unpooled.copiedBuffer("3\n", CharsetUtil.US_ASCII))
                       .addListener(ChannelFutureListener.CLOSE);
                } else {
                    throw new IllegalStateException("unexpected message: " + str);
                }
                return;
            }

            boolean finished = handleProxyProtocol(ctx, msg);
            if (finished) {
                this.finished = finished;
            }
        }

        protected abstract boolean handleProxyProtocol(ChannelHandlerContext ctx, Object msg) throws Exception;

        @Override
        public final void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
            ctx.flush();
        }

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

Frequently Asked Questions

What is the TerminalHandler class?
TerminalHandler is a class in the netty codebase, defined in handler-proxy/src/test/java/io/netty/handler/proxy/ProxyServer.java.
Where is TerminalHandler defined?
TerminalHandler is defined in handler-proxy/src/test/java/io/netty/handler/proxy/ProxyServer.java at line 263.

Analyze Your Own Codebase

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

Try Supermodel Free