Home / Class/ AbstractOioMessageChannel Class — netty Architecture

AbstractOioMessageChannel Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  05d0e1d1_041f_3bb0_1b63_cf10f9ca30d5["AbstractOioMessageChannel"]
  000fb419_e41d_1a48_ef90_714912c9af79["AbstractOioMessageChannel.java"]
  05d0e1d1_041f_3bb0_1b63_cf10f9ca30d5 -->|defined in| 000fb419_e41d_1a48_ef90_714912c9af79
  5babe4c6_1a02_bae5_9fa6_3605000816fd["AbstractOioMessageChannel()"]
  05d0e1d1_041f_3bb0_1b63_cf10f9ca30d5 -->|method| 5babe4c6_1a02_bae5_9fa6_3605000816fd
  654f6259_3abd_002a_bdf7_32613ed60eb2["doRead()"]
  05d0e1d1_041f_3bb0_1b63_cf10f9ca30d5 -->|method| 654f6259_3abd_002a_bdf7_32613ed60eb2
  17a6299a_a14f_2e88_94f3_ebcb9fe2d898["doReadMessages()"]
  05d0e1d1_041f_3bb0_1b63_cf10f9ca30d5 -->|method| 17a6299a_a14f_2e88_94f3_ebcb9fe2d898

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/oio/AbstractOioMessageChannel.java lines 32–113

@Deprecated
public abstract class AbstractOioMessageChannel extends AbstractOioChannel {

    private final List<Object> readBuf = new ArrayList<Object>();

    protected AbstractOioMessageChannel(Channel parent) {
        super(parent);
    }

    @Override
    protected void doRead() {
        if (!readPending) {
            // We have to check readPending here because the Runnable to read could have been scheduled and later
            // during the same read loop readPending was set to false.
            return;
        }
        // In OIO we should set readPending to false even if the read was not successful so we can schedule
        // another read on the event loop if no reads are done.
        readPending = false;

        final ChannelConfig config = config();
        final ChannelPipeline pipeline = pipeline();
        final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
        allocHandle.reset(config);

        boolean closed = false;
        Throwable exception = null;
        try {
            do {
                // Perform a read.
                int localRead = doReadMessages(readBuf);
                if (localRead == 0) {
                    break;
                }
                if (localRead < 0) {
                    closed = true;
                    break;
                }

                allocHandle.incMessagesRead(localRead);
            } while (allocHandle.continueReading());
        } catch (Throwable t) {
            exception = t;
        }

        boolean readData = false;
        int size = readBuf.size();
        if (size > 0) {
            readData = true;
            for (int i = 0; i < size; i++) {
                readPending = false;
                pipeline.fireChannelRead(readBuf.get(i));
            }
            readBuf.clear();
            allocHandle.readComplete();
            pipeline.fireChannelReadComplete();
        }

        if (exception != null) {
            if (exception instanceof IOException) {
                closed = true;
            }

            pipeline.fireExceptionCaught(exception);
        }

        if (closed) {
            if (isOpen()) {
                unsafe().close(unsafe().voidPromise());
            }
        } else if (readPending || config.isAutoRead() || !readData && isActive()) {
            // Reading 0 bytes could mean there is a SocketTimeout and no data was actually read, so we
            // should execute read() again because no data may have been read.
            read();
        }
    }

    /**
     * Read messages into the given array and return the amount which was read.
     */
    protected abstract int doReadMessages(List<Object> msgs) throws Exception;

Frequently Asked Questions

What is the AbstractOioMessageChannel class?
AbstractOioMessageChannel is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/oio/AbstractOioMessageChannel.java.
Where is AbstractOioMessageChannel defined?
AbstractOioMessageChannel is defined in transport/src/main/java/io/netty/channel/oio/AbstractOioMessageChannel.java at line 32.

Analyze Your Own Codebase

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

Try Supermodel Free