title: how to get a guava ListenableFuture from a callback?
body: <p>I want to use the apache async http client to make asynchronous http calls, in order to run more than one call per thread. </p>
  
  <p>The code is listed here: <a href="https://hc.apache.org/httpcomponents-asyncclient-dev/quickstart.html" rel="nofollow noreferrer">https://hc.apache.org/httpcomponents-asyncclient-dev/quickstart.html</a></p>
  
  <pre><code>CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
  
  // Start the client
  httpclient.start();
  
  // One most likely would want to use a callback for operation result
  final CountDownLatch latch1 = new CountDownLatch(1);
  final HttpGet request2 = new HttpGet("http://www.apache.org/");
  httpclient.execute(request2, new FutureCallback&lt;HttpResponse&gt;() {
  
      public void completed(final HttpResponse response2) {
          latch1.countDown();
          System.out.println(request2.getRequestLine() + "-&gt;" + response2.getStatusLine());
      }
  
      public void failed(final Exception ex) {
          latch1.countDown();
          System.out.println(request2.getRequestLine() + "-&gt;" + ex);
      }
  
      public void cancelled() {
          latch1.countDown();
          System.out.println(request2.getRequestLine() + " cancelled");
      }
  
  });
  latch1.await();
  </code></pre>
  
  <p>In the last time i programmed in nodejs and was very happy with the promise approach. The closest item i found was ListenableFuture from GUAVA. (I can't use Java 8). The question is how to convert the callback approach to ListenableFuture.</p>
  
  <p>In nodejs this would be easy because in the callback i could just call the resolve function. I am not aware how to do this in Java and i did not find in google how to do this. </p>