main() — netty Function Reference
Architecture documentation for the main() function in QuicServerSoReusePortExample.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 05d3f0f6_a57f_f271_99dd_01ab54393c9e["main()"] 9e1e7ace_1eff_7ddc_7b13_1f3aa2d65de2["QuicServerSoReusePortExample"] 05d3f0f6_a57f_f271_99dd_01ab54393c9e -->|defined in| 9e1e7ace_1eff_7ddc_7b13_1f3aa2d65de2 style 05d3f0f6_a57f_f271_99dd_01ab54393c9e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-native-quic/src/test/java/io/netty/handler/codec/quic/example/QuicServerSoReusePortExample.java lines 56–157
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();
// We will bind one socket to each EventLoopGroup.
int numCores = NettyRuntime.availableProcessors();
EventLoopGroup group = new MultiThreadIoEventLoopGroup(numCores, EpollIoHandler.newFactory());
try {
Bootstrap bs = new Bootstrap().group(group)
.channel(EpollDatagramChannel.class)
.option(EpollChannelOption.SO_REUSEPORT, true)
// Use QuicCodecDispatcher as we use SO_REUSEPORT and bind multiple times to the same port.
.handler(new QuicCodecDispatcher() {
@Override
protected void initChannel(Channel channel, int localConnectionIdLength,
QuicConnectionIdGenerator idGenerator) {
ChannelHandler codec = new QuicServerCodecBuilder()
.localConnectionIdLength(localConnectionIdLength)
.connectionIdAddressGenerator(idGenerator)
.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());
}
});
}
@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();
}
}
Domain
Subdomains
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/QuicServerSoReusePortExample.java.
Where is main() defined?
main() is defined in codec-native-quic/src/test/java/io/netty/handler/codec/quic/example/QuicServerSoReusePortExample.java at line 56.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free