美文网首页程序员
netty源码分析(3)-AbstractBootstrapCo

netty源码分析(3)-AbstractBootstrapCo

作者: Jorgezhong | 来源:发表于2019-02-18 16:00 被阅读0次

上一节分析了初始化Channel的过程,其中涉及了AbstractBootstrap及其子类的成员变量配置以及初始化过程。其中初始化具体Bootstrap的时候有这么一个成员变量,用于存储Bootstrap的配置信息。

private final ServerBootstrapConfig config = new ServerBootstrapConfig(this);

分析源码我们发现AbstractBootstrapConfig只是AbstractBootstrap的一个包装类,父类提供获取父类成员变量的方法,配置类的具体子提供类获取子类的成员变更了方法。

public abstract class AbstractBootstrapConfig<B extends AbstractBootstrap<B, C>, C extends Channel> {

    protected final B bootstrap;

    protected AbstractBootstrapConfig(B bootstrap) {
        this.bootstrap = ObjectUtil.checkNotNull(bootstrap, "bootstrap");
    }

    /**
     * Returns the configured local address or {@code null} if non is configured yet.
     */
    public final SocketAddress localAddress() {
        return bootstrap.localAddress();
    }

    /**
     * Returns the configured {@link ChannelFactory} or {@code null} if non is configured yet.
     */
    @SuppressWarnings("deprecation")
    public final ChannelFactory<? extends C> channelFactory() {
        return bootstrap.channelFactory();
    }

    /**
     * Returns the configured {@link ChannelHandler} or {@code null} if non is configured yet.
     */
    public final ChannelHandler handler() {
        return bootstrap.handler();
    }

    /**
     * Returns a copy of the configured options.
     */
    public final Map<ChannelOption<?>, Object> options() {
        return bootstrap.options();
    }

    /**
     * Returns a copy of the configured attributes.
     */
    public final Map<AttributeKey<?>, Object> attrs() {
        return bootstrap.attrs();
    }

    /**
     * Returns the configured {@link EventLoopGroup} or {@code null} if non is configured yet.
     */
    @SuppressWarnings("deprecation")
    public final EventLoopGroup group() {
        return bootstrap.group();
    }

    @Override
    public String toString() {...}
}

相关文章

网友评论

    本文标题:netty源码分析(3)-AbstractBootstrapCo

    本文链接:https://www.haomeiwen.com/subject/qvgaeqtx.html