Home / Class/ AbstractNioByteChannel Class — netty Architecture

AbstractNioByteChannel Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  81dd42bf_4dab_740c_6405_14423e9ad1f8["AbstractNioByteChannel"]
  b651d516_44e3_d960_a63c_4be7f06c25ba["AbstractNioByteChannel.java"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|defined in| b651d516_44e3_d960_a63c_4be7f06c25ba
  99a8b888_1c0b_1244_11a3_714452395cf9["AbstractNioByteChannel()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| 99a8b888_1c0b_1244_11a3_714452395cf9
  a1208fe3_98ac_33d0_2ddc_395abeb75df8["ChannelFuture()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| a1208fe3_98ac_33d0_2ddc_395abeb75df8
  4894ae17_932d_8d9d_5adf_e6684db2d184["isInputShutdown0()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| 4894ae17_932d_8d9d_5adf_e6684db2d184
  d5f6b768_30ce_449d_b267_434b7e914d5c["AbstractNioUnsafe()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| d5f6b768_30ce_449d_b267_434b7e914d5c
  115a8504_9ce5_687e_bebb_e55387439a5f["ChannelMetadata()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| 115a8504_9ce5_687e_bebb_e55387439a5f
  dc410111_84b8_c71e_6712_87ccf53c2adc["shouldBreakReadReady()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| dc410111_84b8_c71e_6712_87ccf53c2adc
  059ecb5f_a32b_b26f_c193_f5b0c2582375["isAllowHalfClosure()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| 059ecb5f_a32b_b26f_c193_f5b0c2582375
  254496f6_25fc_84de_730e_8f3b0842a4b3["doWrite0()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| 254496f6_25fc_84de_730e_8f3b0842a4b3
  e280c816_366c_4e91_6697_7eba37a14c24["doWriteInternal()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| e280c816_366c_4e91_6697_7eba37a14c24
  a28491f1_6177_d155_eb85_0f25c627fb66["doWrite()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| a28491f1_6177_d155_eb85_0f25c627fb66
  772cbaf3_7c7d_e0eb_0134_a3f3061cb2af["Object()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| 772cbaf3_7c7d_e0eb_0134_a3f3061cb2af
  46da3fe7_43e8_758e_f039_58b516d9c088["incompleteWrite()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| 46da3fe7_43e8_758e_f039_58b516d9c088
  b3b8d9c2_3c76_2c11_ed36_bff10b5cdd5f["doWriteFileRegion()"]
  81dd42bf_4dab_740c_6405_14423e9ad1f8 -->|method| b3b8d9c2_3c76_2c11_ed36_bff10b5cdd5f

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java lines 46–357

public abstract class AbstractNioByteChannel extends AbstractNioChannel {
    private static final ChannelMetadata METADATA = new ChannelMetadata(false, 16);
    private static final String EXPECTED_TYPES =
            " (expected: " + StringUtil.simpleClassName(ByteBuf.class) + ", " +
            StringUtil.simpleClassName(FileRegion.class) + ')';

    private final Runnable flushTask = new Runnable() {
        @Override
        public void run() {
            // Calling flush0 directly to ensure we not try to flush messages that were added via write(...) in the
            // meantime.
            ((AbstractNioUnsafe) unsafe()).flush0();
        }
    };
    private boolean inputClosedSeenErrorOnRead;

    /**
     * Create a new instance
     *
     * @param parent            the parent {@link Channel} by which this instance was created. May be {@code null}
     * @param ch                the underlying {@link SelectableChannel} on which it operates
     */
    protected AbstractNioByteChannel(Channel parent, SelectableChannel ch) {
        super(parent, ch, SelectionKey.OP_READ);
    }

    /**
     * Shutdown the input side of the channel.
     */
    protected abstract ChannelFuture shutdownInput();

    protected boolean isInputShutdown0() {
        return false;
    }

    @Override
    protected AbstractNioUnsafe newUnsafe() {
        return new NioByteUnsafe();
    }

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

    final boolean shouldBreakReadReady(ChannelConfig config) {
        return isInputShutdown0() && (inputClosedSeenErrorOnRead || !isAllowHalfClosure(config));
    }

    private static boolean isAllowHalfClosure(ChannelConfig config) {
        return config instanceof SocketChannelConfig &&
                ((SocketChannelConfig) config).isAllowHalfClosure();
    }

    protected class NioByteUnsafe extends AbstractNioUnsafe {

        private void closeOnRead(ChannelPipeline pipeline) {
            if (!isInputShutdown0()) {
                if (isAllowHalfClosure(config())) {
                    shutdownInput();
                    pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE);
                } else {
                    close(voidPromise());
                }
            } else if (!inputClosedSeenErrorOnRead) {
                inputClosedSeenErrorOnRead = true;
                pipeline.fireUserEventTriggered(ChannelInputShutdownReadComplete.INSTANCE);
            }
        }

        private void handleReadException(ChannelPipeline pipeline, ByteBuf byteBuf, Throwable cause, boolean close,
                RecvByteBufAllocator.Handle allocHandle) {
            if (byteBuf != null) {
                if (byteBuf.isReadable()) {
                    readPending = false;
                    try {
                        pipeline.fireChannelRead(byteBuf);
                    } catch (Exception e) {
                        cause.addSuppressed(e);
                    }
                } else {

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free