Example usage for org.apache.http.nio.protocol AsyncNHttpClientHandler AsyncNHttpClientHandler

List of usage examples for org.apache.http.nio.protocol AsyncNHttpClientHandler AsyncNHttpClientHandler

Introduction

In this page you can find the example usage for org.apache.http.nio.protocol AsyncNHttpClientHandler AsyncNHttpClientHandler.

Prototype

public AsyncNHttpClientHandler(final HttpProcessor httpProcessor,
            final NHttpRequestExecutionHandler execHandler, final ConnectionReuseStrategy connStrategy,
            final ByteBufferAllocator allocator, final HttpParams params) 

Source Link

Usage

From source file:net.spy.memcached.CouchbaseConnection.java

private List<CouchbaseNode> createConnections(List<InetSocketAddress> addrs) throws IOException {
    List<CouchbaseNode> nodeList = new LinkedList<CouchbaseNode>();

    for (InetSocketAddress a : addrs) {
        HttpParams params = new SyncBasicHttpParams();
        params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
                .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000)
                .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
                .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
                .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
                .setParameter(CoreProtocolPNames.USER_AGENT, "Spymemcached Client/1.1");

        HttpProcessor httpproc = new ImmutableHttpProcessor(
                new HttpRequestInterceptor[] { new RequestContent(), new RequestTargetHost(),
                        new RequestConnControl(), new RequestUserAgent(), new RequestExpectContinue(), });

        AsyncNHttpClientHandler protocolHandler = new AsyncNHttpClientHandler(httpproc,
                new MyHttpRequestExecutionHandler(), new DefaultConnectionReuseStrategy(),
                new DirectByteBufferAllocator(), params);
        protocolHandler.setEventListener(new EventLogger());

        AsyncConnectionManager connMgr = new AsyncConnectionManager(new HttpHost(a.getHostName(), a.getPort()),
                NUM_CONNS, protocolHandler, params);
        getLogger().info("Added %s to connect queue", a);

        CouchbaseNode node = connFactory.createCouchDBNode(a, connMgr);
        node.init();/*from   ww  w  .ja v a2  s  .c  o  m*/
        nodeList.add(node);
    }

    return nodeList;
}

From source file:com.couchbase.client.ViewNodeTest.java

private AsyncConnectionManager createConMgr(String host, int port) throws IOReactorException {
    HttpHost target = new HttpHost(host, port);
    int maxConnections = 1;

    HttpParams params = new SyncBasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.USER_AGENT, "Couchbase Java Client 1.1");

    HttpProcessor httpproc = new ImmutableHttpProcessor(
            new HttpRequestInterceptor[] { new RequestContent(), new RequestTargetHost(),
                    new RequestConnControl(), new RequestUserAgent(), new RequestExpectContinue(), });

    AsyncNHttpClientHandler protocolHandler = new AsyncNHttpClientHandler(httpproc,
            new ViewNode.MyHttpRequestExecutionHandler(), new DefaultConnectionReuseStrategy(),
            new DirectByteBufferAllocator(), params);

    protocolHandler.setEventListener(new ViewNode.EventLogger());
    RequeueOpCallback callback = mock(RequeueOpCallback.class);
    AsyncConnectionManager manager = new AsyncConnectionManager(target, maxConnections, protocolHandler, params,
            callback);//from w  w w.  j  a va  2s . c om

    return manager;
}

From source file:com.couchbase.client.ViewConnection.java

/**
 * Create ViewNode connections and queue them up for connect.
 *
 * This method also defines the connection params for each connection,
 * including the default settings like timeouts and the user agent string.
 *
 * @param addrs addresses of all the nodes it should connect to.
 * @return Returns a list of the ViewNodes.
 * @throws IOException/*from   w  ww  .  ja  va 2 s  . co m*/
 */
private List<ViewNode> createConnections(List<InetSocketAddress> addrs) throws IOException {

    List<ViewNode> nodeList = new LinkedList<ViewNode>();

    for (InetSocketAddress a : addrs) {
        HttpParams params = new SyncBasicHttpParams();
        params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
                .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000)
                .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
                .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
                .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
                .setParameter(CoreProtocolPNames.USER_AGENT, "Couchbase Java Client 1.0.2");

        HttpProcessor httpproc = new ImmutableHttpProcessor(
                new HttpRequestInterceptor[] { new RequestContent(), new RequestTargetHost(),
                        new RequestConnControl(), new RequestUserAgent(), new RequestExpectContinue(), });

        AsyncNHttpClientHandler protocolHandler = new AsyncNHttpClientHandler(httpproc,
                new MyHttpRequestExecutionHandler(), new DefaultConnectionReuseStrategy(),
                new DirectByteBufferAllocator(), params);
        protocolHandler.setEventListener(new EventLogger());

        AsyncConnectionManager connMgr = new AsyncConnectionManager(new HttpHost(a.getHostName(), a.getPort()),
                NUM_CONNS, protocolHandler, params, new RequeueOpCallback(this));
        getLogger().info("Added %s to connect queue", a.getHostName());

        ViewNode node = connFactory.createViewNode(a, connMgr);
        node.init();
        nodeList.add(node);
    }

    return nodeList;
}

From source file:com.alibaba.openapi.client.rpc.AlibabaClientReactor.java

private void createIOEventDispatch(ClientPolicy policy, HttpParams params)
        throws NoSuchAlgorithmException, KeyManagementException {
    HttpProcessor httpproc = createHttpProcessor();
    ByteBufferAllocator allocator = new HeapByteBufferAllocator();
    ////HTTP I/O?I/O???I/O?HTTP???NHttpClientHandlerNHttpServiceHandler?HTTP??HTTP???(handler).
    AsyncNHttpClientHandler handler = new AsyncNHttpClientHandler(httpproc,
            new AliNHttpRequstExecutionHandler(new ProtocolProvider(policy), allocator),
            new DefaultConnectionReuseStrategy(), allocator, params);
    //        BufferingHttpClientHandler handler = new BufferingHttpClientHandler(httpproc, new MyHttpRequestExecutionHandler(),
    //                new DefaultConnectionReuseStrategy(), params);
    handler.setEventListener(new EventLogger());
    SSLContext sslcontext = SSLContext.getInstance("TLS");
    sslcontext.init(null, new TrustManager[] { new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }/*ww  w  .j  av  a2 s .c  om*/

        public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1)
                throws CertificateException {
        }

        public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1)
                throws CertificateException {
        }
    } }, new SecureRandom());
    sslcontext.getClientSessionContext().setSessionCacheSize(200);
    sslcontext.getClientSessionContext().setSessionTimeout(30000);
    //dispatchIOhandler
    ioEventDispatch = new AutoSSLClientIOEventDispatch(handler, sslcontext, params);
}