Home / Class/ ServerBootstrap Class — netty Architecture

ServerBootstrap Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  2fb94a4f_2aca_1486_1e90_659b2d71aad5["ServerBootstrap"]
  2d8678e4_c020_b8ee_69ca_75f537a75f47["ServerBootstrap.java"]
  2fb94a4f_2aca_1486_1e90_659b2d71aad5 -->|defined in| 2d8678e4_c020_b8ee_69ca_75f537a75f47
  ad57acf2_107b_00a8_4616_d610e01bc748["ServerBootstrap()"]
  2fb94a4f_2aca_1486_1e90_659b2d71aad5 -->|method| ad57acf2_107b_00a8_4616_d610e01bc748
  09073c8c_5c81_6831_9300_84392504d430["init()"]
  2fb94a4f_2aca_1486_1e90_659b2d71aad5 -->|method| 09073c8c_5c81_6831_9300_84392504d430
  d0512918_7f4a_96d3_04fb_4c1123336a10["EventLoopGroup()"]
  2fb94a4f_2aca_1486_1e90_659b2d71aad5 -->|method| d0512918_7f4a_96d3_04fb_4c1123336a10
  846d1695_bfe1_9164_f50c_a27de36be7dd["ChannelHandler()"]
  2fb94a4f_2aca_1486_1e90_659b2d71aad5 -->|method| 846d1695_bfe1_9164_f50c_a27de36be7dd
  37fedd3b_070d_40e5_5a48_dcc4f3d35509["childOptions()"]
  2fb94a4f_2aca_1486_1e90_659b2d71aad5 -->|method| 37fedd3b_070d_40e5_5a48_dcc4f3d35509
  2e638004_da17_66ba_f7b7_22c0dd87426c["childAttrs()"]
  2fb94a4f_2aca_1486_1e90_659b2d71aad5 -->|method| 2e638004_da17_66ba_f7b7_22c0dd87426c
  cd2e94e1_ef0b_c362_89ea_332665c8f1b3["ServerBootstrapConfig()"]
  2fb94a4f_2aca_1486_1e90_659b2d71aad5 -->|method| cd2e94e1_ef0b_c362_89ea_332665c8f1b3

Relationship Graph

Source Code

transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java lines 44–312

public class ServerBootstrap extends AbstractBootstrap<ServerBootstrap, ServerChannel> {

    private static final InternalLogger logger = InternalLoggerFactory.getInstance(ServerBootstrap.class);

    // The order in which child ChannelOptions are applied is important they may depend on each other for validation
    // purposes.
    private final Map<ChannelOption<?>, Object> childOptions = new LinkedHashMap<ChannelOption<?>, Object>();
    private final Map<AttributeKey<?>, Object> childAttrs = new ConcurrentHashMap<AttributeKey<?>, Object>();
    private final ServerBootstrapConfig config = new ServerBootstrapConfig(this);
    private volatile EventLoopGroup childGroup;
    private volatile ChannelHandler childHandler;

    public ServerBootstrap() { }

    private ServerBootstrap(ServerBootstrap bootstrap) {
        super(bootstrap);
        childGroup = bootstrap.childGroup;
        childHandler = bootstrap.childHandler;
        synchronized (bootstrap.childOptions) {
            childOptions.putAll(bootstrap.childOptions);
        }
        childAttrs.putAll(bootstrap.childAttrs);
    }

    /**
     * Specify the {@link EventLoopGroup} which is used for the parent (acceptor) and the child (client).
     */
    @Override
    public ServerBootstrap group(EventLoopGroup group) {
        return group(group, group);
    }

    /**
     * Set the {@link EventLoopGroup} for the parent (acceptor) and the child (client). These
     * {@link EventLoopGroup}'s are used to handle all the events and IO for {@link ServerChannel} and
     * {@link Channel}'s.
     * <p>
     * <strong>Important:</strong> Usually this is only useful for advanced use-cases and usually
     * {@link #group(EventLoopGroup)} is the preferred way to configure the group.
     */
    public ServerBootstrap group(EventLoopGroup parentGroup, EventLoopGroup childGroup) {
        super.group(parentGroup);
        if (this.childGroup != null) {
            throw new IllegalStateException("childGroup set already");
        }
        this.childGroup = ObjectUtil.checkNotNull(childGroup, "childGroup");
        return this;
    }

    /**
     * Allow to specify a {@link ChannelOption} which is used for the {@link Channel} instances once they get created
     * (after the acceptor accepted the {@link Channel}). Use a value of {@code null} to remove a previous set
     * {@link ChannelOption}.
     */
    public <T> ServerBootstrap childOption(ChannelOption<T> childOption, T value) {
        ObjectUtil.checkNotNull(childOption, "childOption");
        synchronized (childOptions) {
            if (value == null) {
                childOptions.remove(childOption);
            } else {
                childOptions.put(childOption, value);
            }
        }
        return this;
    }

    /**
     * Set the specific {@link AttributeKey} with the given value on every child {@link Channel}. If the value is
     * {@code null} the {@link AttributeKey} is removed
     */
    public <T> ServerBootstrap childAttr(AttributeKey<T> childKey, T value) {
        ObjectUtil.checkNotNull(childKey, "childKey");
        if (value == null) {
            childAttrs.remove(childKey);
        } else {
            childAttrs.put(childKey, value);
        }
        return this;
    }

    /**

Frequently Asked Questions

What is the ServerBootstrap class?
ServerBootstrap is a class in the netty codebase, defined in transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java.
Where is ServerBootstrap defined?
ServerBootstrap is defined in transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java at line 44.

Analyze Your Own Codebase

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

Try Supermodel Free