public static void main(String[] args) throws InterruptedException, IOException { try { IOReactorConfig config = IOReactorConfig.custom().setSoTimeout(15000).setTcpNoDelay(true).build(); final HttpServer server = ServerBootstrap.bootstrap().setListenerPort(PORT).setServerInfo("Test/1.1").setIOReactorConfig(config).setExceptionLogger(ExceptionLogger.STD_ERR).registerHandler("*", new HTTPTimeHandler()).create(); server.start(); System.out.println("Server started"); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { System.out.println("Server shutdown requested"); server.shutdown(5, TimeUnit.SECONDS); } }); server.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); } finally { System.out.println("Server shutdown"); } }
@SneakyThrows public NioServer( int port, int workers ) { this.port = port; this.mapper.register( "/static/*", new NioClasspathResourceHandler( "/static", "/WEB-INF" ) ); val ioReactorConfig = IOReactorConfig.custom().setIoThreadCount( workers ).build(); val httpProcessor = HttpProcessorBuilder.create() .add( new ResponseDate() ) .add( new ResponseServer( "OAP Server/1.0" ) ) .add( new ResponseContent() ) .add( new ResponseConnControl() ) .build(); SSLContext sslContext = getSslContext( port ); server = ServerBootstrap.bootstrap() .setListenerPort( port ) .setServerInfo( "OAP Server/1.0" ) .setConnectionReuseStrategy( DefaultClientConnectionReuseStrategy.INSTANCE ) .setHttpProcessor( httpProcessor ) .setIOReactorConfig( ioReactorConfig ) .setSslContext( sslContext ) .setExceptionLogger( ex -> log.debug( ex.getMessage(), ex ) ) .setHandlerMapper( mapper ) .create(); }