Home / Class/ Native Class — netty Architecture

Native Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  3a2176ad_d250_6417_2863_7a8e697645d2["Native"]
  f74d59b3_d24b_4ca1_ed20_fa5d532d50aa["Native.java"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|defined in| f74d59b3_d24b_4ca1_ed20_fa5d532d50aa
  9b486c7c_b75c_8442_c4a3_f42ce828d1d4["registerUnix()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| 9b486c7c_b75c_8442_c4a3_f42ce828d1d4
  f4c0f6b0_8934_af75_4ab3_1c063a0857b2["FileDescriptor()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| f4c0f6b0_8934_af75_4ab3_1c063a0857b2
  ce9fc741_2c03_faf5_1d52_4679519af878["keventWait()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| ce9fc741_2c03_faf5_1d52_4679519af878
  ccf4bc7a_f0dc_303f_6e1c_6dd81a978656["kqueueCreate()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| ccf4bc7a_f0dc_303f_6e1c_6dd81a978656
  6db6331a_948f_9892_3674_a1b7e83f5a7b["keventTriggerUserEvent()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| 6db6331a_948f_9892_3674_a1b7e83f5a7b
  dd6fa0cd_e4ee_c223_a01c_5207e1bb2d93["keventAddUserEvent()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| dd6fa0cd_e4ee_c223_a01c_5207e1bb2d93
  4c38109e_b54d_277b_671c_9c49f3507141["sizeofKEvent()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| 4c38109e_b54d_277b_671c_9c49f3507141
  65260946_8373_0aaa_4554_496081d1400a["offsetofKEventIdent()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| 65260946_8373_0aaa_4554_496081d1400a
  0fc78e5f_45bf_bbcb_a649_c631c63111b8["offsetofKEventFlags()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| 0fc78e5f_45bf_bbcb_a649_c631c63111b8
  f69ba4a3_9fef_21b8_5e2c_91758a8ef91f["offsetofKEventFFlags()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| f69ba4a3_9fef_21b8_5e2c_91758a8ef91f
  4fb0eab8_0f3f_53da_0ff3_e377410665c8["offsetofKEventFilter()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| 4fb0eab8_0f3f_53da_0ff3_e377410665c8
  27459012_55d5_4374_2b96_b3f67ada21b4["offsetofKeventData()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| 27459012_55d5_4374_2b96_b3f67ada21b4
  6135830a_e35e_efcb_d15a_2efa3984e195["offsetofKeventUdata()"]
  3a2176ad_d250_6417_2863_7a8e697645d2 -->|method| 6135830a_e35e_efcb_d15a_2efa3984e195

Relationship Graph

Source Code

transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/Native.java lines 56–198

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

    static {
        // Preload all classes that will be used in the OnLoad(...) function of JNI to eliminate the possiblity of a
        // class-loader deadlock. This is a workaround for https://github.com/netty/netty/issues/11209.

        // This needs to match all the classes that are loaded via NETTY_JNI_UTIL_LOAD_CLASS or looked up via
        // NETTY_JNI_UTIL_FIND_CLASS.
        ClassInitializerUtil.tryLoadClasses(Native.class,
                // netty_kqueue_bsdsocket
                PeerCredentials.class, DefaultFileRegion.class, FileChannel.class, java.io.FileDescriptor.class
        );

        try {
            // First, try calling a side-effect free JNI method to see if the library was already
            // loaded by the application.
            sizeofKEvent();
        } catch (UnsatisfiedLinkError ignore) {
            // The library was not previously loaded, load it now.
            loadNativeLibrary();
        }
        Unix.registerInternal(new Runnable() {
            @Override
            public void run() {
                registerUnix();
            }
        });
    }

    private static native int registerUnix();

    static final short EV_ADD = evAdd();
    static final short EV_ENABLE = evEnable();
    static final short EV_DISABLE = evDisable();
    static final short EV_DELETE = evDelete();
    static final short EV_CLEAR = evClear();
    static final short EV_ERROR = evError();
    static final short EV_EOF = evEOF();

    static final int NOTE_READCLOSED = noteReadClosed();
    static final int NOTE_CONNRESET = noteConnReset();
    static final int NOTE_DISCONNECTED = noteDisconnected();

    static final int NOTE_RDHUP = NOTE_READCLOSED | NOTE_CONNRESET | NOTE_DISCONNECTED;

    // Commonly used combinations of EV defines
    static final short EV_ADD_ENABLE = (short) (EV_ADD | EV_ENABLE);
    static final short EV_DELETE_DISABLE = (short) (EV_DELETE | EV_DISABLE);

    static final short EVFILT_READ = evfiltRead();
    static final short EVFILT_WRITE = evfiltWrite();
    static final short EVFILT_USER = evfiltUser();
    static final short EVFILT_SOCK = evfiltSock();

    // Flags for connectx(2)
    private static final int CONNECT_RESUME_ON_READ_WRITE = connectResumeOnReadWrite();
    private static final int CONNECT_DATA_IDEMPOTENT = connectDataIdempotent();
    static final int CONNECT_TCP_FASTOPEN = CONNECT_RESUME_ON_READ_WRITE | CONNECT_DATA_IDEMPOTENT;
    static final boolean IS_SUPPORTING_TCP_FASTOPEN_CLIENT = isSupportingFastOpenClient();
    static final boolean IS_SUPPORTING_TCP_FASTOPEN_SERVER = isSupportingFastOpenServer();

    static final KQueueIoOps READ_ENABLED_OPS =
            KQueueIoOps.newOps(Native.EVFILT_READ, Native.EV_ADD_ENABLE, 0);
    static final KQueueIoOps WRITE_ENABLED_OPS =
            KQueueIoOps.newOps(Native.EVFILT_WRITE, Native.EV_ADD_ENABLE, 0);
    static final KQueueIoOps READ_DISABLED_OPS =
            KQueueIoOps.newOps(Native.EVFILT_READ, Native.EV_DELETE_DISABLE, 0);
    static final KQueueIoOps WRITE_DISABLED_OPS =
            KQueueIoOps.newOps(Native.EVFILT_WRITE, Native.EV_DELETE_DISABLE, 0);

    static FileDescriptor newKQueue() {
        return new FileDescriptor(kqueueCreate());
    }

    static int keventWait(int kqueueFd, KQueueEventArray changeList, KQueueEventArray eventList,
                          int tvSec, int tvNsec) throws IOException {
        int ready = keventWait(kqueueFd, changeList.memoryAddress(), changeList.size(),
                               eventList.memoryAddress(), eventList.capacity(), tvSec, tvNsec);
        if (ready < 0) {
            throw newIOException("kevent", ready);

Frequently Asked Questions

What is the Native class?
Native is a class in the netty codebase, defined in transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/Native.java.
Where is Native defined?
Native is defined in transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/Native.java at line 56.

Analyze Your Own Codebase

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

Try Supermodel Free