Home / Class/ NioDatagramChannel Class — netty Architecture

NioDatagramChannel Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8["NioDatagramChannel"]
  f0175f02_e236_6e72_b72b_a4342260737d["NioDatagramChannel.java"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|defined in| f0175f02_e236_6e72_b72b_a4342260737d
  d9c9a730_46fa_7083_96da_f095e4abbc5c["DatagramChannel()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| d9c9a730_46fa_7083_96da_f095e4abbc5c
  2137a422_5c04_5bda_150a_6f18890f8ba3["NioDatagramChannel()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| 2137a422_5c04_5bda_150a_6f18890f8ba3
  4eafc010_07ee_5e86_7f99_b9d96e632e10["ChannelMetadata()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| 4eafc010_07ee_5e86_7f99_b9d96e632e10
  11aa5334_4613_f20b_d3b7_1cb0320fe911["DatagramChannelConfig()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| 11aa5334_4613_f20b_d3b7_1cb0320fe911
  c6aebd7b_7193_ccf4_ca2c_c1762809f463["isActive()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| c6aebd7b_7193_ccf4_ca2c_c1762809f463
  b58eb517_cba8_b84b_7f8b_5e83103381c4["isConnected()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| b58eb517_cba8_b84b_7f8b_5e83103381c4
  09969467_c177_2914_ebe7_7a81ec7c8e66["SocketAddress()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| 09969467_c177_2914_ebe7_7a81ec7c8e66
  ea40bfdc_bf94_ae22_b442_67a5d692ac7c["doBind()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| ea40bfdc_bf94_ae22_b442_67a5d692ac7c
  4cd271fa_9688_ba4c_1007_403fea997255["doBind0()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| 4cd271fa_9688_ba4c_1007_403fea997255
  542e7de3_afb8_7f31_ef01_9ec6ca8c6195["doConnect()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| 542e7de3_afb8_7f31_ef01_9ec6ca8c6195
  a0db9cc0_c808_22c1_7393_1088292a6aa6["doFinishConnect()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| a0db9cc0_c808_22c1_7393_1088292a6aa6
  9439bdb5_2122_0040_92bc_3d8fd64cdac5["doDisconnect()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| 9439bdb5_2122_0040_92bc_3d8fd64cdac5
  55b22e56_efbf_a1ed_4507_1e95c849cc26["doClose()"]
  62bb7cb5_86a2_a73b_659d_4f8936fbd7b8 -->|method| 55b22e56_efbf_a1ed_4507_1e95c849cc26

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java lines 65–628

public final class NioDatagramChannel
        extends AbstractNioMessageChannel implements io.netty.channel.socket.DatagramChannel {

    private static final ChannelMetadata METADATA = new ChannelMetadata(true, 16);
    private static final SelectorProvider DEFAULT_SELECTOR_PROVIDER = SelectorProvider.provider();
    private static final String EXPECTED_TYPES =
            " (expected: " + StringUtil.simpleClassName(DatagramPacket.class) + ", " +
            StringUtil.simpleClassName(AddressedEnvelope.class) + '<' +
            StringUtil.simpleClassName(ByteBuf.class) + ", " +
            StringUtil.simpleClassName(SocketAddress.class) + ">, " +
            StringUtil.simpleClassName(ByteBuf.class) + ')';

    private final DatagramChannelConfig config;

    private Map<InetAddress, List<MembershipKey>> memberships;

    /**
     *  Use the {@link SelectorProvider} to open {@link DatagramChannel} and so remove condition in
     *  {@link SelectorProvider#provider()} which is called by each DatagramChannel.open() otherwise.
     * <p>
     *  See <a href="https://github.com/netty/netty/issues/2308">#2308</a>.
     */
    private static DatagramChannel newSocket(SelectorProvider provider) {
        try {
            return provider.openDatagramChannel();
        } catch (IOException e) {
            throw new ChannelException("Failed to open a socket.", e);
        }
    }

    private static DatagramChannel newSocket(SelectorProvider provider, SocketProtocolFamily ipFamily) {
        if (ipFamily == null) {
            return newSocket(provider);
        }

        try {
            return provider.openDatagramChannel(ipFamily.toJdkFamily());
        } catch (IOException e) {
            throw new ChannelException("Failed to open a socket.", e);
        }
    }

    /**
     * Create a new instance which will use the Operation Systems default {@link SocketProtocolFamily}.
     */
    public NioDatagramChannel() {
        this(newSocket(DEFAULT_SELECTOR_PROVIDER));
    }

    /**
     * Create a new instance using the given {@link SelectorProvider}
     * which will use the Operation Systems default {@link SocketProtocolFamily}.
     */
    public NioDatagramChannel(SelectorProvider provider) {
        this(newSocket(provider));
    }

    /**
     * Create a new instance using the given {@link InternetProtocolFamily}. If {@code null} is used it will depend
     * on the Operation Systems default which will be chosen.
     *
     * @deprecated use {@link NioDatagramChannel#NioDatagramChannel(SocketProtocolFamily)}
     */
    @Deprecated
    public NioDatagramChannel(InternetProtocolFamily ipFamily) {
        this(ipFamily == null ? null : ipFamily.toSocketProtocolFamily());
    }

    /**
     * Create a new instance using the given {@link SocketProtocolFamily}. If {@code null} is used it will depend
     * on the Operation Systems default which will be chosen.
     */
    public NioDatagramChannel(SocketProtocolFamily protocolFamily) {
        this(newSocket(DEFAULT_SELECTOR_PROVIDER, protocolFamily));
    }

    /**
     * Create a new instance using the given {@link SelectorProvider} and {@link InternetProtocolFamily}.
     * If {@link InternetProtocolFamily} is {@code null} it will depend on the Operation Systems default
     * which will be chosen.
     *

Frequently Asked Questions

What is the NioDatagramChannel class?
NioDatagramChannel is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java.
Where is NioDatagramChannel defined?
NioDatagramChannel is defined in transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java at line 65.

Analyze Your Own Codebase

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

Try Supermodel Free