当前位置: 首页>>代码示例>>Java>>正文


Java ServerBootstrap类代码示例

本文整理汇总了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");
   }
}
 
开发者ID:developerSid,项目名称:AwesomeJavaLibraryExamples,代码行数:28,代码来源:HTTPServer.java

示例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();
}
 
开发者ID:oaplatform,项目名称:oap,代码行数:28,代码来源:NioServer.java


注:本文中的org.apache.http.impl.nio.bootstrap.ServerBootstrap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。