main() — netty Function Reference
Architecture documentation for the main() function in QuicServerExample.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 1abb7b1d_92a6_cce6_9ab0_fef90fc51d4c["main()"] 7be62b50_79de_d916_a0d7_e87717583f43["QuicServerExample"] 1abb7b1d_92a6_cce6_9ab0_fef90fc51d4c -->|defined in| 7be62b50_79de_d916_a0d7_e87717583f43 style 1abb7b1d_92a6_cce6_9ab0_fef90fc51d4c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-native-quic/src/test/java/io/netty/handler/codec/quic/example/QuicServerExample.java lines 50–125
public static void main(String[] args) throws Exception {
SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate();
QuicSslContext context = QuicSslContextBuilder.forServer(
selfSignedCertificate.privateKey(), null, selfSignedCertificate.certificate())
.applicationProtocols("http/0.9").build();
EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
ChannelHandler codec = new QuicServerCodecBuilder().sslContext(context)
.maxIdleTimeout(5000, TimeUnit.MILLISECONDS)
// Configure some limits for the maximal number of streams (and the data) that we want to handle.
.initialMaxData(10000000)
.initialMaxStreamDataBidirectionalLocal(1000000)
.initialMaxStreamDataBidirectionalRemote(1000000)
.initialMaxStreamsBidirectional(100)
.initialMaxStreamsUnidirectional(100)
.activeMigration(true)
// Setup a token handler. In a production system you would want to implement and provide your custom
// one.
.tokenHandler(InsecureQuicTokenHandler.INSTANCE)
// ChannelHandler that is added into QuicChannel pipeline.
.handler(new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) {
QuicChannel channel = (QuicChannel) ctx.channel();
// Create streams etc..
}
public void channelInactive(ChannelHandlerContext ctx) {
((QuicChannel) ctx.channel()).collectStats().addListener(f -> {
if (f.isSuccess()) {
LOGGER.info("Connection closed: {}", f.getNow());
}
//only test for first connection
ctx.channel().parent().close();
});
}
@Override
public boolean isSharable() {
return true;
}
})
.streamHandler(new ChannelInitializer<QuicStreamChannel>() {
@Override
protected void initChannel(QuicStreamChannel ch) {
// Add a LineBasedFrameDecoder here as we just want to do some simple HTTP 0.9 handling.
ch.pipeline().addLast(new LineBasedFrameDecoder(1024))
.addLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ByteBuf byteBuf = (ByteBuf) msg;
try {
if (byteBuf.toString(CharsetUtil.US_ASCII).trim().equals("GET /")) {
ByteBuf buffer = ctx.alloc().directBuffer();
buffer.writeCharSequence("Hello World!\r\n", CharsetUtil.US_ASCII);
// Write the buffer and shutdown the output by writing a FIN.
ctx.writeAndFlush(buffer).addListener(QuicStreamChannel.SHUTDOWN_OUTPUT);
}
} finally {
byteBuf.release();
}
}
});
}
}).build();
try {
Bootstrap bs = new Bootstrap();
Channel channel = bs.group(group)
.channel(NioDatagramChannel.class)
.handler(codec)
.bind(new InetSocketAddress(9999)).sync().channel();
channel.closeFuture().sync();
} finally {
group.shutdownGracefully();
}
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does main() do?
main() is a function in the netty codebase, defined in codec-native-quic/src/test/java/io/netty/handler/codec/quic/example/QuicServerExample.java.
Where is main() defined?
main() is defined in codec-native-quic/src/test/java/io/netty/handler/codec/quic/example/QuicServerExample.java at line 50.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free