Home / Class/ DefaultChannelGroup Class — netty Architecture

DefaultChannelGroup Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  6d7f33a8_3187_e4ea_396d_f62be954d07b["DefaultChannelGroup"]
  ddd8381f_0b91_0d92_215e_996f7c6b8fb4["DefaultChannelGroup.java"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|defined in| ddd8381f_0b91_0d92_215e_996f7c6b8fb4
  be8df25b_3acc_3b3a_6aaa_6bbe323a01f2["DefaultChannelGroup()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| be8df25b_3acc_3b3a_6aaa_6bbe323a01f2
  b90dab04_26df_2a2a_d19f_be5614fe0311["String()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| b90dab04_26df_2a2a_d19f_be5614fe0311
  d7fe1cd5_b319_d854_1a61_06384e50987c["Channel()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| d7fe1cd5_b319_d854_1a61_06384e50987c
  12d82202_ee9b_5c2c_1147_053a783cac90["isEmpty()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| 12d82202_ee9b_5c2c_1147_053a783cac90
  0f02863a_99e8_2202_080e_3dd72c97b55b["size()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| 0f02863a_99e8_2202_080e_3dd72c97b55b
  042466f0_21ef_45ff_fd42_9acb59893417["contains()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| 042466f0_21ef_45ff_fd42_9acb59893417
  4d0e5010_2e39_3533_9d5c_db2eee504dfe["add()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| 4d0e5010_2e39_3533_9d5c_db2eee504dfe
  dd37ff53_4497_0e13_b556_9e12f3d16e16["remove()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| dd37ff53_4497_0e13_b556_9e12f3d16e16
  c06670c9_4cf4_7caf_ce13_03bbeca8f639["clear()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| c06670c9_4cf4_7caf_ce13_03bbeca8f639
  1c60ade1_2589_4b9e_d382_6a7712a8cc1d["iterator()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| 1c60ade1_2589_4b9e_d382_6a7712a8cc1d
  6062ae97_e0c1_5aa7_2596_de73ea307395["toArray()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| 6062ae97_e0c1_5aa7_2596_de73ea307395
  35c79e04_74bc_7829_a6a7_e0728e9bb727["ChannelGroupFuture()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| 35c79e04_74bc_7829_a6a7_e0728e9bb727
  f14fde2a_664a_72e5_0362_6d0a344d639d["Object()"]
  6d7f33a8_3187_e4ea_396d_f62be954d07b -->|method| f14fde2a_664a_72e5_0362_6d0a344d639d

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java lines 43–463

public class DefaultChannelGroup extends AbstractSet<Channel> implements ChannelGroup {

    private static final AtomicInteger nextId = new AtomicInteger();
    private final String name;
    private final EventExecutor executor;
    private final ConcurrentMap<ChannelId, Channel> serverChannels = new ConcurrentHashMap<>();
    private final ConcurrentMap<ChannelId, Channel> nonServerChannels = new ConcurrentHashMap<>();
    private final ChannelFutureListener remover = new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            remove(future.channel());
        }
    };
    private final VoidChannelGroupFuture voidFuture = new VoidChannelGroupFuture(this);
    private final boolean stayClosed;
    private volatile boolean closed;

    /**
     * Creates a new group with a generated name and the provided {@link EventExecutor} to notify the
     * {@link ChannelGroupFuture}s.
     */
    public DefaultChannelGroup(EventExecutor executor) {
        this(executor, false);
    }

    /**
     * Creates a new group with the specified {@code name} and {@link EventExecutor} to notify the
     * {@link ChannelGroupFuture}s.  Please note that different groups can have the same name, which means no
     * duplicate check is done against group names.
     */
    public DefaultChannelGroup(String name, EventExecutor executor) {
        this(name, executor, false);
    }

    /**
     * Creates a new group with a generated name and the provided {@link EventExecutor} to notify the
     * {@link ChannelGroupFuture}s. {@code stayClosed} defines whether or not, this group can be closed
     * more than once. Adding channels to a closed group will immediately close them, too. This makes it
     * easy, to shutdown server and child channels at once.
     */
    public DefaultChannelGroup(EventExecutor executor, boolean stayClosed) {
        this("group-0x" + Integer.toHexString(nextId.incrementAndGet()), executor, stayClosed);
    }

    /**
     * Creates a new group with the specified {@code name} and {@link EventExecutor} to notify the
     * {@link ChannelGroupFuture}s. {@code stayClosed} defines whether or not, this group can be closed
     * more than once. Adding channels to a closed group will immediately close them, too. This makes it
     * easy, to shutdown server and child channels at once. Please note that different groups can have
     * the same name, which means no duplicate check is done against group names.
     */
    public DefaultChannelGroup(String name, EventExecutor executor, boolean stayClosed) {
        ObjectUtil.checkNotNull(name, "name");
        this.name = name;
        this.executor = executor;
        this.stayClosed = stayClosed;
    }

    @Override
    public String name() {
        return name;
    }

    @Override
    public Channel find(ChannelId id) {
        Channel c = nonServerChannels.get(id);
        if (c != null) {
            return c;
        } else {
            return serverChannels.get(id);
        }
    }

    @Override
    public boolean isEmpty() {
        return nonServerChannels.isEmpty() && serverChannels.isEmpty();
    }

    @Override
    public int size() {
        return nonServerChannels.size() + serverChannels.size();

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free