本文整理匯總了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();
}