Home / Class/ LocalChannel Class — netty Architecture

LocalChannel Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8["LocalChannel"]
  e832f9b0_66fa_273d_c41a_059a1e7dde03["LocalChannel.java"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|defined in| e832f9b0_66fa_273d_c41a_059a1e7dde03
  fae3abfb_6397_547f_6591_15e29dcf32f9["LocalChannel()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| fae3abfb_6397_547f_6591_15e29dcf32f9
  80e9fb91_c59e_d18c_c471_83dc38a2a035["ChannelMetadata()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| 80e9fb91_c59e_d18c_c471_83dc38a2a035
  132f0251_937f_cc1f_67f7_ce2cae69f1af["ChannelConfig()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| 132f0251_937f_cc1f_67f7_ce2cae69f1af
  4f65a791_2e18_14d5_e2b9_4ac02b7c8080["LocalServerChannel()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| 4f65a791_2e18_14d5_e2b9_4ac02b7c8080
  64c2356a_7595_21cb_3c1f_5ea823bfa144["LocalAddress()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| 64c2356a_7595_21cb_3c1f_5ea823bfa144
  3ce42b96_1b62_30d4_6518_db8eca00b52c["isOpen()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| 3ce42b96_1b62_30d4_6518_db8eca00b52c
  e5e77d83_af4b_40c2_06fb_b37cd74710b7["isActive()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| e5e77d83_af4b_40c2_06fb_b37cd74710b7
  0a52b648_ee30_1bd9_32c1_a4f6a57be200["AbstractUnsafe()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| 0a52b648_ee30_1bd9_32c1_a4f6a57be200
  c717252f_a515_46f3_5efa_2596fe64f54b["isCompatible()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| c717252f_a515_46f3_5efa_2596fe64f54b
  5e2523ae_db35_d117_4447_ff86683da668["SocketAddress()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| 5e2523ae_db35_d117_4447_ff86683da668
  9f78cf60_4bba_256d_19f7_ed523fbe93ff["doRegister()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| 9f78cf60_4bba_256d_19f7_ed523fbe93ff
  6f32f167_611c_444c_1d2a_cae03560dda4["doDeregister()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| 6f32f167_611c_444c_1d2a_cae03560dda4
  60014652_5e69_eacb_7bce_6e56bfdfeb05["doBind()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 -->|method| 60014652_5e69_eacb_7bce_6e56bfdfeb05

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/local/LocalChannel.java lines 54–586

public class LocalChannel extends AbstractChannel {
    private static final InternalLogger logger = InternalLoggerFactory.getInstance(LocalChannel.class);
    @SuppressWarnings({ "rawtypes" })
    private static final AtomicReferenceFieldUpdater<LocalChannel, Future> FINISH_READ_FUTURE_UPDATER =
            AtomicReferenceFieldUpdater.newUpdater(LocalChannel.class, Future.class, "finishReadFuture");
    private static final ChannelMetadata METADATA = new ChannelMetadata(false);
    private static final int MAX_READER_STACK_DEPTH = 8;

    private enum State { OPEN, BOUND, CONNECTED, CLOSED }

    private final ChannelConfig config = new DefaultChannelConfig(this);
    // To further optimize this we could write our own SPSC queue.
    final Queue<Object> inboundBuffer = PlatformDependent.newSpscQueue();
    private final Runnable readTask = new Runnable() {
        @Override
        public void run() {
            // Ensure the inboundBuffer is not empty as readInbound() will always call fireChannelReadComplete()
            if (!inboundBuffer.isEmpty()) {
                readInbound();
            }
        }
    };

    private final Runnable shutdownHook = new Runnable() {
        @Override
        public void run() {
            unsafe().close(unsafe().voidPromise());
        }
    };

    private final Runnable finishReadTask = new Runnable() {
        @Override
        public void run() {
            finishPeerRead0(LocalChannel.this);
        }
    };

    private IoRegistration registration;

    private volatile State state;
    private volatile LocalChannel peer;
    private volatile LocalAddress localAddress;
    private volatile LocalAddress remoteAddress;
    private volatile ChannelPromise connectPromise;
    private volatile boolean readInProgress;
    private volatile boolean writeInProgress;
    private volatile Future<?> finishReadFuture;

    public LocalChannel() {
        super(null);
        config().setAllocator(new PreferHeapByteBufAllocator(config.getAllocator()));
    }

    protected LocalChannel(LocalServerChannel parent, LocalChannel peer) {
        super(parent);
        config().setAllocator(new PreferHeapByteBufAllocator(config.getAllocator()));
        this.peer = peer;
        localAddress = parent.localAddress();
        remoteAddress = peer.localAddress();
    }

    @Override
    public ChannelMetadata metadata() {
        return METADATA;
    }

    @Override
    public ChannelConfig config() {
        return config;
    }

    @Override
    public LocalServerChannel parent() {
        return (LocalServerChannel) super.parent();
    }

    @Override
    public LocalAddress localAddress() {
        return (LocalAddress) super.localAddress();
    }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free