Home / Class/ AbstractKQueueStreamChannel Class — netty Architecture

AbstractKQueueStreamChannel Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  d154050d_32bb_fde7_fa64_5c82411c48d6["AbstractKQueueStreamChannel"]
  dec001f2_dbaa_7715_de1b_ddd2dc9c85f8["AbstractKQueueStreamChannel.java"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|defined in| dec001f2_dbaa_7715_de1b_ddd2dc9c85f8
  0ef65da8_976d_08c6_4703_bf1ded4d4de1["AbstractKQueueStreamChannel()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| 0ef65da8_976d_08c6_4703_bf1ded4d4de1
  f0fdf025_625e_6320_e5b6_ff9754828189["AbstractKQueueUnsafe()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| f0fdf025_625e_6320_e5b6_ff9754828189
  587951c7_3ab5_3afd_4199_656fe293b16a["ChannelMetadata()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| 587951c7_3ab5_3afd_4199_656fe293b16a
  ffda4400_32a8_bde7_1ee3_64222fbdad60["writeBytes()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| ffda4400_32a8_bde7_1ee3_64222fbdad60
  b80a7867_955d_4885_8e07_5d2861489576["adjustMaxBytesPerGatheringWrite()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| b80a7867_955d_4885_8e07_5d2861489576
  9c9d9b4b_f693_63b7_ac81_c2fc0c01e420["writeBytesMultiple()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| 9c9d9b4b_f693_63b7_ac81_c2fc0c01e420
  0e756965_236e_58d1_9f65_591a78844358["writeDefaultFileRegion()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| 0e756965_236e_58d1_9f65_591a78844358
  e244d96f_44c9_5ac8_fe4f_c9810b5e3a63["writeFileRegion()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| e244d96f_44c9_5ac8_fe4f_c9810b5e3a63
  c37b6b64_00c0_2805_a64f_69d2f1283642["doWrite()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| c37b6b64_00c0_2805_a64f_69d2f1283642
  bd3a0c39_614b_daae_7204_b68d27ee6ab0["doWriteSingle()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| bd3a0c39_614b_daae_7204_b68d27ee6ab0
  5e722992_098a_76fd_00b1_7e52bc6b14a4["doWriteMultiple()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| 5e722992_098a_76fd_00b1_7e52bc6b14a4
  4d5138fc_023c_2036_1ae1_a5eac0a6eb13["Object()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| 4d5138fc_023c_2036_1ae1_a5eac0a6eb13
  c1d36cec_2690_f2db_f77d_5a819d7016a4["doShutdownOutput()"]
  d154050d_32bb_fde7_fa64_5c82411c48d6 -->|method| c1d36cec_2690_f2db_f77d_5a819d7016a4

Relationship Graph

Source Code

transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/AbstractKQueueStreamChannel.java lines 52–615

public abstract class AbstractKQueueStreamChannel extends AbstractKQueueChannel implements DuplexChannel {
    private static final InternalLogger logger = InternalLoggerFactory.getInstance(AbstractKQueueStreamChannel.class);
    private static final ChannelMetadata METADATA = new ChannelMetadata(false, 16);
    private static final String EXPECTED_TYPES =
            " (expected: " + StringUtil.simpleClassName(ByteBuf.class) + ", " +
                    StringUtil.simpleClassName(DefaultFileRegion.class) + ')';
    private WritableByteChannel byteChannel;
    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.
            ((AbstractKQueueUnsafe) unsafe()).flush0();
        }
    };

    AbstractKQueueStreamChannel(Channel parent, BsdSocket fd, boolean active) {
        super(parent, fd, active);
    }

    AbstractKQueueStreamChannel(Channel parent, BsdSocket fd, SocketAddress remote) {
        super(parent, fd, remote);
    }

    AbstractKQueueStreamChannel(BsdSocket fd) {
        this(null, fd, isSoErrorZero(fd));
    }

    @Override
    protected AbstractKQueueUnsafe newUnsafe() {
        return new KQueueStreamUnsafe();
    }

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

    /**
     * Write bytes form the given {@link ByteBuf} to the underlying {@link java.nio.channels.Channel}.
     * @param in the collection which contains objects to write.
     * @param buf the {@link ByteBuf} from which the bytes should be written
     * @return The value that should be decremented from the write quantum which starts at
     * {@link ChannelConfig#getWriteSpinCount()}. The typical use cases are as follows:
     * <ul>
     *     <li>0 - if no write was attempted. This is appropriate if an empty {@link ByteBuf} (or other empty content)
     *     is encountered</li>
     *     <li>1 - if a single call to write data was made to the OS</li>
     *     <li>{@link ChannelUtils#WRITE_STATUS_SNDBUF_FULL} - if an attempt to write data was made to the OS, but no
     *     data was accepted</li>
     * </ul>
     */
    private int writeBytes(ChannelOutboundBuffer in, ByteBuf buf) throws Exception {
        int readableBytes = buf.readableBytes();
        if (readableBytes == 0) {
            in.remove();
            return 0;
        }

        if (buf.hasMemoryAddress() || buf.nioBufferCount() == 1) {
            return doWriteBytes(in, buf);
        } else {
            ByteBuffer[] nioBuffers = buf.nioBuffers();
            return writeBytesMultiple(in, nioBuffers, nioBuffers.length, readableBytes,
                    config().getMaxBytesPerGatheringWrite());
        }
    }

    private void adjustMaxBytesPerGatheringWrite(long attempted, long written, long oldMaxBytesPerGatheringWrite) {
        // By default we track the SO_SNDBUF when ever it is explicitly set. However some OSes may dynamically change
        // SO_SNDBUF (and other characteristics that determine how much data can be written at once) so we should try
        // make a best effort to adjust as OS behavior changes.
        if (attempted == written) {
            if (attempted << 1 > oldMaxBytesPerGatheringWrite) {
                config().setMaxBytesPerGatheringWrite(attempted << 1);
            }
        } else if (attempted > MAX_BYTES_PER_GATHERING_WRITE_ATTEMPTED_LOW_THRESHOLD && written < attempted >>> 1) {
            config().setMaxBytesPerGatheringWrite(attempted >>> 1);
        }
    }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free