hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1042785 - in /httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http: impl/nio/client/ impl/nio/conn/ impl/nio/pool/ nio/conn/
Date Mon, 06 Dec 2010 20:43:40 GMT
Author: olegk
Date: Mon Dec  6 20:43:40 2010
New Revision: 1042785

URL: http://svn.apache.org/viewvc?rev=1042785&view=rev
Log:
Added parameters to specify a connect timeout when leasing an I/O session

Modified:
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/pool/SessionPool.java
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/conn/IOSessionManager.java

Modified: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java?rev=1042785&r1=1042784&r2=1042785&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
Mon Dec  6 20:43:40 2010
@@ -29,6 +29,7 @@ package org.apache.http.impl.nio.client;
 import java.io.IOException;
 import java.nio.channels.SelectionKey;
 import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
@@ -80,7 +81,8 @@ class DefaultAsyncRequestDirector<T> imp
         this.params = params;
 
         HttpRoute route = new HttpRoute(handler.getTarget());
-        this.sessionFuture = this.sessmrg.leaseSession(route, null, new InternalFutureCallback());
+        this.sessionFuture = this.sessmrg.leaseSession(
+                route, null, 0, TimeUnit.MILLISECONDS, new InternalFutureCallback());
     }
 
     public Future<T> getResultFuture() {

Modified: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java?rev=1042785&r1=1042784&r2=1042785&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/conn/BasicIOSessionManager.java
Mon Dec  6 20:43:40 2010
@@ -27,6 +27,7 @@
 package org.apache.http.impl.nio.conn;
 
 import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -58,6 +59,8 @@ public class BasicIOSessionManager imple
     public synchronized Future<ManagedIOSession> leaseSession(
             final HttpRoute route,
             final Object state,
+            final long connectTimeout,
+            final TimeUnit timeUnit,
             final FutureCallback<ManagedIOSession> callback) {
         if (this.log.isDebugEnabled()) {
             this.log.debug("I/O session request: route[" + route + "][state: " + state +
"]");
@@ -68,7 +71,7 @@ public class BasicIOSessionManager imple
         }
         BasicFuture<ManagedIOSession> future = new BasicFuture<ManagedIOSession>(
                 callback);
-        this.pool.lease(route, state, new InternalPoolEntryCallback(future));
+        this.pool.lease(route, state, connectTimeout, timeUnit, new InternalPoolEntryCallback(future));
         if (this.log.isDebugEnabled()) {
             if (!future.isDone()) {
                 this.log.debug("I/O session could not be allocated immediately: " +

Modified: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java?rev=1042785&r1=1042784&r2=1042785&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/pool/LeaseRequest.java
Mon Dec  6 20:43:40 2010
@@ -30,15 +30,18 @@ class LeaseRequest<T> {
 
     private final T route;
     private final Object state;
+    private final int connectTimeout;
     private final PoolEntryCallback<T> callback;
 
     public LeaseRequest(
             final T route,
             final Object state,
+            final int connectTimeout,
             final PoolEntryCallback<T> callback) {
         super();
         this.route = route;
         this.state = state;
+        this.connectTimeout = connectTimeout;
         this.callback = callback;
     }
 
@@ -54,6 +57,10 @@ class LeaseRequest<T> {
         return this.callback;
     }
 
+    public int getConnectTimeout() {
+        return this.connectTimeout;
+    }
+
     @Override
     public String toString() {
         StringBuilder buffer = new StringBuilder();

Modified: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/pool/SessionPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/pool/SessionPool.java?rev=1042785&r1=1042784&r2=1042785&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/pool/SessionPool.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/pool/SessionPool.java
Mon Dec  6 20:43:40 2010
@@ -32,6 +32,7 @@ import java.util.LinkedList;
 import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -114,13 +115,21 @@ public class SessionPool<T> {
         return pool;
     }
 
-    public void lease(final T route, final Object state, final PoolEntryCallback<T>
callback) {
+    public void lease(
+            final T route, final Object state,
+            final long connectTimeout, final TimeUnit timeUnit,
+            final PoolEntryCallback<T> callback) {
         if (this.isShutDown) {
             throw new IllegalStateException("Session pool has been shut down");
         }
         this.lock.lock();
         try {
-            LeaseRequest<T> request = new LeaseRequest<T>(route, state, callback);
+            TimeUnit unit = timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS;
+            int timeout = (int) unit.toMillis(connectTimeout);
+            if (timeout < 0) {
+                timeout = 0;
+            }
+            LeaseRequest<T> request = new LeaseRequest<T>(route, state, timeout,
callback);
             this.leasingRequests.add(request);
 
             processPendingRequests();
@@ -166,6 +175,7 @@ public class SessionPool<T> {
 
             T route = request.getRoute();
             Object state = request.getState();
+            int timeout = request.getConnectTimeout();
             PoolEntryCallback<T> callback = request.getCallback();
 
             if (getAllocatedTotal() >= this.maxTotal) {
@@ -200,6 +210,7 @@ public class SessionPool<T> {
                             this.routeResolver.resolveLocalAddress(route),
                             route,
                             this.sessionRequestCallback);
+                    sessionRequest.setConnectTimeout(timeout);
                     pool.addPending(sessionRequest, callback);
                 }
             }

Modified: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/conn/IOSessionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/conn/IOSessionManager.java?rev=1042785&r1=1042784&r2=1042785&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/conn/IOSessionManager.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/conn/IOSessionManager.java
Mon Dec  6 20:43:40 2010
@@ -27,13 +27,16 @@
 package org.apache.http.nio.conn;
 
 import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.http.nio.concurrent.FutureCallback;
 
 public interface IOSessionManager<T> {
 
     Future<ManagedIOSession> leaseSession(
-            T route, Object state, FutureCallback<ManagedIOSession> callback);
+            T route, Object state,
+            long connectTimeout, TimeUnit timeUnit,
+            FutureCallback<ManagedIOSession> callback);
 
     void releaseSession(ManagedIOSession session);
 



Mime
View raw message