Home / Class/ SimpleChannelInboundHandler Class — netty Architecture

SimpleChannelInboundHandler Class — netty Architecture

Architecture documentation for the SimpleChannelInboundHandler class in SimpleChannelInboundHandler.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  83b83372_f1af_b71d_b6a1_92ebc4e86f2c["SimpleChannelInboundHandler"]
  793a4e72_ee91_fb2a_78be_c77ddee6722e["SimpleChannelInboundHandler.java"]
  83b83372_f1af_b71d_b6a1_92ebc4e86f2c -->|defined in| 793a4e72_ee91_fb2a_78be_c77ddee6722e
  01c63f14_adef_3159_c703_c0cf3dedb1e3["SimpleChannelInboundHandler()"]
  83b83372_f1af_b71d_b6a1_92ebc4e86f2c -->|method| 01c63f14_adef_3159_c703_c0cf3dedb1e3
  1b07f85f_a730_9068_6e66_e35693971d31["acceptInboundMessage()"]
  83b83372_f1af_b71d_b6a1_92ebc4e86f2c -->|method| 1b07f85f_a730_9068_6e66_e35693971d31
  5e0c7714_d30e_fe0b_f3a8_4adf2fb3dc51["channelRead()"]
  83b83372_f1af_b71d_b6a1_92ebc4e86f2c -->|method| 5e0c7714_d30e_fe0b_f3a8_4adf2fb3dc51
  9a9ced9e_c4c4_7c42_0607_73b5f85aeee6["channelRead0()"]
  83b83372_f1af_b71d_b6a1_92ebc4e86f2c -->|method| 9a9ced9e_c4c4_7c42_0607_73b5f85aeee6

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/SimpleChannelInboundHandler.java lines 42–120

public abstract class SimpleChannelInboundHandler<I> extends ChannelInboundHandlerAdapter {

    private final TypeParameterMatcher matcher;
    private final boolean autoRelease;

    /**
     * see {@link #SimpleChannelInboundHandler(boolean)} with {@code true} as boolean parameter.
     */
    protected SimpleChannelInboundHandler() {
        this(true);
    }

    /**
     * Create a new instance which will try to detect the types to match out of the type parameter of the class.
     *
     * @param autoRelease   {@code true} if handled messages should be released automatically by passing them to
     *                      {@link ReferenceCountUtil#release(Object)}.
     */
    protected SimpleChannelInboundHandler(boolean autoRelease) {
        matcher = TypeParameterMatcher.find(this, SimpleChannelInboundHandler.class, "I");
        this.autoRelease = autoRelease;
    }

    /**
     * see {@link #SimpleChannelInboundHandler(Class, boolean)} with {@code true} as boolean value.
     */
    protected SimpleChannelInboundHandler(Class<? extends I> inboundMessageType) {
        this(inboundMessageType, true);
    }

    /**
     * Create a new instance
     *
     * @param inboundMessageType    The type of messages to match
     * @param autoRelease           {@code true} if handled messages should be released automatically by passing them to
     *                              {@link ReferenceCountUtil#release(Object)}.
     */
    protected SimpleChannelInboundHandler(Class<? extends I> inboundMessageType, boolean autoRelease) {
        matcher = TypeParameterMatcher.get(inboundMessageType);
        this.autoRelease = autoRelease;
    }

    /**
     * Returns {@code true} if the given message should be handled. If {@code false} it will be passed to the next
     * {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
     */
    public boolean acceptInboundMessage(Object msg) throws Exception {
        return matcher.match(msg);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        boolean release = true;
        try {
            if (acceptInboundMessage(msg)) {
                @SuppressWarnings("unchecked")
                I imsg = (I) msg;
                channelRead0(ctx, imsg);
            } else {
                release = false;
                ctx.fireChannelRead(msg);
            }
        } finally {
            if (autoRelease && release) {
                ReferenceCountUtil.release(msg);
            }
        }
    }

    /**
     * Is called for each message of type {@link I}.
     *
     * @param ctx           the {@link ChannelHandlerContext} which this {@link SimpleChannelInboundHandler}
     *                      belongs to
     * @param msg           the message to handle
     * @throws Exception    is thrown if an error occurred
     */
    protected abstract void channelRead0(ChannelHandlerContext ctx, I msg) throws Exception;
}

Frequently Asked Questions

What is the SimpleChannelInboundHandler class?
SimpleChannelInboundHandler is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/SimpleChannelInboundHandler.java.
Where is SimpleChannelInboundHandler defined?
SimpleChannelInboundHandler is defined in transport/src/main/java/io/netty/channel/SimpleChannelInboundHandler.java at line 42.

Analyze Your Own Codebase

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

Try Supermodel Free