1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.testsuite.svm;
17
18 import io.netty.bootstrap.ServerBootstrap;
19 import io.netty.channel.Channel;
20 import io.netty.channel.ChannelOption;
21 import io.netty.channel.EventLoopGroup;
22 import io.netty.channel.nio.NioEventLoopGroup;
23 import io.netty.channel.socket.nio.NioServerSocketChannel;
24 import io.netty.handler.logging.LogLevel;
25 import io.netty.handler.logging.LoggingHandler;
26
27
28
29
30
31 public final class HttpNativeServer {
32
33
34
35
36 private HttpNativeServer() {
37 }
38
39 public static void main(String[] args) throws Exception {
40
41 EventLoopGroup group = new NioEventLoopGroup();
42
43 boolean serverStartSucess = false;
44 try {
45 ServerBootstrap b = new ServerBootstrap();
46 b.option(ChannelOption.SO_BACKLOG, 1024);
47 b.group(group)
48 .channel(NioServerSocketChannel.class)
49 .handler(new LoggingHandler(LogLevel.INFO))
50 .childHandler(new HttpNativeServerInitializer());
51
52 Channel channel = b.bind(0).sync().channel();
53 System.err.println("Server started, will shutdown now.");
54
55 channel.close().sync();
56 serverStartSucess = true;
57 } finally {
58 group.shutdownGracefully();
59 }
60
61 System.exit(serverStartSucess ? 0 : 1);
62 }
63 }