Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5449117F3A for ; Fri, 10 Oct 2014 19:49:57 +0000 (UTC) Received: (qmail 16342 invoked by uid 500); 10 Oct 2014 19:49:57 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 16300 invoked by uid 500); 10 Oct 2014 19:49:57 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 16291 invoked by uid 99); 10 Oct 2014 19:49:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Oct 2014 19:49:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Oct 2014 19:49:53 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5AE2323889F1 for ; Fri, 10 Oct 2014 19:49:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1630967 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http: impl/nio/client/ nio/client/ Date: Fri, 10 Oct 2014 19:49:32 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20141010194933.5AE2323889F1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Fri Oct 10 19:49:32 2014 New Revision: 1630967 URL: http://svn.apache.org/r1630967 Log: Added support for minimal async client capable of pipelined request execution Added: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpPipeliningClient.java (with props) httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java (with props) httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java (with props) httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpPipeliningClient.java - copied, changed from r1630966, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClient.java httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClientBase.java httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClient.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClient.java?rev=1630967&r1=1630966&r2=1630967&view=diff ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClient.java (original) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClient.java Fri Oct 10 19:49:32 2014 @@ -36,6 +36,7 @@ import org.apache.http.HttpResponse; import org.apache.http.annotation.ThreadSafe; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.client.utils.URIUtils; import org.apache.http.concurrent.BasicFuture; import org.apache.http.concurrent.FutureCallback; @@ -43,7 +44,6 @@ import org.apache.http.nio.client.HttpAs import org.apache.http.nio.client.methods.HttpAsyncMethods; import org.apache.http.nio.protocol.HttpAsyncRequestProducer; import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; -import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import org.apache.http.util.Args; @@ -64,7 +64,7 @@ public abstract class CloseableHttpAsync final HttpAsyncRequestProducer requestProducer, final HttpAsyncResponseConsumer responseConsumer, final FutureCallback callback) { - return execute(requestProducer, responseConsumer, new BasicHttpContext(), callback); + return execute(requestProducer, responseConsumer, HttpClientContext.create(), callback); } @Override @@ -81,14 +81,14 @@ public abstract class CloseableHttpAsync public Future execute( final HttpHost target, final HttpRequest request, final FutureCallback callback) { - return execute(target, request, new BasicHttpContext(), callback); + return execute(target, request, HttpClientContext.create(), callback); } @Override public Future execute( final HttpUriRequest request, final FutureCallback callback) { - return execute(request, new BasicHttpContext(), callback); + return execute(request, HttpClientContext.create(), callback); } @Override Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClientBase.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClientBase.java?rev=1630967&r1=1630966&r2=1630967&view=diff ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClientBase.java (original) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClientBase.java Fri Oct 10 19:49:32 2014 @@ -37,7 +37,7 @@ import org.apache.http.nio.conn.NHttpCli import org.apache.http.nio.reactor.IOEventDispatch; import org.apache.http.util.Asserts; -abstract class CloseableHttpAsyncClientBase extends CloseableHttpAsyncClient { +abstract class CloseableHttpAsyncClientBase extends CloseableHttpPipeliningClient { private final Log log = LogFactory.getLog(getClass()); Added: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpPipeliningClient.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpPipeliningClient.java?rev=1630967&view=auto ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpPipeliningClient.java (added) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpPipeliningClient.java Fri Oct 10 19:49:32 2014 @@ -0,0 +1,92 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ +package org.apache.http.impl.nio.client; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Future; + +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.annotation.ThreadSafe; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.concurrent.FutureCallback; +import org.apache.http.nio.client.HttpPipeliningClient; +import org.apache.http.nio.client.methods.HttpAsyncMethods; +import org.apache.http.nio.protocol.HttpAsyncRequestProducer; +import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; +import org.apache.http.protocol.HttpContext; +import org.apache.http.util.Args; + +/** + * Base implementation of {@link org.apache.http.nio.client.HttpPipeliningClient} that also + * implements {@link java.io.Closeable}. + * + * @since 4.1 + */ +@ThreadSafe +public abstract class CloseableHttpPipeliningClient + extends CloseableHttpAsyncClient implements HttpPipeliningClient { + + @Override + public Future> execute( + final HttpHost target, + final List requestProducers, + final List> responseConsumers, + final FutureCallback> callback) { + return execute(target, requestProducers, responseConsumers, HttpClientContext.create(), callback); + } + + @Override + public Future> execute( + final HttpHost target, + final List requests, + final FutureCallback> callback) { + return execute(target, requests, HttpClientContext.create(), callback); + } + + @Override + public Future> execute( + final HttpHost target, + final List requests, + final HttpContext context, + final FutureCallback> callback) { + Args.notEmpty(requests, "HTTP request list"); + final List requestProducers = new ArrayList( + requests.size()); + final List> responseConsumers = new ArrayList>( + requests.size()); + for (int i = 0; i < requests.size(); i++) { + final HttpRequest request = requests.get(i); + requestProducers.add(HttpAsyncMethods.create(target, request)); + responseConsumers.add(HttpAsyncMethods.createConsumer()); + } + return execute(target, requestProducers, responseConsumers, context, callback); + } + +} Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpPipeliningClient.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpPipeliningClient.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpPipeliningClient.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java?rev=1630967&r1=1630966&r2=1630967&view=diff ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java (original) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java Fri Oct 10 19:49:32 2014 @@ -29,13 +29,13 @@ package org.apache.http.impl.nio.client; import org.apache.http.annotation.Immutable; import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; -import org.apache.http.impl.nio.reactor.IOReactorConfig; import org.apache.http.nio.conn.NHttpClientConnectionManager; import org.apache.http.nio.reactor.ConnectingIOReactor; import org.apache.http.util.Args; /** - * Factory methods for {@link CloseableHttpAsyncClient} instances. + * Factory methods for {@link org.apache.http.impl.nio.client.CloseableHttpAsyncClient} and + * {@link org.apache.http.impl.nio.client.CloseableHttpPipeliningClient} instances. * * @since 4.0 */ @@ -67,35 +67,111 @@ public class HttpAsyncClients { * configuration based on ssytem properties. */ public static CloseableHttpAsyncClient createSystem() { - return HttpAsyncClientBuilder.create().useSystemProperties().build(); + return HttpAsyncClientBuilder.create() + .useSystemProperties() + .build(); } /** - * Creates {@link CloseableHttpAsyncClient} instance that implements - * the most basic HTTP protocol support. + * Creates {@link CloseableHttpAsyncClient} instance that supports esential HTTP protocol + * aspects only. This client does not support HTTP state management, authentication + * and automatic redirects. */ public static CloseableHttpAsyncClient createMinimal() { - return new MinimalHttpAsyncClient( - new PoolingNHttpClientConnectionManager(IOReactorUtils.create(IOReactorConfig.DEFAULT))); + return MinimalHttpAsyncClientBuilder.create() + .disableCookieManagement() + .build(); } /** - * Creates {@link CloseableHttpAsyncClient} instance that implements - * the most basic HTTP protocol support. + * Creates {@link CloseableHttpAsyncClient} instance that supports esential HTTP protocol + * aspects only. This client does not support HTTP state management, authentication + * and automatic redirects. */ public static CloseableHttpAsyncClient createMinimal(final ConnectingIOReactor ioreactor) { Args.notNull(ioreactor, "I/O reactor"); - return new MinimalHttpAsyncClient( - new PoolingNHttpClientConnectionManager(ioreactor)); + return createMinimal(new PoolingNHttpClientConnectionManager(ioreactor), false); } /** - * Creates {@link CloseableHttpAsyncClient} instance that implements - * the most basic HTTP protocol support. + * Creates {@link CloseableHttpAsyncClient} instance that supports esential HTTP protocol + * aspects only. This client does not support HTTP state management, authentication + * and automatic redirects. */ public static CloseableHttpAsyncClient createMinimal(final NHttpClientConnectionManager connManager) { + return createMinimal(connManager, false); + } + + /** + * Creates {@link CloseableHttpAsyncClient} instance that supports esential HTTP protocol + * aspects only. This client does not support HTTP state management, authentication + * and automatic redirects. + *

+ * Please note that clients with a shared connection manager make no attempts to control + * its life cycle and dealocation of resources. It is a responibility of the caller to + * ensure that the shared connection manager is properly started and shut down when no + * longer needed. + * + * @since 4.1 + */ + public static CloseableHttpAsyncClient createMinimal( + final NHttpClientConnectionManager connManager, final boolean shared) { + Args.notNull(connManager, "Connection manager"); + return MinimalHttpAsyncClientBuilder.create() + .setConnectionManager(connManager) + .setConnectionManagerShared(shared) + .disableCookieManagement() + .build(); + } + + /** + * Creates {@link CloseableHttpPipeliningClient} instance that supports pipelined request + * execution. This client does not support authentication and automatic redirects. + * + * @since 4.1 + */ + public static CloseableHttpPipeliningClient createPipelining() { + return MinimalHttpAsyncClientBuilder.create().build(); + } + + /** + * Creates {@link CloseableHttpPipeliningClient} instance that supports pipelined request + * execution. This client does not support authentication and automatic redirects. + * + * @since 4.1 + */ + public static CloseableHttpPipeliningClient createPipelining(final ConnectingIOReactor ioreactor) { + return createPipelining(new PoolingNHttpClientConnectionManager(ioreactor), false); + } + + /** + * Creates {@link CloseableHttpPipeliningClient} instance that supports pipelined request + * execution. This client does not support authentication and automatic redirects. + * + * @since 4.1 + */ + public static CloseableHttpPipeliningClient createPipelining(final NHttpClientConnectionManager connManager) { + return createPipelining(connManager, false); + } + + /** + * Creates {@link CloseableHttpPipeliningClient} instance that supports pipelined request + * execution. This client does not support authentication and automatic redirects. + *

+ * Please note that clients with a shared connection manager make no attempts to control + * its life cycle and dealocation of resources. It is a responibility of the caller to + * ensure that the shared connection manager is properly started and shut down when no + * longer needed. + * + * @since 4.1 + */ + public static CloseableHttpPipeliningClient createPipelining( + final NHttpClientConnectionManager connManager, final boolean shared) { Args.notNull(connManager, "Connection manager"); - return new MinimalHttpAsyncClient(connManager); + return MinimalHttpAsyncClientBuilder.create() + .setConnectionManager(connManager) + .setConnectionManagerShared(shared) + .build(); } } Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java?rev=1630967&r1=1630966&r2=1630967&view=diff ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java (original) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java Fri Oct 10 19:49:32 2014 @@ -26,12 +26,14 @@ */ package org.apache.http.impl.nio.client; +import java.util.List; import java.util.concurrent.Future; import java.util.concurrent.ThreadFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.ConnectionReuseStrategy; +import org.apache.http.HttpHost; import org.apache.http.auth.AuthSchemeProvider; import org.apache.http.auth.AuthState; import org.apache.http.client.CookieStore; @@ -143,4 +145,14 @@ class InternalHttpAsyncClient extends Cl return future; } + @Override + public Future> execute( + final HttpHost target, + final List requestProducers, + final List> responseConsumers, + final HttpContext context, + final FutureCallback> callback) { + throw new UnsupportedOperationException("Pipelining not supported"); + } + } Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java?rev=1630967&r1=1630966&r2=1630967&view=diff ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java (original) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java Fri Oct 10 19:49:32 2014 @@ -26,16 +26,19 @@ */ package org.apache.http.impl.nio.client; +import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ThreadFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.http.ConnectionReuseStrategy; +import org.apache.http.HttpHost; import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.client.protocol.RequestClientConnControl; import org.apache.http.concurrent.BasicFuture; import org.apache.http.concurrent.FutureCallback; +import org.apache.http.conn.ConnectionKeepAliveStrategy; import org.apache.http.impl.DefaultConnectionReuseStrategy; import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy; import org.apache.http.nio.NHttpClientEventHandler; @@ -45,11 +48,6 @@ import org.apache.http.nio.protocol.Http import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpProcessor; -import org.apache.http.protocol.ImmutableHttpProcessor; -import org.apache.http.protocol.RequestContent; -import org.apache.http.protocol.RequestTargetHost; -import org.apache.http.protocol.RequestUserAgent; -import org.apache.http.util.VersionInfo; class MinimalHttpAsyncClient extends CloseableHttpAsyncClientBase { @@ -57,23 +55,32 @@ class MinimalHttpAsyncClient extends Clo private final NHttpClientConnectionManager connmgr; private final HttpProcessor httpProcessor; + private final ConnectionReuseStrategy connReuseStrategy; + private final ConnectionKeepAliveStrategy keepaliveStrategy; public MinimalHttpAsyncClient( final NHttpClientConnectionManager connmgr, final ThreadFactory threadFactory, - final NHttpClientEventHandler eventHandler) { + final NHttpClientEventHandler eventHandler, + final HttpProcessor httpProcessor, + final ConnectionReuseStrategy connReuseStrategy, + final ConnectionKeepAliveStrategy keepaliveStrategy) { super(connmgr, threadFactory, eventHandler); this.connmgr = connmgr; - this.httpProcessor = new ImmutableHttpProcessor(new RequestContent(), - new RequestTargetHost(), - new RequestClientConnControl(), - new RequestUserAgent(VersionInfo.getUserAgent( - "Apache-HttpAsyncClient", "org.apache.http.nio.client", getClass()))); + this.httpProcessor = httpProcessor; + this.connReuseStrategy = connReuseStrategy; + this.keepaliveStrategy = keepaliveStrategy; } public MinimalHttpAsyncClient( - final NHttpClientConnectionManager connmgr) { - this(connmgr, Executors.defaultThreadFactory(), new LoggingAsyncRequestExecutor()); + final NHttpClientConnectionManager connmgr, + final HttpProcessor httpProcessor) { + this(connmgr, + Executors.defaultThreadFactory(), + new LoggingAsyncRequestExecutor(), + httpProcessor, + DefaultConnectionReuseStrategy.INSTANCE, + DefaultConnectionKeepAliveStrategy.INSTANCE); } @Override @@ -96,8 +103,39 @@ class MinimalHttpAsyncClient extends Clo future, this.connmgr, this.httpProcessor, - DefaultConnectionReuseStrategy.INSTANCE, - DefaultConnectionKeepAliveStrategy.INSTANCE); + this.connReuseStrategy, + this.keepaliveStrategy); + try { + handler.start(); + } catch (final Exception ex) { + handler.failed(ex); + } + return future; + } + + @Override + public Future> execute( + final HttpHost target, + final List requestProducers, + final List> responseConsumers, + final HttpContext context, + final FutureCallback> callback) { + ensureRunning(); + final BasicFuture> future = new BasicFuture>(callback); + final HttpClientContext localcontext = HttpClientContext.adapt( + context != null ? context : new BasicHttpContext()); + @SuppressWarnings("resource") + final PipeliningClientExchangeHandlerImpl handler = new PipeliningClientExchangeHandlerImpl( + this.log, + target, + requestProducers, + responseConsumers, + localcontext, + future, + this.connmgr, + this.httpProcessor, + this.connReuseStrategy, + this.keepaliveStrategy); try { handler.start(); } catch (final Exception ex) { Added: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java?rev=1630967&view=auto ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java (added) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java Fri Oct 10 19:49:32 2014 @@ -0,0 +1,162 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.impl.nio.client; + +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; + +import org.apache.http.ConnectionReuseStrategy; +import org.apache.http.annotation.NotThreadSafe; +import org.apache.http.client.protocol.RequestAddCookies; +import org.apache.http.client.protocol.RequestClientConnControl; +import org.apache.http.client.protocol.ResponseProcessCookies; +import org.apache.http.conn.ConnectionKeepAliveStrategy; +import org.apache.http.impl.DefaultConnectionReuseStrategy; +import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy; +import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; +import org.apache.http.impl.nio.reactor.IOReactorConfig; +import org.apache.http.nio.conn.NHttpClientConnectionManager; +import org.apache.http.protocol.HttpProcessor; +import org.apache.http.protocol.HttpProcessorBuilder; +import org.apache.http.protocol.RequestContent; +import org.apache.http.protocol.RequestTargetHost; +import org.apache.http.protocol.RequestUserAgent; +import org.apache.http.util.VersionInfo; + +/** + * Builder for {@link org.apache.http.impl.nio.client.MinimalHttpAsyncClient} instances. + * + * @since 4.1 + */ +@NotThreadSafe +class MinimalHttpAsyncClientBuilder { + + private NHttpClientConnectionManager connManager; + private boolean connManagerShared; + private ConnectionReuseStrategy reuseStrategy; + private ConnectionKeepAliveStrategy keepAliveStrategy; + private String userAgent; + private ThreadFactory threadFactory; + private boolean cookieManagementDisabled; + + public static MinimalHttpAsyncClientBuilder create() { + return new MinimalHttpAsyncClientBuilder(); + } + + protected MinimalHttpAsyncClientBuilder() { + super(); + } + + public final MinimalHttpAsyncClientBuilder setConnectionManager( + final NHttpClientConnectionManager connManager) { + this.connManager = connManager; + return this; + } + + public final MinimalHttpAsyncClientBuilder setConnectionManagerShared( + final boolean shared) { + this.connManagerShared = shared; + return this; + } + + public final MinimalHttpAsyncClientBuilder setConnectionReuseStrategy( + final ConnectionReuseStrategy reuseStrategy) { + this.reuseStrategy = reuseStrategy; + return this; + } + + public final MinimalHttpAsyncClientBuilder setKeepAliveStrategy( + final ConnectionKeepAliveStrategy keepAliveStrategy) { + this.keepAliveStrategy = keepAliveStrategy; + return this; + } + + public final MinimalHttpAsyncClientBuilder setUserAgent(final String userAgent) { + this.userAgent = userAgent; + return this; + } + + public final MinimalHttpAsyncClientBuilder setThreadFactory(final ThreadFactory threadFactory) { + this.threadFactory = threadFactory; + return this; + } + + public final MinimalHttpAsyncClientBuilder disableCookieManagement() { + cookieManagementDisabled = true; + return this; + } + + public MinimalHttpAsyncClient build() { + + NHttpClientConnectionManager connManager = this.connManager; + if (connManager == null) { + connManager = new PoolingNHttpClientConnectionManager( + IOReactorUtils.create(IOReactorConfig.DEFAULT)); + } + ConnectionReuseStrategy reuseStrategy = this.reuseStrategy; + if (reuseStrategy == null) { + reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE; + } + ConnectionKeepAliveStrategy keepAliveStrategy = this.keepAliveStrategy; + if (keepAliveStrategy == null) { + keepAliveStrategy = DefaultConnectionKeepAliveStrategy.INSTANCE; + } + String userAgent = this.userAgent; + if (userAgent == null) { + userAgent = VersionInfo.getUserAgent( + "Apache-HttpAsyncClient", "org.apache.http.nio.client", getClass()); + } + final HttpProcessorBuilder b = HttpProcessorBuilder.create(); + b.addAll( + new RequestContent(), + new RequestTargetHost(), + new RequestClientConnControl(), + new RequestUserAgent(userAgent)); + if (!cookieManagementDisabled) { + b.add(new RequestAddCookies()); + b.add(new ResponseProcessCookies()); + } + final HttpProcessor httpprocessor = b.build(); + + ThreadFactory threadFactory = null; + if (!this.connManagerShared) { + threadFactory = this.threadFactory; + if (threadFactory == null) { + threadFactory = Executors.defaultThreadFactory(); + } + } + return new MinimalHttpAsyncClient( + connManager, + threadFactory, + new LoggingAsyncRequestExecutor(), + httpprocessor, + reuseStrategy, + keepAliveStrategy); + } + +} Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java?rev=1630967&view=auto ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java (added) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java Fri Oct 10 19:49:32 2014 @@ -0,0 +1,335 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ +package org.apache.http.impl.nio.client; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.logging.Log; +import org.apache.http.ConnectionClosedException; +import org.apache.http.ConnectionReuseStrategy; +import org.apache.http.HttpException; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.HttpRequestWrapper; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.concurrent.BasicFuture; +import org.apache.http.conn.ConnectionKeepAliveStrategy; +import org.apache.http.conn.routing.HttpRoute; +import org.apache.http.nio.ContentDecoder; +import org.apache.http.nio.ContentEncoder; +import org.apache.http.nio.IOControl; +import org.apache.http.nio.NHttpClientConnection; +import org.apache.http.nio.conn.NHttpClientConnectionManager; +import org.apache.http.nio.protocol.HttpAsyncRequestProducer; +import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; +import org.apache.http.nio.protocol.Pipelined; +import org.apache.http.protocol.HttpCoreContext; +import org.apache.http.protocol.HttpProcessor; +import org.apache.http.util.Args; +import org.apache.http.util.Asserts; + +/** + * {@link org.apache.http.nio.protocol.HttpAsyncClientExchangeHandler} implementation + * that supports HTTP message pipelining. + *

+ * Instances of this class are expected to be accessed by one thread at a time only. + * The {@link #cancel()} method can be called concurrently by multiple threads. + */ +@Pipelined +class PipeliningClientExchangeHandlerImpl extends AbstractClientExchangeHandler { + + private final HttpHost target; + private final Queue requestProducerQueue; + private final Queue> responseConsumerQueue; + private final Queue requestQueue; + private final Queue resultQueue; + private final HttpClientContext localContext; + private final BasicFuture> resultFuture; + private final HttpProcessor httpProcessor; + private final AtomicReference requestProducerRef; + private final AtomicReference> responseConsumerRef; + + public PipeliningClientExchangeHandlerImpl( + final Log log, + final HttpHost target, + final List requestProducers, + final List> responseConsumers, + final HttpClientContext localContext, + final BasicFuture> resultFuture, + final NHttpClientConnectionManager connmgr, + final HttpProcessor httpProcessor, + final ConnectionReuseStrategy connReuseStrategy, + final ConnectionKeepAliveStrategy keepaliveStrategy) { + super(log, localContext, resultFuture, connmgr, connReuseStrategy, keepaliveStrategy); + Args.notNull(target, "HTTP target"); + Args.notEmpty(requestProducers, "Request producer list"); + Args.notEmpty(responseConsumers, "Response consumer list"); + Args.check(requestProducers.size() == responseConsumers.size(), + "Number of request producers does not match that of response consumers"); + this.target = target; + this.requestProducerQueue = new ConcurrentLinkedQueue(requestProducers); + this.responseConsumerQueue = new ConcurrentLinkedQueue>(responseConsumers); + this.requestQueue = new ConcurrentLinkedQueue(); + this.resultQueue = new ConcurrentLinkedQueue(); + this.localContext = localContext; + this.resultFuture = resultFuture; + this.httpProcessor = httpProcessor; + this.requestProducerRef = new AtomicReference(null); + this.responseConsumerRef = new AtomicReference>(null); + } + + private void closeProducer(final HttpAsyncRequestProducer requestProducer) { + if (requestProducer != null) { + try { + requestProducer.close(); + } catch (IOException ex) { + this.log.debug("I/O error closing request producer", ex); + } + } + } + + private void closeConsumer(final HttpAsyncResponseConsumer responseConsumer) { + if (responseConsumer != null) { + try { + responseConsumer.close(); + } catch (IOException ex) { + this.log.debug("I/O error closing response consumer", ex); + } + } + } + + @Override + void releaseResources() { + closeProducer(this.requestProducerRef.getAndSet(null)); + closeConsumer(this.responseConsumerRef.getAndSet(null)); + while (!this.requestProducerQueue.isEmpty()) { + closeProducer(this.requestProducerQueue.remove()); + } + while (!this.responseConsumerQueue.isEmpty()) { + closeConsumer(this.responseConsumerQueue.remove()); + } + this.requestQueue.clear(); + this.resultQueue.clear(); + } + + @Override + void executionFailed(final Exception ex) { + final HttpAsyncRequestProducer requestProducer = this.requestProducerRef.get(); + if (requestProducer != null) { + requestProducer.failed(ex); + } + final HttpAsyncResponseConsumer responseConsumer = this.responseConsumerRef.get(); + if (responseConsumer != null) { + responseConsumer.failed(ex); + } + } + + @Override + boolean executionCancelled() { + final HttpAsyncResponseConsumer responseConsumer = this.responseConsumerRef.get(); + final boolean cancelled = responseConsumer != null && responseConsumer.cancel(); + this.resultFuture.cancel(); + return cancelled; + } + + public void start() throws HttpException, IOException { + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + getId() + "] start execution"); + } + + final HttpRoute route = new HttpRoute(this.target); + setRoute(route); + + this.localContext.setAttribute(HttpClientContext.HTTP_TARGET_HOST, this.target); + this.localContext.setAttribute(HttpClientContext.HTTP_ROUTE, route); + + requestConnection(); + } + + @Override + public HttpRequest generateRequest() throws IOException, HttpException { + verifytRoute(); + if (!isRouteEstablished()) { + onRouteToTarget(); + onRouteComplete(); + } + final NHttpClientConnection localConn = getConnection(); + this.localContext.setAttribute(HttpCoreContext.HTTP_CONNECTION, localConn); + + Asserts.check(this.requestProducerRef.get() == null, "Inconsistent state: currentRequest producer is not null"); + final HttpAsyncRequestProducer requestProducer = this.requestProducerQueue.poll(); + if (requestProducer == null) { + return null; + } + this.requestProducerRef.set(requestProducer); + + final HttpRequest original = requestProducer.generateRequest(); + final HttpRequestWrapper currentRequest = HttpRequestWrapper.wrap(original); + final RequestConfig config = this.localContext.getRequestConfig(); + if (config.getSocketTimeout() > 0) { + localConn.setSocketTimeout(config.getSocketTimeout()); + } + + this.httpProcessor.process(currentRequest, this.localContext); + + this.requestQueue.add(currentRequest); + setCurrentRequest(currentRequest); + + return currentRequest; + } + + @Override + public void produceContent( + final ContentEncoder encoder, final IOControl ioctrl) throws IOException { + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + getId() + "] produce content"); + } + final HttpAsyncRequestProducer requestProducer = this.requestProducerRef.get(); + Asserts.check(requestProducer != null, "Inconsistent state: request producer is null"); + requestProducer.produceContent(encoder, ioctrl); + if (encoder.isCompleted()) { + requestProducer.resetRequest(); + } + } + + @Override + public void requestCompleted() { + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + getId() + "] Request completed"); + } + final HttpAsyncRequestProducer requestProducer = this.requestProducerRef.getAndSet(null); + Asserts.check(requestProducer != null, "Inconsistent state: request producer is null"); + requestProducer.requestCompleted(this.localContext); + try { + requestProducer.close(); + } catch (IOException ioex) { + this.log.debug(ioex.getMessage(), ioex); + } + } + + @Override + public void responseReceived( + final HttpResponse response) throws IOException, HttpException { + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + getId() + "] Response received " + response.getStatusLine()); + } + + Asserts.check(this.responseConsumerRef.get() == null, "Inconsistent state: response consumer is not null"); + + final HttpAsyncResponseConsumer responseConsumer = this.responseConsumerQueue.poll(); + Asserts.check(responseConsumer != null, "Inconsistent state: response consumer queue is empty"); + this.responseConsumerRef.set(responseConsumer); + + final HttpRequest request = this.requestQueue.poll(); + Asserts.check(request != null, "Inconsistent state: request queue is empty"); + + this.localContext.setAttribute(HttpCoreContext.HTTP_REQUEST, request); + this.localContext.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); + this.httpProcessor.process(response, this.localContext); + + responseConsumer.responseReceived(response); + + setCurrentResponse(response); + } + + @Override + public void consumeContent( + final ContentDecoder decoder, final IOControl ioctrl) throws IOException { + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + getId() + "] Consume content"); + } + final HttpAsyncResponseConsumer responseConsumer = this.responseConsumerRef.get(); + Asserts.check(responseConsumer != null, "Inconsistent state: response consumer is null"); + responseConsumer.consumeContent(decoder, ioctrl); + } + + @Override + public void responseCompleted() throws IOException, HttpException { + if (this.log.isDebugEnabled()) { + this.log.debug("[exchange: " + getId() + "] Response processed"); + } + + final boolean keepAlive = manageConnectionPersistence(); + + final HttpAsyncResponseConsumer responseConsumer = this.responseConsumerRef.getAndSet(null); + Asserts.check(responseConsumer != null, "Inconsistent state: response consumer is null"); + try { + responseConsumer.responseCompleted(this.localContext); + final T result = responseConsumer.getResult(); + final Exception ex = responseConsumer.getException(); + try { + responseConsumer.close(); + } catch (IOException ioex) { + this.log.debug(ioex.getMessage(), ioex); + } + if (result != null) { + this.resultQueue.add(result); + } else { + this.resultFuture.failed(ex); + } + if (!this.resultFuture.isDone() && this.responseConsumerQueue.isEmpty()) { + this.resultFuture.completed(new ArrayList(this.resultQueue)); + this.resultQueue.clear(); + } + + if (this.resultFuture.isDone()) { + close(); + } else { + if (!keepAlive) { + failed(new ConnectionClosedException("Connection closed")); + } else { + final NHttpClientConnection localConn = getConnection(); + if (localConn != null) { + localConn.requestOutput(); + } else { + requestConnection(); + } + } + } + } catch (final RuntimeException ex) { + failed(ex); + throw ex; + } + } + + @Override + public void inputTerminated() { + failed(new ConnectionClosedException("Connection closed")); + } + + public void abortConnection() { + discardConnection(); + } + +} Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java?rev=1630967&r1=1630966&r2=1630967&view=diff ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java (original) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java Fri Oct 10 19:49:32 2014 @@ -113,8 +113,7 @@ public interface HttpAsyncClient { FutureCallback callback); /** - * Initiates asynchronous HTTP request execution against the given target - * using the default context. + * Initiates asynchronous HTTP request execution against the given target. * * @param target the target host for the request. * Implementations may accept {@code null} @@ -145,8 +144,7 @@ public interface HttpAsyncClient { FutureCallback callback); /** - * Initiates asynchronous HTTP request execution using the default - * context. + * Initiates asynchronous HTTP request execution. * * @param request the request to execute * @param callback future callback. Copied: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpPipeliningClient.java (from r1630966, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java) URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpPipeliningClient.java?p2=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpPipeliningClient.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java&r1=1630966&r2=1630967&rev=1630967&view=diff ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java (original) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpPipeliningClient.java Fri Oct 10 19:49:32 2014 @@ -26,12 +26,12 @@ */ package org.apache.http.nio.client; +import java.util.List; import java.util.concurrent.Future; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.concurrent.FutureCallback; import org.apache.http.nio.protocol.HttpAsyncRequestProducer; import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; @@ -43,117 +43,95 @@ import org.apache.http.protocol.HttpCont * execution process and leaves the specifics of state management, * authentication and redirect handling up to individual implementations. * - * @since 4.0 + * @since 4.1 */ -public interface HttpAsyncClient { +public interface HttpPipeliningClient extends HttpAsyncClient { /** - * Initiates asynchronous HTTP request execution using the given context. + * Initiates pipelined execution of a sequence of requests. *

- * The request producer passed to this method will be used to generate + * The request producers passed to this method will be used to generate * a request message and stream out its content without buffering it - * in memory. The response consumer passed to this method will be used + * in memory. The response consumers passed to this method will be used * to process a response message without buffering its content in memory. *

* Please note it may be unsafe to interact with the context instance * while the request is still being executed. * * @param the result type of request execution. - * @param requestProducer request producer callback. - * @param responseConsumer response consumer callaback. + * @param target the target host for the request. + * @param requestProducers list of request producers. + * @param responseConsumers list of response consumers. * @param context HTTP context * @param callback future callback. * @return future representing pending completion of the operation. */ - Future execute( - HttpAsyncRequestProducer requestProducer, - HttpAsyncResponseConsumer responseConsumer, + Future> execute( + HttpHost target, + List requestProducers, + List> responseConsumers, HttpContext context, - FutureCallback callback); + FutureCallback> callback); /** - * Initiates asynchronous HTTP request execution using the default - * context. + * Initiates pipelined execution of a sequence of requests. *

- * The request producer passed to this method will be used to generate + * The request producers passed to this method will be used to generate * a request message and stream out its content without buffering it - * in memory. The response consumer passed to this method will be used + * in memory. The response consumers passed to this method will be used * to process a response message without buffering its content in memory. * * @param the result type of request execution. - * @param requestProducer request producer callback. - * @param responseConsumer response consumer callaback. + * @param target the target host for the request. + * @param requestProducers list of request producers. + * @param responseConsumers list of response consumers. * @param callback future callback. * @return future representing pending completion of the operation. */ - Future execute( - HttpAsyncRequestProducer requestProducer, - HttpAsyncResponseConsumer responseConsumer, - FutureCallback callback); + Future> execute( + HttpHost target, + List requestProducers, + List> responseConsumers, + FutureCallback> callback); /** - * Initiates asynchronous HTTP request execution against the given target - * using the given context. + * Initiates pipelined execution of a sequence of requests against + * the given target using the given context. *

* Please note it may be unsafe to interact with the context instance * while the request is still being executed. * - * @param target the target host for the request. + * @param target the target host for the requests. * Implementations may accept {@code null} * if they can still determine a route, for example * to a default target or by inspecting the request. - * @param request the request to execute + * @param requests the requests to execute * @param context the context to use for the execution, or * {@code null} to use the default context * @param callback future callback. * @return future representing pending completion of the operation. */ - Future execute( - HttpHost target, HttpRequest request, HttpContext context, - FutureCallback callback); + Future> execute( + HttpHost target, + List requests, + HttpContext context, + FutureCallback> callback); /** - * Initiates asynchronous HTTP request execution against the given target - * using the default context. + * Initiates pipelined execution of a sequence of requests against + * the given target. * - * @param target the target host for the request. + * @param target the target host for the requests. * Implementations may accept {@code null} * if they can still determine a route, for example * to a default target or by inspecting the request. - * @param request the request to execute - * @param callback future callback. - * @return future representing pending completion of the operation. - */ - Future execute( - HttpHost target, HttpRequest request, - FutureCallback callback); - - /** - * Initiates asynchronous HTTP request execution using the given - * context. - *

- * Please note it may be unsafe to interact with the context instance - * while the request is still being executed. - * - * @param request the request to execute - * @param context HTTP context - * @param callback future callback. - * @return future representing pending completion of the operation. - */ - Future execute( - HttpUriRequest request, HttpContext context, - FutureCallback callback); - - /** - * Initiates asynchronous HTTP request execution using the default - * context. - * - * @param request the request to execute + * @param requests the requests to execute * @param callback future callback. * @return future representing pending completion of the operation. */ - Future execute( - HttpUriRequest request, - FutureCallback callback); + Future> execute( + HttpHost target, + List requests, + FutureCallback> callback); }