ServerBootstrapAcceptor Class — netty Architecture
Architecture documentation for the ServerBootstrapAcceptor class in ServerBootstrap.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD f32a5269_a3d9_354a_3815_e297ee3f3e29["ServerBootstrapAcceptor"] 2d8678e4_c020_b8ee_69ca_75f537a75f47["ServerBootstrap.java"] f32a5269_a3d9_354a_3815_e297ee3f3e29 -->|defined in| 2d8678e4_c020_b8ee_69ca_75f537a75f47 ea714223_dadb_7507_4730_191aee88a62f["ServerBootstrapAcceptor()"] f32a5269_a3d9_354a_3815_e297ee3f3e29 -->|method| ea714223_dadb_7507_4730_191aee88a62f 62382788_d26c_b56b_2499_06e1b104f9c3["channelRead()"] f32a5269_a3d9_354a_3815_e297ee3f3e29 -->|method| 62382788_d26c_b56b_2499_06e1b104f9c3 0b873b52_fd29_cffc_2068_8b007dde392f["forceClose()"] f32a5269_a3d9_354a_3815_e297ee3f3e29 -->|method| 0b873b52_fd29_cffc_2068_8b007dde392f 3cdc83af_6f42_7ad0_b2c2_4d7c213870c4["exceptionCaught()"] f32a5269_a3d9_354a_3815_e297ee3f3e29 -->|method| 3cdc83af_6f42_7ad0_b2c2_4d7c213870c4
Relationship Graph
Source Code
transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java lines 189–275
private static class ServerBootstrapAcceptor extends ChannelInboundHandlerAdapter {
private final EventLoopGroup childGroup;
private final ChannelHandler childHandler;
private final Entry<ChannelOption<?>, Object>[] childOptions;
private final Entry<AttributeKey<?>, Object>[] childAttrs;
private final Runnable enableAutoReadTask;
private final Collection<ChannelInitializerExtension> extensions;
ServerBootstrapAcceptor(
final Channel channel, EventLoopGroup childGroup, ChannelHandler childHandler,
Entry<ChannelOption<?>, Object>[] childOptions, Entry<AttributeKey<?>, Object>[] childAttrs,
Collection<ChannelInitializerExtension> extensions) {
this.childGroup = childGroup;
this.childHandler = childHandler;
this.childOptions = childOptions;
this.childAttrs = childAttrs;
this.extensions = extensions;
// Task which is scheduled to re-enable auto-read.
// It's important to create this Runnable before we try to submit it as otherwise the URLClassLoader may
// not be able to load the class because of the file limit it already reached.
//
// See https://github.com/netty/netty/issues/1328
enableAutoReadTask = new Runnable() {
@Override
public void run() {
channel.config().setAutoRead(true);
}
};
}
@Override
@SuppressWarnings("unchecked")
public void channelRead(ChannelHandlerContext ctx, Object msg) {
final Channel child = (Channel) msg;
child.pipeline().addLast(childHandler);
try {
setChannelOptions(child, childOptions, logger);
} catch (Throwable cause) {
forceClose(child, cause);
return;
}
setAttributes(child, childAttrs);
if (!extensions.isEmpty()) {
for (ChannelInitializerExtension extension : extensions) {
try {
extension.postInitializeServerChildChannel(child);
} catch (Exception e) {
logger.warn("Exception thrown from postInitializeServerChildChannel", e);
}
}
}
try {
childGroup.register(child).addListener(future -> {
if (!future.isSuccess()) {
forceClose(child, future.cause());
}
});
} catch (Throwable t) {
forceClose(child, t);
}
}
private static void forceClose(Channel child, Throwable t) {
child.unsafe().closeForcibly();
logger.warn("Failed to register an accepted channel: {}", child, t);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
final ChannelConfig config = ctx.channel().config();
if (config.isAutoRead()) {
// stop accept new connections for 1 second to allow the channel to recover
// See https://github.com/netty/netty/issues/1328
config.setAutoRead(false);
ctx.channel().eventLoop().schedule(enableAutoReadTask, 1, TimeUnit.SECONDS);
Source
Frequently Asked Questions
What is the ServerBootstrapAcceptor class?
ServerBootstrapAcceptor is a class in the netty codebase, defined in transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java.
Where is ServerBootstrapAcceptor defined?
ServerBootstrapAcceptor is defined in transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java at line 189.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free