diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java b/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java index 5abbeb307..fc245c0fc 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java @@ -27,11 +27,9 @@ package org.apache.http.examples.client; import java.io.IOException; -import java.util.List; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import org.apache.http.HttpResponse; @@ -112,20 +110,6 @@ public class ClientWithRequestFuture { HttpClientContext.create(), handler, callback); Boolean wasItOk4 = futureTask4.get(10, TimeUnit.SECONDS); System.out.println("It was ok? " + wasItOk4); - - // Multiple requests, with a callback - HttpGet request5 = new HttpGet("http://google.com"); - HttpGet request6 = new HttpGet("http://bing.com"); - HttpGet request7 = new HttpGet("http://yahoo.com"); - // using a null HttpContext here since it is optional - // the callback will be called for each request as their responses come back. - List> futureTask = requestExecService.executeMultiple( - HttpClientContext.create(), handler, callback, - 20,TimeUnit.SECONDS, request5, request6, request7); - // you can still access the futures directly, if you want. The futures are in the same order as the requests. - for (Future future : futureTask) { - System.out.println("another result " + future.get()); - } } finally { requestExecService.close(); } diff --git a/httpclient/src/main/java/org/apache/http/impl/client/FutureRequestExecutionService.java b/httpclient/src/main/java/org/apache/http/impl/client/FutureRequestExecutionService.java index 3156b4fb6..be0efa5e0 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/FutureRequestExecutionService.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/FutureRequestExecutionService.java @@ -28,19 +28,13 @@ package org.apache.http.impl.client; import java.io.Closeable; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.http.annotation.ThreadSafe; import org.apache.http.client.HttpClient; import org.apache.http.client.ResponseHandler; import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.concurrent.FutureCallback; import org.apache.http.protocol.HttpContext; @@ -131,63 +125,6 @@ public class FutureRequestExecutionService implements Closeable { return httpRequestFutureTask; } - /** - * Schedule multiple requests for execution. - * - * @param - * - * @param responseHandler - * handler that will process the responses. - * @param requests - * one or more requests. - * @return a list of HttpAsyncClientFutureTask for the scheduled requests. - * @throws InterruptedException - */ - public List> executeMultiple( - final ResponseHandler responseHandler, - final HttpUriRequest... requests) throws InterruptedException { - return executeMultiple(HttpClientContext.create(), responseHandler, null, -1, null, requests); - } - - /** - * Schedule multiple requests for execution with a timeout. - * - * @param - * - * @param context - * optional context; use null if not needed. - * @param responseHandler - * handler that will process the responses. - * @param callback - * callback handler that will be called when requests are scheduled, - * started, completed, failed, or cancelled. - * @param timeout - * @param timeUnit - * @param requests - * one or more requests. - * @return a list of HttpAsyncClientFutureTask for the scheduled requests. - * @throws InterruptedException - */ - public List> executeMultiple( - final HttpContext context, - final ResponseHandler responseHandler, - final FutureCallback callback, - final long timeout, final TimeUnit timeUnit, - final HttpUriRequest... requests) throws InterruptedException { - metrics.getScheduledConnections().incrementAndGet(); - final List> callables = new ArrayList>(); - for (final HttpUriRequest request : requests) { - final HttpRequestTaskCallable callable = new HttpRequestTaskCallable( - httpclient, request, context, responseHandler, callback, metrics); - callables.add(callable); - } - if (timeout > 0) { - return executorService.invokeAll(callables, timeout, timeUnit); - } else { - return executorService.invokeAll(callables); - } - } - /** * @return metrics gathered for this instance. * @see FutureRequestExecutionMetrics diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java b/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java index d624d09e7..06739d5a1 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java @@ -28,7 +28,8 @@ package org.apache.http.impl.client; import java.io.IOException; import java.net.InetSocketAddress; -import java.util.List; +import java.util.LinkedList; +import java.util.Queue; import java.util.concurrent.CancellationException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -126,29 +127,30 @@ public class TestFutureRequestExecutionService { @Test public void shouldExecuteMultipleCalls() throws InterruptedException, ExecutionException { - final HttpGet[] requests= new HttpGet[100]; - for(int i=0;i<100;i++) { - requests[i]=new HttpGet(uri); + final int reqNo = 100; + final Queue> tasks = new LinkedList>(); + for(int i = 0; i < reqNo; i++) { + final Future task = httpAsyncClientWithFuture.execute( + new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler()); + tasks.add(task); } - final List> tasks = httpAsyncClientWithFuture.executeMultiple( - new OkidokiHandler(), requests); for (final Future task : tasks) { - Assert.assertTrue("request should have returned OK", task.get().booleanValue()); + final Boolean b = task.get(); + Assert.assertNotNull(b); + Assert.assertTrue("request should have returned OK", b.booleanValue()); } } @Test public void shouldExecuteMultipleCallsAndCallback() throws InterruptedException { final int reqNo = 100; - final HttpGet[] requests= new HttpGet[reqNo]; - for(int i = 0; i < reqNo; i++) { - requests[i] = new HttpGet(uri); - } final CountDownLatch latch = new CountDownLatch(reqNo); final CountingCallback callback = new CountingCallback(latch); - httpAsyncClientWithFuture.executeMultiple(null, - new OkidokiHandler(), callback , 10, TimeUnit.SECONDS, requests); - + for(int i = 0; i < reqNo; i++) { + httpAsyncClientWithFuture.execute( + new HttpGet(uri), HttpClientContext.create(), + new OkidokiHandler(), callback); + } latch.await(10, TimeUnit.SECONDS); Assert.assertEquals(100, callback.completed.get()); @@ -188,7 +190,8 @@ public class TestFutureRequestExecutionService { private final class OkidokiHandler implements ResponseHandler { - public Boolean handleResponse(final HttpResponse response) throws ClientProtocolException, IOException { + public Boolean handleResponse( + final HttpResponse response) throws ClientProtocolException, IOException { return response.getStatusLine().getStatusCode() == 200; } }