本文整理汇总了Java中org.apache.http.impl.nio.bootstrap.ServerBootstrap类的典型用法代码示例。如果您正苦于以下问题:Java ServerBootstrap类的具体用法?Java ServerBootstrap怎么用?Java ServerBootstrap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerBootstrap类属于org.apache.http.impl.nio.bootstrap包,在下文中一共展示了ServerBootstrap类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.http.impl.nio.bootstrap.ServerBootstrap; //导入依赖的package包/类
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");
}
}
示例2: NioServer
import org.apache.http.impl.nio.bootstrap.ServerBootstrap; //导入依赖的package包/类
@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();
}