Home / Class/ AbstractUnsafe Class — netty Architecture

AbstractUnsafe Class — netty Architecture

Architecture documentation for the AbstractUnsafe class in AbstractChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  330d05c9_85ca_2e57_92f5_e996fb442b81["AbstractUnsafe"]
  2f45d36a_a64d_2e11_9b5d_198acbea865d["AbstractChannel.java"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|defined in| 2f45d36a_a64d_2e11_9b5d_198acbea865d
  30686258_744e_d516_027d_4264d61dbea3["assertEventLoop()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| 30686258_744e_d516_027d_4264d61dbea3
  76bb2e8b_b67d_24a0_996b_0e6d08d90a79["recvBufAllocHandle()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| 76bb2e8b_b67d_24a0_996b_0e6d08d90a79
  23a8cfa5_df8f_820b_e96e_7ebf7469ee68["ChannelOutboundBuffer()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| 23a8cfa5_df8f_820b_e96e_7ebf7469ee68
  2119f3ed_893d_fab6_2f4b_7c5c69b88339["SocketAddress()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| 2119f3ed_893d_fab6_2f4b_7c5c69b88339
  7ac63885_60f4_64a0_2bb5_20c6a0c6de73["register()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| 7ac63885_60f4_64a0_2bb5_20c6a0c6de73
  3636c0b5_4718_d99f_6eb8_ab7c7fc1bcc7["register0()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| 3636c0b5_4718_d99f_6eb8_ab7c7fc1bcc7
  12b196ff_bea6_a14a_f304_feba219fd5ac["bind()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| 12b196ff_bea6_a14a_f304_feba219fd5ac
  49488e5c_2130_0f61_1882_15fe94cba0eb["disconnect()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| 49488e5c_2130_0f61_1882_15fe94cba0eb
  3247fe36_e8dd_2a94_aca8_58f72f5210e8["close()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| 3247fe36_e8dd_2a94_aca8_58f72f5210e8
  e95fc83e_066e_406e_f5b1_0ff28fed8f37["shutdownOutput()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| e95fc83e_066e_406e_f5b1_0ff28fed8f37
  021f3296_6641_a119_4d87_0ee097950fa6["closeOutboundBufferForShutdown()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| 021f3296_6641_a119_4d87_0ee097950fa6
  6a2d44b1_60ce_ee0e_05d7_10de760601f8["doClose0()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| 6a2d44b1_60ce_ee0e_05d7_10de760601f8
  f6f2cb54_f0d8_1bcf_3e68_20a048e9867a["fireChannelInactiveAndDeregister()"]
  330d05c9_85ca_2e57_92f5_e996fb442b81 -->|method| f6f2cb54_f0d8_1bcf_3e68_20a048e9867a

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/AbstractChannel.java lines 288–919

    protected abstract class AbstractUnsafe implements Unsafe {

        private volatile ChannelOutboundBuffer outboundBuffer = new ChannelOutboundBuffer(AbstractChannel.this);
        private RecvByteBufAllocator.Handle recvHandle;
        private boolean inFlush0;
        /** true if the channel has never been registered, false otherwise */
        private boolean neverRegistered = true;

        private void assertEventLoop() {
            assert !registered || eventLoop.inEventLoop();
        }

        @Override
        public RecvByteBufAllocator.Handle recvBufAllocHandle() {
            if (recvHandle == null) {
                recvHandle = config().getRecvByteBufAllocator().newHandle();
            }
            return recvHandle;
        }

        @Override
        public final ChannelOutboundBuffer outboundBuffer() {
            return outboundBuffer;
        }

        @Override
        public final SocketAddress localAddress() {
            return localAddress0();
        }

        @Override
        public final SocketAddress remoteAddress() {
            return remoteAddress0();
        }

        @Override
        public final void register(EventLoop eventLoop, final ChannelPromise promise) {
            ObjectUtil.checkNotNull(eventLoop, "eventLoop");
            if (isRegistered()) {
                promise.setFailure(new IllegalStateException("registered to an event loop already"));
                return;
            }
            if (!isCompatible(eventLoop)) {
                promise.setFailure(
                        new IllegalStateException("incompatible event loop type: " + eventLoop.getClass().getName()));
                return;
            }

            AbstractChannel.this.eventLoop = eventLoop;

            // Clear any cached executors from prior event loop registrations.
            AbstractChannelHandlerContext context = pipeline.tail;
            do {
                context.contextExecutor = null;
                context = context.prev;
            } while (context != null);

            if (eventLoop.inEventLoop()) {
                register0(promise);
            } else {
                try {
                    eventLoop.execute(new Runnable() {
                        @Override
                        public void run() {
                            register0(promise);
                        }
                    });
                } catch (Throwable t) {
                    logger.warn(
                            "Force-closing a channel whose registration task was not accepted by an event loop: {}",
                            AbstractChannel.this, t);
                    closeForcibly();
                    closeFuture.setClosed();
                    safeSetFailure(promise, t);
                }
            }
        }

        private void register0(ChannelPromise promise) {
            // check if the channel is still open as it could be closed in the mean time when the register
            // call was outside of the eventLoop

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free