上一节分析了初始化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() {...}
}
网友评论