Package org.apache.http.impl.nio.client

Examples of org.apache.http.impl.nio.client.CloseableHttpAsyncClient


            restartReactor();
        }
    }

    private void restartReactor() {
        CloseableHttpAsyncClient client2 = client;
        resetVars();
        shutdown(client2);
    }
View Full Code Here


  public void afterPropertiesSet() {
    startAsyncClient();
  }

  private void startAsyncClient() {
        CloseableHttpAsyncClient asyncClient = getHttpAsyncClient();
    if (!asyncClient.isRunning()) {
      asyncClient.start();
    }
  }
View Full Code Here

    RequestConfig requestConfig = RequestConfig.custom().build();
    HttpAsyncClientBuilder builder = HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig);
    // default is 2 per host which won't let us monitor multiple directories
    builder.setMaxConnPerRoute(Integer.MAX_VALUE);
    builder.setMaxConnTotal(Integer.MAX_VALUE);
    CloseableHttpAsyncClient httpClient = builder.build();
    httpClient.start();
    return httpClient;
  }
View Full Code Here

        .setSocketTimeout(SOCKET_TIMEOUT)
        .setConnectTimeout(CONNECT_TIMEOUT).build();
    // don't reuse connections
    NoConnectionReuseStrategy reuseStrategy = new NoConnectionReuseStrategy();

    CloseableHttpAsyncClient asyncClient = HttpAsyncClients.custom()
        .setConnectionReuseStrategy(reuseStrategy)
        .setDefaultRequestConfig(requestConfig).build();
    asyncClient.start();
    return asyncClient;
  }
View Full Code Here

            restartReactor();
        }
    }

    private void restartReactor() {
        CloseableHttpAsyncClient client2 = client;
        resetVars();
        shutdown(client2);
    }
View Full Code Here

      listSize = limit;
  
      RequestConfig requestConfig = RequestConfig.custom()
          .setSocketTimeout(3000)
          .setConnectTimeout(3000).build();
      CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
          .setDefaultRequestConfig(requestConfig)
          .build();
      try {
        httpclient.start();
        double requestIndex = (double)limit/100;
        int period = (int)Math.ceil(requestIndex);
        final HttpGet[] requests = new HttpGet[period];
        for (int i = 0; i < period; i++) {
          requests[i] = new HttpGet(ARTICLELIST_URL_STRING + "/start:" + i*100);
        }
        final CountDownLatch latch = new CountDownLatch(requests.length);
        stringBuilder.append("<ol>");
        for (final HttpGet request: requests) {
          httpclient.execute(request, new FutureCallback<HttpResponse>() {
            public void completed(final HttpResponse response) {
              BasicResponseHandler handler = new BasicResponseHandler();
              latch.countDown();
              stringBuilder.append("<li>" + request.getRequestLine() + "->" + response.getStatusLine() + "</li>");
              System.out.println(request.getRequestLine() + "->" + response.getStatusLine());
            }
            public void failed(final Exception ex) {
              latch.countDown();
              System.out.println(request.getRequestLine() + "->" + ex);
            }
            public void cancelled() {
              latch.countDown();
              System.out.println(request.getRequestLine() + "cancelled");
            }
          });
        }
        latch.await();
        System.out.println("Shutting down");
      } finally {
        try {
          httpclient.close();
        } catch(Exception e) {}
      }
      System.out.println("Done");
      stringBuilder.append("</ol>");
        return stringBuilder.toString().getBytes();
View Full Code Here

      listSize = limit;
  
      RequestConfig requestConfig = RequestConfig.custom()
          .setSocketTimeout(3000)
          .setConnectTimeout(3000).build();
      CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
          .setDefaultRequestConfig(requestConfig)
          .build();
      try {
        httpclient.start();
        double requestIndex = (double)limit/100;
        int period = (int)Math.ceil(requestIndex);
        final HttpGet[] requests = new HttpGet[period];
        for (int i = 0; i < period; i++) {
          requests[i] = new HttpGet(ARTICLELIST_URL_STRING + "/start:" + i*100);
        }
        final CountDownLatch latch = new CountDownLatch(requests.length);
        // stringBuilder.append("<ol>");
        for (final HttpGet request: requests) {
          httpclient.execute(request, new FutureCallback<HttpResponse>() {
            public void completed(final HttpResponse response) {
              BasicResponseHandler handler = new BasicResponseHandler();
              try {
                extract(handler.handleResponse(response));
              } catch (Exception e)  {
                System.out.println("ERROR: skipping");
              }
              latch.countDown();
              System.out.println(request.getRequestLine() + "->" + response.getStatusLine());
            }
            public void failed(final Exception ex) {
              latch.countDown();
              System.out.println(request.getRequestLine() + "->" + ex);
            }
            public void cancelled() {
              latch.countDown();
              System.out.println(request.getRequestLine() + "cancelled");
            }
          });
        }
        latch.await();
        System.out.println("Shutting down");
      } finally {
        try {
          httpclient.close();
        } catch(Exception e) {}
      }
      System.out.println("Done");
      // stringBuilder.append("</ol>");
      ObjectMapper jsonOutputMapper = new ObjectMapper();
View Full Code Here

    static final Gson gson = new GsonBuilder().create();

    static CloseableHttpAsyncClient buildDefaultHttpClient() {
        // TODO: Increase timeout??
        RequestConfig requestConfig = RequestConfig.custom().build();
        CloseableHttpAsyncClient httpClient = HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig).build();
        httpClient.start();
        return httpClient;
    }
View Full Code Here

TOP

Related Classes of org.apache.http.impl.nio.client.CloseableHttpAsyncClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.