You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2013/06/11 16:10:32 UTC

svn commit: r1491801 - in /httpcomponents/httpclient/trunk/httpclient/src: examples/org/apache/http/examples/client/ main/java/org/apache/http/impl/client/ test/java/org/apache/http/impl/client/

Author: olegk
Date: Tue Jun 11 14:10:31 2013
New Revision: 1491801

URL: http://svn.apache.org/r1491801
Log:
Removed #executeMultiple from FutureRequestExecutionService

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/FutureRequestExecutionService.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java?rev=1491801&r1=1491800&r2=1491801&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientWithRequestFuture.java Tue Jun 11 14:10:31 2013
@@ -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<Future<Boolean>> 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<Boolean> future : futureTask) {
-                System.out.println("another result " + future.get());
-            }
         } finally {
             requestExecService.close();
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/FutureRequestExecutionService.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/FutureRequestExecutionService.java?rev=1491801&r1=1491800&r2=1491801&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/FutureRequestExecutionService.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/FutureRequestExecutionService.java Tue Jun 11 14:10:31 2013
@@ -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;
 
@@ -132,63 +126,6 @@ public class FutureRequestExecutionServi
     }
 
     /**
-     * Schedule multiple requests for execution.
-     *
-     * @param <T>
-     *
-     * @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 <T> List<Future<T>> executeMultiple(
-            final ResponseHandler<T> responseHandler,
-            final HttpUriRequest... requests) throws InterruptedException {
-        return executeMultiple(HttpClientContext.create(), responseHandler, null, -1, null, requests);
-    }
-
-    /**
-     * Schedule multiple requests for execution with a timeout.
-     *
-     * @param <T>
-     *
-     * @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 <T> List<Future<T>> executeMultiple(
-            final HttpContext context,
-            final ResponseHandler<T> responseHandler,
-            final FutureCallback<T> callback,
-            final long timeout, final TimeUnit timeUnit,
-            final HttpUriRequest... requests) throws InterruptedException {
-        metrics.getScheduledConnections().incrementAndGet();
-        final List<Callable<T>> callables = new ArrayList<Callable<T>>();
-        for (final HttpUriRequest request : requests) {
-            final HttpRequestTaskCallable<T> callable = new HttpRequestTaskCallable<T>(
-                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
      */

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java?rev=1491801&r1=1491800&r2=1491801&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java Tue Jun 11 14:10:31 2013
@@ -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 TestFutureRequestExecutionS
 
     @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<Future<Boolean>> tasks = new LinkedList<Future<Boolean>>();
+        for(int i = 0; i < reqNo; i++) {
+            final Future<Boolean> task = httpAsyncClientWithFuture.execute(
+                    new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
+            tasks.add(task);
         }
-        final List<Future<Boolean>> tasks = httpAsyncClientWithFuture.executeMultiple(
-            new OkidokiHandler(), requests);
         for (final Future<Boolean> 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 TestFutureRequestExecutionS
 
 
     private final class OkidokiHandler implements ResponseHandler<Boolean> {
-        public Boolean handleResponse(final HttpResponse response) throws ClientProtocolException, IOException {
+        public Boolean handleResponse(
+                final HttpResponse response) throws ClientProtocolException, IOException {
             return response.getStatusLine().getStatusCode() == 200;
         }
     }