當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。