Java 类org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory 实例源码

项目:nio-benchmark    文件:AsyncServer.java   
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);
}
项目:LibOppo    文件:OppoMessenger.java   
@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 + '/';
}