當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultNHttpServerConnection類代碼示例

本文整理匯總了Java中org.apache.http.impl.nio.DefaultNHttpServerConnection的典型用法代碼示例。如果您正苦於以下問題:Java DefaultNHttpServerConnection類的具體用法?Java DefaultNHttpServerConnection怎麽用?Java DefaultNHttpServerConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DefaultNHttpServerConnection類屬於org.apache.http.impl.nio包,在下文中一共展示了DefaultNHttpServerConnection類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import org.apache.http.impl.nio.DefaultNHttpServerConnection; //導入依賴的package包/類
public void start() throws Exception {
	// Create HTTP protocol basic processing chain
	HttpProcessor httpProcessor = HttpProcessorBuilder.create()
			.add(new ResponseDate()).add(new ResponseContent())
			.add(new ResponseConnControl()).build();
	// Create server
	HttpAsyncService protocolHandler = new HttpAsyncService(httpProcessor,
			uriMapper);
	NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory = new DefaultNHttpServerConnectionFactory();
	IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(
			protocolHandler, connFactory);
	IOReactorConfig config = IOReactorConfig.custom()
			.setIoThreadCount(threads).setSoReuseAddress(true).build();
	ListeningIOReactor ioReactor = new DefaultListeningIOReactor(config);
	// Start server
	ioReactor.listen(new InetSocketAddress(port));
	ioReactor.execute(ioEventDispatch);
}
 
開發者ID:fxbonnet,項目名稱:nio-benchmark,代碼行數:19,代碼來源:AsyncServer.java

示例2: OppoMessenger

import org.apache.http.impl.nio.DefaultNHttpServerConnection; //導入依賴的package包/類
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED")
public OppoMessenger(final String remoteHost, final int remotePort, final int localPort,
                     final HttpClientService httpClient)
        throws IOException {
    this.httpClient = httpClient;

    // Set up the server
    final HttpProcessor processor = HttpProcessorBuilder.create()
            .add(new ResponseContent())
            .add(new ResponseContentEncoding())
            .add(new ResponseConnControl())
            .build();

    final HttpAsyncService service = new HttpAsyncService(processor, mapper);
    final NHttpConnectionFactory<DefaultNHttpServerConnection> connectionFactory = new DefaultNHttpServerConnectionFactory(ConnectionConfig.DEFAULT);
    final IOEventDispatch dispatch = new DefaultHttpServerIODispatch(service, connectionFactory);

    server = new DefaultListeningIOReactor(IOReactorConfig.DEFAULT);
    server.listen(new InetSocketAddress(localPort));

    new Thread(new Runnable() {
        @Override public void run() {
            try {
                server.execute(dispatch);
            } catch (final IOException e) {
                logger().level(Error).message("HTTP server failed").error(e).log();
            }
        }
    }, "Oppo HTTP server");

    // Set up the client
    deviceUrlBase = "http://" + remoteHost + ':' + remotePort + '/';
}
 
開發者ID:markmckenna,項目名稱:LibOppo,代碼行數:34,代碼來源:OppoMessenger.java


注:本文中的org.apache.http.impl.nio.DefaultNHttpServerConnection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。