Home / Class/ DefaultChannelId Class — netty Architecture

DefaultChannelId Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  20dcb0e9_635a_927e_e4b0_31b79bc84709["DefaultChannelId"]
  9946471d_6cee_f311_adfa_f1facc2d5f8d["DefaultChannelId.java"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|defined in| 9946471d_6cee_f311_adfa_f1facc2d5f8d
  2e1e369d_9647_658a_e7b6_17d55f78fff8["DefaultChannelId()"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|method| 2e1e369d_9647_658a_e7b6_17d55f78fff8
  f0c7f7e4_2aba_5506_a08d_94bc7c7bd25a["processHandlePid()"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|method| f0c7f7e4_2aba_5506_a08d_94bc7c7bd25a
  ae2ec16d_46c0_863e_c3f8_f57eaa932736["jmxPid()"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|method| ae2ec16d_46c0_863e_c3f8_f57eaa932736
  478fc34f_b108_10df_c8a9_c1549c05cf81["defaultProcessId()"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|method| 478fc34f_b108_10df_c8a9_c1549c05cf81
  aca15d4b_776f_9644_2693_2188808974da["writeInt()"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|method| aca15d4b_776f_9644_2693_2188808974da
  4b21a91b_5148_c685_e244_5e9d21f5f792["writeLong()"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|method| 4b21a91b_5148_c685_e244_5e9d21f5f792
  f69276f1_496a_39a1_ba4d_43a9db820ebd["String()"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|method| f69276f1_496a_39a1_ba4d_43a9db820ebd
  56b0b6cf_df86_87a4_a8c9_12d701ba661e["appendHexDumpField()"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|method| 56b0b6cf_df86_87a4_a8c9_12d701ba661e
  1cb9e8a1_1429_beaf_5254_26629909fbaf["hashCode()"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|method| 1cb9e8a1_1429_beaf_5254_26629909fbaf
  591edfaf_0e7e_48ab_0eb0_f09c4447b3fa["compareTo()"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|method| 591edfaf_0e7e_48ab_0eb0_f09c4447b3fa
  7aaae750_f0a8_9122_e38f_357a6d55bfc9["equals()"]
  20dcb0e9_635a_927e_e4b0_31b79bc84709 -->|method| 7aaae750_f0a8_9122_e38f_357a6d55bfc9

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/DefaultChannelId.java lines 39–342

public final class DefaultChannelId implements ChannelId {

    private static final long serialVersionUID = 3884076183504074063L;

    private static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultChannelId.class);
    private static final byte[] MACHINE_ID;
    private static final int PROCESS_ID_LEN = 4;
    private static final int PROCESS_ID;
    private static final int SEQUENCE_LEN = 4;
    private static final int TIMESTAMP_LEN = 8;
    private static final int RANDOM_LEN = 4;

    private static final AtomicInteger nextSequence = new AtomicInteger();

    /**
     * Returns a new {@link DefaultChannelId} instance.
     */
    public static DefaultChannelId newInstance() {
        return new DefaultChannelId(MACHINE_ID,
                                    PROCESS_ID,
                                    nextSequence.getAndIncrement(),
                                    Long.reverse(System.nanoTime()) ^ System.currentTimeMillis(),
                                    ThreadLocalRandom.current().nextInt());
    }

    static {
        int processId = -1;
        String customProcessId = SystemPropertyUtil.get("io.netty.processId");
        if (customProcessId != null) {
            try {
                processId = Integer.parseInt(customProcessId);
            } catch (NumberFormatException e) {
                // Malformed input.
            }

            if (processId < 0) {
                processId = -1;
                logger.warn("-Dio.netty.processId: {} (malformed)", customProcessId);
            } else if (logger.isDebugEnabled()) {
                logger.debug("-Dio.netty.processId: {} (user-set)", processId);
            }
        }

        if (processId < 0) {
            processId = defaultProcessId();
            if (logger.isDebugEnabled()) {
                logger.debug("-Dio.netty.processId: {} (auto-detected)", processId);
            }
        }

        PROCESS_ID = processId;

        byte[] machineId = null;
        String customMachineId = SystemPropertyUtil.get("io.netty.machineId");
        if (customMachineId != null) {
            try {
                machineId = parseMAC(customMachineId);
            } catch (Exception e) {
                logger.warn("-Dio.netty.machineId: {} (malformed)", customMachineId, e);
            }
            if (machineId != null) {
                logger.debug("-Dio.netty.machineId: {} (user-set)", customMachineId);
            }
        }

        if (machineId == null) {
            machineId = defaultMachineId();
            if (logger.isDebugEnabled()) {
                logger.debug("-Dio.netty.machineId: {} (auto-detected)", MacAddressUtil.formatAddress(machineId));
            }
        }

        MACHINE_ID = machineId;
    }

    static int processHandlePid(ClassLoader loader) {
        // pid is positive on unix, non{-1,0} on windows
        int nilValue = -1;
        if (PlatformDependent.javaVersion() >= 9) {
            Long pid;
            try {

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free