NioMessageUnsafe Class — netty Architecture
Architecture documentation for the NioMessageUnsafe class in AbstractNioMessageChannel.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 8eba98e8_3c2a_def1_f7a1_96325e814899["NioMessageUnsafe"] 7f2b3e34_70a9_a8fb_c486_84a47e9eb723["AbstractNioMessageChannel.java"] 8eba98e8_3c2a_def1_f7a1_96325e814899 -->|defined in| 7f2b3e34_70a9_a8fb_c486_84a47e9eb723 fdaeb6e3_b1a0_895b_8d25_cbfe40e8b726["read()"] 8eba98e8_3c2a_def1_f7a1_96325e814899 -->|method| fdaeb6e3_b1a0_895b_8d25_cbfe40e8b726
Relationship Graph
Source Code
transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java lines 65–130
private final class NioMessageUnsafe extends AbstractNioUnsafe {
private final List<Object> readBuf = new ArrayList<Object>();
@Override
public void read() {
assert eventLoop().inEventLoop();
final ChannelConfig config = config();
final ChannelPipeline pipeline = pipeline();
final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
allocHandle.reset(config);
boolean closed = false;
Throwable exception = null;
try {
try {
do {
int localRead = doReadMessages(readBuf);
if (localRead == 0) {
break;
}
if (localRead < 0) {
closed = true;
break;
}
allocHandle.incMessagesRead(localRead);
} while (continueReading(allocHandle));
} catch (Throwable t) {
exception = t;
}
int size = readBuf.size();
for (int i = 0; i < size; i ++) {
readPending = false;
pipeline.fireChannelRead(readBuf.get(i));
}
readBuf.clear();
allocHandle.readComplete();
pipeline.fireChannelReadComplete();
if (exception != null) {
closed = closeOnReadError(exception);
pipeline.fireExceptionCaught(exception);
}
if (closed) {
inputShutdown = true;
if (isOpen()) {
close(voidPromise());
}
}
} finally {
// Check if there is a readPending which was not processed yet.
// This could be for two reasons:
// * The user called Channel.read() or ChannelHandlerContext.read() in channelRead(...) method
// * The user called Channel.read() or ChannelHandlerContext.read() in channelReadComplete(...) method
//
// See https://github.com/netty/netty/issues/2254
if (!readPending && !config.isAutoRead()) {
removeReadOp();
}
}
}
}
Source
Frequently Asked Questions
What is the NioMessageUnsafe class?
NioMessageUnsafe is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java.
Where is NioMessageUnsafe defined?
NioMessageUnsafe is defined in transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java at line 65.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free