Home / Function/ handlerAdded() — netty Function Reference

handlerAdded() — netty Function Reference

Architecture documentation for the handlerAdded() function in CombinedChannelDuplexHandler.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  3922501c_89d9_9315_87b2_3d95db47dd42["handlerAdded()"]
  d9e90966_2763_e0d8_7a2c_c3339937a5a7["CombinedChannelDuplexHandler"]
  3922501c_89d9_9315_87b2_3d95db47dd42 -->|defined in| d9e90966_2763_e0d8_7a2c_c3339937a5a7
  26381b7a_54f3_93c6_3580_82181da58ae7["init()"]
  3922501c_89d9_9315_87b2_3d95db47dd42 -->|calls| 26381b7a_54f3_93c6_3580_82181da58ae7
  3e2d2ea2_85bb_3b7c_3ecf_cbe54807d561["DelegatingChannelHandlerContext()"]
  3922501c_89d9_9315_87b2_3d95db47dd42 -->|calls| 3e2d2ea2_85bb_3b7c_3ecf_cbe54807d561
  34f36d79_45c9_b7bb_b5c2_abf59684bd19["exceptionCaught()"]
  3922501c_89d9_9315_87b2_3d95db47dd42 -->|calls| 34f36d79_45c9_b7bb_b5c2_abf59684bd19
  96ae33ed_29ae_f046_79a9_09fb0de64312["removeInboundHandler()"]
  3922501c_89d9_9315_87b2_3d95db47dd42 -->|calls| 96ae33ed_29ae_f046_79a9_09fb0de64312
  6c1d8b66_6d65_d3a4_8c9a_0215caab624e["removeOutboundHandler()"]
  3922501c_89d9_9315_87b2_3d95db47dd42 -->|calls| 6c1d8b66_6d65_d3a4_8c9a_0215caab624e
  style 3922501c_89d9_9315_87b2_3d95db47dd42 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java lines 126–174

    @Override
    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
        if (inboundHandler == null) {
            throw new IllegalStateException(
                    "init() must be invoked before being added to a " + ChannelPipeline.class.getSimpleName() +
                            " if " +  CombinedChannelDuplexHandler.class.getSimpleName() +
                            " was constructed with the default constructor.");
        }

        outboundCtx = new DelegatingChannelHandlerContext(ctx, outboundHandler);
        inboundCtx = new DelegatingChannelHandlerContext(ctx, inboundHandler) {
            @SuppressWarnings("deprecation")
            @Override
            public ChannelHandlerContext fireExceptionCaught(Throwable cause) {
                if (!outboundCtx.removed) {
                    try {
                        // We directly delegate to the ChannelOutboundHandler as this may override exceptionCaught(...)
                        // as well
                        outboundHandler.exceptionCaught(outboundCtx, cause);
                    } catch (Throwable error) {
                        if (logger.isDebugEnabled()) {
                            logger.debug(
                                    "An exception " +
                                    "was thrown by a user handler's exceptionCaught() " +
                                    "method while handling the following exception:", cause);
                        } else if (logger.isWarnEnabled()) {
                            logger.warn(
                                    "An exception '{}' [enable DEBUG level for full stacktrace] " +
                                    "was thrown by a user handler's exceptionCaught() " +
                                    "method while handling the following exception:", error, cause);
                        }
                    }
                } else {
                    super.fireExceptionCaught(cause);
                }
                return this;
            }
        };

        // The inboundCtx and outboundCtx were created and set now it's safe to call removeInboundHandler() and
        // removeOutboundHandler().
        handlerAdded = true;

        try {
            inboundHandler.handlerAdded(inboundCtx);
        } finally {
            outboundHandler.handlerAdded(outboundCtx);
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does handlerAdded() do?
handlerAdded() is a function in the netty codebase, defined in transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java.
Where is handlerAdded() defined?
handlerAdded() is defined in transport/src/main/java/io/netty/channel/CombinedChannelDuplexHandler.java at line 126.
What does handlerAdded() call?
handlerAdded() calls 5 function(s): DelegatingChannelHandlerContext, exceptionCaught, init, removeInboundHandler, removeOutboundHandler.

Analyze Your Own Codebase

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

Try Supermodel Free