QuicServerSoReusePortExample Class — netty Architecture
Architecture documentation for the QuicServerSoReusePortExample class in QuicServerSoReusePortExample.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 9e1e7ace_1eff_7ddc_7b13_1f3aa2d65de2["QuicServerSoReusePortExample"] cb386f06_f537_f57e_ea3c_020361c77a5e["QuicServerSoReusePortExample.java"] 9e1e7ace_1eff_7ddc_7b13_1f3aa2d65de2 -->|defined in| cb386f06_f537_f57e_ea3c_020361c77a5e 71f6decb_946e_4b6f_c058_07ad251183e0["QuicServerSoReusePortExample()"] 9e1e7ace_1eff_7ddc_7b13_1f3aa2d65de2 -->|method| 71f6decb_946e_4b6f_c058_07ad251183e0 05d3f0f6_a57f_f271_99dd_01ab54393c9e["main()"] 9e1e7ace_1eff_7ddc_7b13_1f3aa2d65de2 -->|method| 05d3f0f6_a57f_f271_99dd_01ab54393c9e
Relationship Graph
Source Code
codec-native-quic/src/test/java/io/netty/handler/codec/quic/example/QuicServerSoReusePortExample.java lines 50–158
public final class QuicServerSoReusePortExample {
private static final InternalLogger LOGGER = InternalLoggerFactory.getInstance(QuicServerSoReusePortExample.class);
private QuicServerSoReusePortExample() { }
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(
Source
Frequently Asked Questions
What is the QuicServerSoReusePortExample class?
QuicServerSoReusePortExample is a class in the netty codebase, defined in codec-native-quic/src/test/java/io/netty/handler/codec/quic/example/QuicServerSoReusePortExample.java.
Where is QuicServerSoReusePortExample defined?
QuicServerSoReusePortExample is defined in codec-native-quic/src/test/java/io/netty/handler/codec/quic/example/QuicServerSoReusePortExample.java at line 50.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free