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 2011/02/01 13:57:58 UTC
svn commit: r1066034 - in /httpcomponents/httpasyncclient/trunk: ./
httpasyncclient/src/main/java/org/apache/http/impl/nio/client/
httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/
httpasyncclient/src/main/java/org/apache/http/impl/nio/pool/...
Author: olegk
Date: Tue Feb 1 12:57:58 2011
New Revision: 1066034
URL: http://svn.apache.org/viewvc?rev=1066034&view=rev
Log:
Upgraded HttpClient dependency to version 4.1; code refactored in several areas
Added:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java (with props)
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java (with props)
Removed:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncResponseSet.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResponseCompletedCallback.java
Modified:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultHttpAsyncClient.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ClientConnAdaptor.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingClientConnectionManager.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/pool/SessionPool.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ClientConnectionManager.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ManagedClientConnection.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java
httpcomponents/httpasyncclient/trunk/pom.xml
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java?rev=1066034&r1=1066033&r2=1066034&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java Tue Feb 1 12:57:58 2011
@@ -28,7 +28,8 @@ package org.apache.http.impl.nio.client;
import java.io.IOException;
import java.net.URI;
-import java.util.Iterator;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Future;
import org.apache.commons.logging.Log;
@@ -43,6 +44,7 @@ import org.apache.http.client.ClientProt
import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.client.utils.URIUtils;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.conn.routing.HttpRoutePlanner;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
@@ -52,12 +54,12 @@ import org.apache.http.impl.nio.conn.Def
import org.apache.http.impl.nio.conn.PoolingClientConnectionManager;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.nio.client.HttpAsyncClient;
+import org.apache.http.nio.client.HttpAsyncExchangeHandler;
import org.apache.http.nio.client.HttpAsyncRequestProducer;
import org.apache.http.nio.client.HttpAsyncResponseConsumer;
import org.apache.http.nio.concurrent.BasicFuture;
import org.apache.http.nio.concurrent.FutureCallback;
import org.apache.http.nio.conn.ClientConnectionManager;
-import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.nio.reactor.IOReactorStatus;
@@ -71,9 +73,8 @@ import org.apache.http.protocol.Immutabl
public abstract class AbstractHttpAsyncClient implements HttpAsyncClient {
private final Log log = LogFactory.getLog(getClass());;
- private final ConnectingIOReactor ioReactor;
private final ClientConnectionManager connmgr;
- private final HttpAsyncResponseSet pendingResponses;
+ private final Queue<HttpAsyncExchangeHandler<?>> queue;
private Thread reactorThread;
private BasicHttpProcessor mutableProcessor;
@@ -84,14 +85,14 @@ public abstract class AbstractHttpAsyncC
private HttpRoutePlanner routePlanner;
private HttpParams params;
+ private volatile boolean terminated;
+
protected AbstractHttpAsyncClient(
- final ConnectingIOReactor ioReactor,
final ClientConnectionManager connmgr,
final HttpParams params) {
super();
- this.ioReactor = ioReactor;
this.connmgr = connmgr;
- this.pendingResponses = new HttpAsyncResponseSet();
+ this.queue = new ConcurrentLinkedQueue<HttpAsyncExchangeHandler<?>>();
this.params = params;
}
@@ -102,9 +103,8 @@ public abstract class AbstractHttpAsyncC
}
DefaultConnectingIOReactor defaultioreactor = new DefaultConnectingIOReactor(2, params);
defaultioreactor.setExceptionHandler(new InternalIOReactorExceptionHandler(this.log));
- this.ioReactor = defaultioreactor;
- this.connmgr = new PoolingClientConnectionManager(this.ioReactor);
- this.pendingResponses = new HttpAsyncResponseSet();
+ this.connmgr = new PoolingClientConnectionManager(defaultioreactor);
+ this.queue = new ConcurrentLinkedQueue<HttpAsyncExchangeHandler<?>>();
this.params = params;
}
@@ -274,20 +274,20 @@ public abstract class AbstractHttpAsyncC
NHttpClientProtocolHandler handler = new NHttpClientProtocolHandler();
try {
IOEventDispatch ioEventDispatch = new InternalClientEventDispatch(handler);
- this.ioReactor.execute(ioEventDispatch);
+ this.connmgr.execute(ioEventDispatch);
} catch (Exception ex) {
this.log.error("I/O reactor terminated abnormally", ex);
- Iterator<HttpAsyncResponseConsumer<?>> it = this.pendingResponses.iterator();
- while (it.hasNext()) {
- HttpAsyncResponseConsumer<?> responseConsumer = it.next();
- responseConsumer.failed(ex);
- it.remove();
+ } finally {
+ this.terminated = true;
+ while (!this.queue.isEmpty()) {
+ HttpAsyncResponseConsumer<?> responseConsumer = this.queue.remove();
+ responseConsumer.cancel();
}
}
}
public IOReactorStatus getStatus() {
- return this.ioReactor.getStatus();
+ return this.connmgr.getStatus();
}
public synchronized void start() {
@@ -303,9 +303,8 @@ public abstract class AbstractHttpAsyncC
}
public synchronized void shutdown() throws InterruptedException {
- this.connmgr.shutdown();
try {
- this.ioReactor.shutdown(5000);
+ this.connmgr.shutdown(5000);
} catch (IOException ex) {
this.log.error("I/O error shutting down", ex);
}
@@ -319,7 +318,11 @@ public abstract class AbstractHttpAsyncC
final HttpAsyncResponseConsumer<T> responseConsumer,
final HttpContext context,
final FutureCallback<T> callback) {
- this.pendingResponses.add(responseConsumer);
+ if (this.terminated) {
+ throw new IllegalStateException("Client terminated");
+ }
+ BasicFuture<T> future = new BasicFuture<T>(callback);
+ ResultCallback<T> resultCallback = new DefaultResultCallback<T>(future, this.queue);
DefaultAsyncRequestDirector<T> httpexchange;
synchronized (this) {
httpexchange = new DefaultAsyncRequestDirector<T>(
@@ -327,8 +330,7 @@ public abstract class AbstractHttpAsyncC
requestProducer,
responseConsumer,
context,
- new ResponseCompletedCallback<T>(callback,
- responseConsumer, this.pendingResponses),
+ resultCallback,
this.connmgr,
getProtocolProcessor(),
getRoutePlanner(),
@@ -337,8 +339,9 @@ public abstract class AbstractHttpAsyncC
getRedirectStrategy(),
getParams());
}
+ this.queue.add(httpexchange);
httpexchange.start();
- return httpexchange.getResultFuture();
+ return future;
}
public <T> Future<T> execute(
@@ -370,12 +373,11 @@ public abstract class AbstractHttpAsyncC
URI requestURI = request.getURI();
if (requestURI.isAbsolute()) {
- if (requestURI.getHost() == null) {
+ target = URIUtils.extractHost(requestURI);
+ if (target == null) {
throw new ClientProtocolException(
"URI does not specify a valid host name: " + requestURI);
}
- target = new HttpHost(requestURI.getHost(), requestURI.getPort(), requestURI.getScheme());
- // TODO use URIUtils#extractTarget once it becomes available
}
return target;
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java?rev=1066034&r1=1066033&r2=1066034&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java Tue Feb 1 12:57:58 2011
@@ -68,7 +68,6 @@ import org.apache.http.nio.IOControl;
import org.apache.http.nio.client.HttpAsyncExchangeHandler;
import org.apache.http.nio.client.HttpAsyncRequestProducer;
import org.apache.http.nio.client.HttpAsyncResponseConsumer;
-import org.apache.http.nio.concurrent.BasicFuture;
import org.apache.http.nio.concurrent.FutureCallback;
import org.apache.http.nio.conn.ClientConnectionManager;
import org.apache.http.nio.conn.ManagedClientConnection;
@@ -89,7 +88,7 @@ class DefaultAsyncRequestDirector<T> imp
private final HttpAsyncRequestProducer requestProducer;
private final HttpAsyncResponseConsumer<T> responseConsumer;
private final HttpContext localContext;
- private final BasicFuture<T> resultFuture;
+ private final ResultCallback<T> resultCallback;
private final ClientConnectionManager connmgr;
private final HttpProcessor httppocessor;
private final HttpRoutePlanner routePlanner;
@@ -119,7 +118,7 @@ class DefaultAsyncRequestDirector<T> imp
final HttpAsyncRequestProducer requestProducer,
final HttpAsyncResponseConsumer<T> responseConsumer,
final HttpContext localContext,
- final FutureCallback<T> callback,
+ final ResultCallback<T> callback,
final ClientConnectionManager connmgr,
final HttpProcessor httppocessor,
final HttpRoutePlanner routePlanner,
@@ -132,7 +131,7 @@ class DefaultAsyncRequestDirector<T> imp
this.requestProducer = requestProducer;
this.responseConsumer = responseConsumer;
this.localContext = localContext;
- this.resultFuture = new BasicFuture<T>(callback);
+ this.resultCallback = callback;
this.connmgr = connmgr;
this.httppocessor = httppocessor;
this.routePlanner = routePlanner;
@@ -160,10 +159,6 @@ class DefaultAsyncRequestDirector<T> imp
}
}
- public Future<T> getResultFuture() {
- return this.resultFuture;
- }
-
public HttpHost getTarget() {
return this.requestProducer.getTarget();
}
@@ -220,6 +215,7 @@ class DefaultAsyncRequestDirector<T> imp
this.localContext.setAttribute(ExecutionContext.HTTP_REQUEST, this.currentRequest);
this.localContext.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
this.localContext.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy);
+ this.localContext.setAttribute(ExecutionContext.HTTP_CONNECTION, this.managedConn);
this.httppocessor.process(this.currentRequest, this.localContext);
if (this.log.isDebugEnabled()) {
this.log.debug("Request submitted: " + this.currentRequest.getRequestLine());
@@ -308,7 +304,7 @@ class DefaultAsyncRequestDirector<T> imp
this.responseConsumer.failed(ex);
} finally {
try {
- this.resultFuture.failed(ex);
+ this.resultCallback.failed(ex, this);
} finally {
releaseResources();
}
@@ -340,7 +336,7 @@ class DefaultAsyncRequestDirector<T> imp
if (this.finalResponse != null) {
this.responseConsumer.responseCompleted();
this.log.debug("Response processed");
- this.resultFuture.completed(this.responseConsumer.getResult());
+ this.resultCallback.completed(this.responseConsumer.getResult(), this);
releaseResources();
} else {
if (this.followup != null) {
@@ -370,7 +366,7 @@ class DefaultAsyncRequestDirector<T> imp
this.log.debug("HTTP exchange cancelled");
try {
this.responseConsumer.cancel();
- this.resultFuture.cancel(true);
+ this.resultCallback.cancelled(this);
releaseResources();
} catch (RuntimeException runex) {
failed(runex);
@@ -379,7 +375,7 @@ class DefaultAsyncRequestDirector<T> imp
}
public boolean isDone() {
- return this.resultFuture.isDone();
+ return this.resultCallback.isDone();
}
public T getResult() {
@@ -413,7 +409,7 @@ class DefaultAsyncRequestDirector<T> imp
this.requestProducer.resetRequest();
this.responseConsumer.failed(ex);
} finally {
- this.resultFuture.failed(ex);
+ this.resultCallback.failed(ex, this);
}
}
@@ -423,7 +419,7 @@ class DefaultAsyncRequestDirector<T> imp
this.requestProducer.resetRequest();
this.responseConsumer.cancel();
} finally {
- this.resultFuture.cancel(true);
+ this.resultCallback.cancelled(this);
}
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultHttpAsyncClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultHttpAsyncClient.java?rev=1066034&r1=1066033&r2=1066034&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultHttpAsyncClient.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultHttpAsyncClient.java Tue Feb 1 12:57:58 2011
@@ -27,10 +27,10 @@
package org.apache.http.impl.nio.client;
import org.apache.http.HttpVersion;
+import org.apache.http.client.protocol.RequestClientConnControl;
import org.apache.http.client.protocol.RequestDefaultHeaders;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.nio.conn.ClientConnectionManager;
-import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
@@ -38,7 +38,6 @@ import org.apache.http.params.HttpProtoc
import org.apache.http.params.SyncBasicHttpParams;
import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.HTTP;
-import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
@@ -48,10 +47,9 @@ import org.apache.http.util.VersionInfo;
public class DefaultHttpAsyncClient extends AbstractHttpAsyncClient {
public DefaultHttpAsyncClient(
- final ConnectingIOReactor ioReactor,
final ClientConnectionManager connmgr,
final HttpParams params) {
- super(ioReactor, connmgr, params);
+ super(connmgr, params);
}
public DefaultHttpAsyncClient(
@@ -60,13 +58,12 @@ public class DefaultHttpAsyncClient exte
}
public DefaultHttpAsyncClient() throws IOReactorException {
- this(null);
+ super(null);
}
public DefaultHttpAsyncClient(
- final ConnectingIOReactor ioReactor,
final ClientConnectionManager connmgr) throws IOReactorException {
- this(ioReactor, connmgr, null);
+ this(connmgr, null);
}
@Override
@@ -99,7 +96,7 @@ public class DefaultHttpAsyncClient exte
httpproc.addInterceptor(new RequestContent());
httpproc.addInterceptor(new RequestTargetHost());
// Recommended protocol interceptors
- httpproc.addInterceptor(new RequestConnControl());
+ httpproc.addInterceptor(new RequestClientConnControl());
httpproc.addInterceptor(new RequestUserAgent());
httpproc.addInterceptor(new RequestExpectContinue());
return httpproc;
Added: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java?rev=1066034&view=auto
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java (added)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java Tue Feb 1 12:57:58 2011
@@ -0,0 +1,65 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.nio.client;
+
+import java.util.Queue;
+
+import org.apache.http.nio.client.HttpAsyncExchangeHandler;
+import org.apache.http.nio.concurrent.BasicFuture;
+
+class DefaultResultCallback<T> implements ResultCallback<T> {
+
+ private final BasicFuture<T> future;
+ private final Queue<HttpAsyncExchangeHandler<?>> queue;
+
+ DefaultResultCallback(
+ final BasicFuture<T> future, final Queue<HttpAsyncExchangeHandler<?>> queue) {
+ super();
+ this.future = future;
+ this.queue = queue;
+ }
+
+ public void completed(final T result, final HttpAsyncExchangeHandler<T> handler) {
+ this.future.completed(result);
+ this.queue.remove(handler);
+ }
+
+ public void failed(final Exception ex, final HttpAsyncExchangeHandler<T> handler) {
+ this.future.failed(ex);
+ this.queue.remove(handler);
+ }
+
+ public void cancelled(final HttpAsyncExchangeHandler<T> handler) {
+ this.future.cancel(true);
+ this.queue.remove(handler);
+ }
+
+ public boolean isDone() {
+ return this.future.isDone();
+ }
+
+}
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java?rev=1066034&view=auto
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java (added)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java Tue Feb 1 12:57:58 2011
@@ -0,0 +1,41 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.nio.client;
+
+import org.apache.http.nio.client.HttpAsyncExchangeHandler;
+
+interface ResultCallback<T> {
+
+ void completed(T result, HttpAsyncExchangeHandler<T> handler);
+
+ void failed(Exception ex, HttpAsyncExchangeHandler<T> handler);
+
+ void cancelled(HttpAsyncExchangeHandler<T> handler);
+
+ boolean isDone();
+
+}
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ClientConnAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ClientConnAdaptor.java?rev=1066034&r1=1066033&r2=1066034&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ClientConnAdaptor.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ClientConnAdaptor.java Tue Feb 1 12:57:58 2011
@@ -27,11 +27,15 @@
package org.apache.http.impl.nio.conn;
import java.io.IOException;
+import java.net.InetAddress;
import java.util.concurrent.TimeUnit;
+import javax.net.ssl.SSLSession;
+
import org.apache.http.HttpConnectionMetrics;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
+import org.apache.http.HttpInetConnection;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseFactory;
@@ -183,6 +187,56 @@ class ClientConnAdaptor implements Manag
return this.entry.getEffectiveRoute();
}
+ public SSLSession getSSLSession() {
+ return null;
+ }
+
+ public boolean isSecure() {
+ assertValid();
+ OperatedClientConnection conn = getWrappedConnection();
+ return conn.getSSLIOSession() != null;
+ }
+
+ public InetAddress getLocalAddress() {
+ assertValid();
+ OperatedClientConnection conn = getWrappedConnection();
+ if (conn instanceof HttpInetConnection) {
+ return ((HttpInetConnection) conn).getLocalAddress();
+ } else {
+ return null;
+ }
+ }
+
+ public int getLocalPort() {
+ assertValid();
+ OperatedClientConnection conn = getWrappedConnection();
+ if (conn instanceof HttpInetConnection) {
+ return ((HttpInetConnection) conn).getLocalPort();
+ } else {
+ return -1;
+ }
+ }
+
+ public InetAddress getRemoteAddress() {
+ assertValid();
+ OperatedClientConnection conn = getWrappedConnection();
+ if (conn instanceof HttpInetConnection) {
+ return ((HttpInetConnection) conn).getRemoteAddress();
+ } else {
+ return null;
+ }
+ }
+
+ public int getRemotePort() {
+ assertValid();
+ OperatedClientConnection conn = getWrappedConnection();
+ if (conn instanceof HttpInetConnection) {
+ return ((HttpInetConnection) conn).getRemotePort();
+ } else {
+ return -1;
+ }
+ }
+
public synchronized HttpConnectionMetrics getMetrics() {
assertValid();
OperatedClientConnection conn = getWrappedConnection();
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingClientConnectionManager.java?rev=1066034&r1=1066033&r2=1066034&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingClientConnectionManager.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingClientConnectionManager.java Tue Feb 1 12:57:58 2011
@@ -26,6 +26,7 @@
*/
package org.apache.http.impl.nio.conn;
+import java.io.IOException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -40,11 +41,15 @@ import org.apache.http.nio.conn.ClientCo
import org.apache.http.nio.conn.PoolStats;
import org.apache.http.nio.conn.scheme.SchemeRegistry;
import org.apache.http.nio.reactor.ConnectingIOReactor;
+import org.apache.http.nio.reactor.IOEventDispatch;
+import org.apache.http.nio.reactor.IOReactorException;
+import org.apache.http.nio.reactor.IOReactorStatus;
public class PoolingClientConnectionManager implements ClientConnectionManager {
private final Log log = LogFactory.getLog(getClass());
+ private final ConnectingIOReactor ioreactor;
private final HttpSessionPool pool;
private final SchemeRegistry schemeRegistry;
@@ -62,25 +67,44 @@ public class PoolingClientConnectionMana
if (tunit == null) {
throw new IllegalArgumentException("Time unit may not be null");
}
+ this.ioreactor = ioreactor;
this.pool = new HttpSessionPool(this.log, ioreactor, schemeRegistry, timeToLive, tunit);
this.schemeRegistry = schemeRegistry;
}
public PoolingClientConnectionManager(
final ConnectingIOReactor ioreactor,
- final SchemeRegistry schemeRegistry) {
+ final SchemeRegistry schemeRegistry) throws IOReactorException {
this(ioreactor, schemeRegistry, -1, TimeUnit.MILLISECONDS);
}
public PoolingClientConnectionManager(
- final ConnectingIOReactor ioreactor) {
- this(ioreactor, SchemeRegistryFactory.createDefault(), -1, TimeUnit.MILLISECONDS);
+ final ConnectingIOReactor ioreactor) throws IOReactorException {
+ this(ioreactor, SchemeRegistryFactory.createDefault());
}
public SchemeRegistry getSchemeRegistry() {
return this.schemeRegistry;
}
+ public void execute(final IOEventDispatch eventDispatch) throws IOException {
+ this.ioreactor.execute(eventDispatch);
+ }
+
+ public IOReactorStatus getStatus() {
+ return this.ioreactor.getStatus();
+ }
+
+ public void shutdown(long waitMs) throws IOException {
+ this.log.debug("Connection manager shut down");
+ this.pool.shutdown(waitMs);
+ }
+
+ public void shutdown() throws IOException {
+ this.log.debug("Connection manager shut down");
+ this.pool.shutdown(2000);
+ }
+
public Future<ManagedClientConnection> leaseConnection(
final HttpRoute route,
final Object state,
@@ -193,11 +217,6 @@ public class PoolingClientConnectionMana
this.pool.closeExpired();
}
- public void shutdown() {
- this.log.debug("Connection manager shut down");
- this.pool.shutdown();
- }
-
class InternalPoolEntryCallback implements PoolEntryCallback<HttpRoute, HttpPoolEntry> {
private final BasicFuture<ManagedClientConnection> future;
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/pool/SessionPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/pool/SessionPool.java?rev=1066034&r1=1066033&r2=1066034&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/pool/SessionPool.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/pool/SessionPool.java Tue Feb 1 12:57:58 2011
@@ -26,6 +26,7 @@
*/
package org.apache.http.impl.nio.pool;
+import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -92,7 +93,7 @@ public abstract class SessionPool<T, E e
this.maxTotal = maxTotal;
}
- public void shutdown() {
+ public void shutdown(long waitMs) throws IOException {
if (this.isShutDown) {
return ;
}
@@ -108,6 +109,7 @@ public abstract class SessionPool<T, E e
this.pendingSessions.clear();
this.availableSessions.clear();
this.leasingRequests.clear();
+ this.ioreactor.shutdown(waitMs);
} finally {
this.lock.unlock();
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ClientConnectionManager.java?rev=1066034&r1=1066033&r2=1066034&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ClientConnectionManager.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ClientConnectionManager.java Tue Feb 1 12:57:58 2011
@@ -32,8 +32,9 @@ import java.util.concurrent.TimeUnit;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.nio.concurrent.FutureCallback;
import org.apache.http.nio.conn.scheme.SchemeRegistry;
+import org.apache.http.nio.reactor.IOReactor;
-public interface ClientConnectionManager {
+public interface ClientConnectionManager extends IOReactor {
SchemeRegistry getSchemeRegistry();
@@ -45,6 +46,4 @@ public interface ClientConnectionManager
void releaseConnection(ManagedClientConnection session,
long validDuration, TimeUnit timeUnit);
- void shutdown();
-
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ManagedClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ManagedClientConnection.java?rev=1066034&r1=1066033&r2=1066034&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ManagedClientConnection.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/conn/ManagedClientConnection.java Tue Feb 1 12:57:58 2011
@@ -31,14 +31,14 @@ import java.util.concurrent.TimeUnit;
import org.apache.http.HttpHost;
import org.apache.http.conn.ConnectionReleaseTrigger;
+import org.apache.http.conn.HttpRoutedConnection;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.nio.NHttpClientConnection;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
-public interface ManagedClientConnection extends NHttpClientConnection, ConnectionReleaseTrigger {
-
- HttpRoute getRoute();
+public interface ManagedClientConnection
+ extends HttpRoutedConnection, NHttpClientConnection, ConnectionReleaseTrigger {
Object getState();
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java?rev=1066034&r1=1066033&r2=1066034&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java Tue Feb 1 12:57:58 2011
@@ -72,7 +72,7 @@ public class TestHttpAsync extends Serve
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, null));
this.sessionManager = new PoolingClientConnectionManager(ioReactor, schemeRegistry);
- this.httpclient = new DefaultHttpAsyncClient(ioReactor, this.sessionManager);
+ this.httpclient = new DefaultHttpAsyncClient(this.sessionManager);
}
@After
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java?rev=1066034&r1=1066033&r2=1066034&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java Tue Feb 1 12:57:58 2011
@@ -127,7 +127,7 @@ public class TestHttpsAsync extends Serv
schemeRegistry.register(new Scheme("http", 80, null));
schemeRegistry.register(new Scheme("https", 443, new SSLLayeringStrategy(this.clientSSLContext)));
this.sessionManager = new PoolingClientConnectionManager(ioReactor, schemeRegistry);
- this.httpclient = new DefaultHttpAsyncClient(ioReactor, this.sessionManager);
+ this.httpclient = new DefaultHttpAsyncClient(this.sessionManager);
}
@After
Modified: httpcomponents/httpasyncclient/trunk/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/pom.xml?rev=1066034&r1=1066033&r2=1066034&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/pom.xml (original)
+++ httpcomponents/httpasyncclient/trunk/pom.xml Tue Feb 1 12:57:58 2011
@@ -73,7 +73,7 @@
<maven.compile.optimize>true</maven.compile.optimize>
<maven.compile.deprecation>true</maven.compile.deprecation>
<httpcore.version>4.1</httpcore.version>
- <httpclient.version>4.1-beta1</httpclient.version>
+ <httpclient.version>4.1</httpclient.version>
<commons-logging.version>1.1.1</commons-logging.version>
<junit.version>4.8.1</junit.version>
</properties>