Example usage for org.apache.http.impl.nio.client CloseableHttpPipeliningClient close

List of usage examples for org.apache.http.impl.nio.client CloseableHttpPipeliningClient close

Introduction

In this page you can find the example usage for org.apache.http.impl.nio.client CloseableHttpPipeliningClient close.

Prototype

public void close() throws IOException;

Source Link

Document

Closes this stream and releases any system resources associated with it.

Usage

From source file:com.boonya.http.async.examples.nio.client.AsyncClientPipelined.java

public static void main(final String[] args) throws Exception {
    CloseableHttpPipeliningClient httpclient = HttpAsyncClients.createPipelining();
    try {// w  ww.  ja va2 s. c  o m
        httpclient.start();

        HttpHost targetHost = new HttpHost("localhost", 8080);
        HttpGet[] resquests = { new HttpGet("/docs/index.html"), new HttpGet("/docs/introduction.html"),
                new HttpGet("/docs/setup.html"), new HttpGet("/docs/config/index.html") };

        Future<List<HttpResponse>> future = httpclient.execute(targetHost,
                Arrays.<HttpRequest>asList(resquests), null);
        List<HttpResponse> responses = future.get();
        System.out.println(responses);

        System.out.println("Shutting down");
    } finally {
        httpclient.close();
    }
    System.out.println("Done");
}

From source file:httpasync.AsyncClientPipelined.java

public static void main(final String[] args) throws Exception {
    CloseableHttpPipeliningClient httpclient = HttpAsyncClients.createPipelining();
    try {//  w  w  w . j  a v  a  2s  .com
        httpclient.start();

        HttpHost targetHost = new HttpHost("money.moneydj.com", 80);
        HttpGet[] resquests = { new HttpGet("/us/basic/basic0001/Person"),
                new HttpGet("/us/basic/basic0001/AA"), new HttpGet("/us/basic/basic0001/PSG"),
                //                    new HttpGet("/docs/introduction.html"),
                //                    new HttpGet("/docs/setup.html"),
                //                    new HttpGet("/docs/config/index.html")
        };

        Future<List<HttpResponse>> future = httpclient.execute(targetHost,
                Arrays.<HttpRequest>asList(resquests), null);
        List<HttpResponse> responses = future.get();
        responses.forEach(System.out::println);

        System.out.println("Shutting down");
    } finally {
        httpclient.close();
    }
    System.out.println("Done");
}

From source file:com.boonya.http.async.examples.nio.client.AsyncClientPipelinedStreaming.java

public static void main(final String[] args) throws Exception {
    CloseableHttpPipeliningClient httpclient = HttpAsyncClients.createPipelining();
    try {/*from   w  w  w  . j  ava 2 s  .c  o m*/
        httpclient.start();

        HttpHost targetHost = new HttpHost("localhost", 8080);
        HttpGet[] resquests = { new HttpGet("/docs/index.html"), new HttpGet("/docs/introduction.html"),
                new HttpGet("/docs/setup.html"), new HttpGet("/docs/config/index.html") };

        List<MyRequestProducer> requestProducers = new ArrayList<MyRequestProducer>();
        List<MyResponseConsumer> responseConsumers = new ArrayList<MyResponseConsumer>();
        for (HttpGet request : resquests) {
            requestProducers.add(new MyRequestProducer(targetHost, request));
            responseConsumers.add(new MyResponseConsumer(request));
        }

        Future<List<Boolean>> future = httpclient.execute(targetHost, requestProducers, responseConsumers,
                null);
        future.get();
        System.out.println("Shutting down");
    } finally {
        httpclient.close();
    }
    System.out.println("Done");
}

From source file:httpasync.AsyncClientPipelinedStreaming.java

public static void a() {
    long start = System.currentTimeMillis();
    CloseableHttpPipeliningClient httpclient = HttpAsyncClients.createPipelining();
    try {//from   w w w  .  ja v a2s.c  om
        httpclient.start();

        HttpHost targetHost = new HttpHost("globalquotes.xignite.com", 80);
        //            HttpGet[] resquests = {
        //                    new HttpGet("/docs/index.html"),
        //                    new HttpGet("/docs/introduction.html"),
        //                    new HttpGet("/docs/setup.html"),
        //                    new HttpGet("/docs/config/index.html")
        //            };

        List<MyRequestProducer> requestProducers = new ArrayList<MyRequestProducer>();
        List<MyResponseConsumer> responseConsumers = new ArrayList<MyResponseConsumer>();
        String[] codes = StockParser.stockCodeList.split(",");
        //            500 * 17  ~~~~~~~~~~~~~~~ Shutting down : 12660
        //              avg=17348.1

        //            400 * 21  ~~~~~~~~~~~~~~~ Shutting down : 27476
        //              avg=18923.8

        int take = 400;
        for (int i = 0; i < codes.length / take; i++) {
            String code = Arrays.asList(codes).stream().skip(i * take).limit(take)
                    .collect(Collectors.joining(","));
            HttpGet request = new HttpGet(StockParser.uri + URLEncoder.encode(code.trim()));
            requestProducers.add(new MyRequestProducer(targetHost, request));
            responseConsumers.add(new MyResponseConsumer(request));
        }
        //            System.out.println("? = "+ responseConsumers.size());
        //            for (HttpGet request: resquests) {
        //                requestProducers.add(new MyRequestProducer(targetHost, request));
        //                responseConsumers.add(new MyResponseConsumer(request));
        //            }

        Future<List<Boolean>> future = httpclient.execute(targetHost, requestProducers, responseConsumers,
                new FutureCallback<List<Boolean>>() {
                    @Override
                    public void completed(List<Boolean> result) {
                    }

                    @Override
                    public void failed(Exception ex) {
                        ex.printStackTrace();
                    }

                    @Override
                    public void cancelled() {

                    }
                });
        future.get();
        System.out.println(take + " * " + responseConsumers.size()
                + "  ~~~~~~~~~~~~~~~ Shutting down : "
                + (System.currentTimeMillis() - start));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            httpclient.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //        System.out.println("Done");
}