public class ServerBootstrap extends AbstractBootstrap<ServerBootstrap, ServerChannel> { ...略 private final ServerBootstrapConfig config = new ServerBootstrapConfig(this); ...略 public final ServerBootstrapConfig config() { return config; } ...略 }
public EventLoopGroup childGroup() { return bootstrap.childGroup(); }
/** * Returns the configured {@link ChannelHandler} be used for the child channels or {@code null} * if non is configured yet. */ public ChannelHandler childHandler() { return bootstrap.childHandler(); }
/** * Returns a copy of the configured options which will be used for the child channels. */ public Map<ChannelOption<?>, Object> childOptions() { return bootstrap.childOptions(); }
/** * Returns a copy of the configured attributes which will be used for the child channels. */ public Map<AttributeKey<?>, Object> childAttrs() { return bootstrap.childAttrs(); }
对应的ServerBootstrap的就是:
1 2 3 4
private final Map<ChannelOption<?>, Object> childOptions = new LinkedHashMap<ChannelOption<?>, Object>(); private final Map<AttributeKey<?>, Object> childAttrs = new LinkedHashMap<AttributeKey<?>, Object>(); private volatile EventLoopGroup childGroup; private volatile ChannelHandler childHandler;
public abstract class AbstractBootstrapConfig<B extends AbstractBootstrap<B, C>, C extends Channel> { ...略 protected final B bootstrap;//B的实际类型是ServerBootstrap public final EventLoopGroup group() { return bootstrap.group(); } ...略 }
bootstrap.group():
1 2 3 4 5 6 7 8 9
public abstract class AbstractBootstrap<B extends AbstractBootstrap<B, C>, C extends Channel> implements Cloneable { ...略 volatile EventLoopGroup group;//事件循环组,实际上是NioEventLoopGroup ...略 public final EventLoopGroup group() { return group; } ...略 }