diff --git a/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java b/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java index 8f526e65f..262ab9d7b 100644 --- a/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java +++ b/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java @@ -229,5 +229,11 @@ public interface ManagedClientConnection extends boolean isMarkedReusable() ; + void setState(Object state) + ; + + boolean isStateful() + ; + } // interface ManagedClientConnection diff --git a/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java b/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java index b1d306fa4..7eeaa7f4e 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/AbstractPoolEntry.java @@ -75,7 +75,10 @@ public abstract class AbstractPoolEntry { //@@@ currently accessed from connection manager(s) as attribute //@@@ avoid that, derived classes should decide whether update is allowed //@@@ SCCM: yes, TSCCM: no - protected volatile ConnRoute route; + protected volatile HttpRoute route; + + /** Connection state object */ + protected volatile Object state; /** The tracked route, or null before tracking starts. */ protected volatile RouteTracker tracker; @@ -89,7 +92,7 @@ public abstract class AbstractPoolEntry { * or null */ protected AbstractPoolEntry(OperatedClientConnection occ, - ConnRoute route) { + HttpRoute route) { this.connection = occ; this.route = route; this.tracker = null; diff --git a/module-client/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java b/module-client/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java index 5b54be38f..9a8c19b69 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java @@ -170,5 +170,16 @@ public abstract class AbstractPooledConnAdapter extends AbstractClientConnAdapte } } + // non-javadoc, see interface ManagedClientConnection + public boolean isStateful() { + assertAttached(); + return poolEntry.state != null; + } + + // non-javadoc, see interface ManagedClientConnection + public void setState(final Object state) { + poolEntry.state = state; + } + } // class AbstractPooledConnAdapter diff --git a/module-client/src/main/java/org/apache/http/impl/conn/ConnRoute.java b/module-client/src/main/java/org/apache/http/impl/conn/ConnRoute.java deleted file mode 100644 index b358799f1..000000000 --- a/module-client/src/main/java/org/apache/http/impl/conn/ConnRoute.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * $HeadURL$ - * $Revision$ - * $Date$ - * - * ==================================================================== - * - * 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.conn; - -import org.apache.http.conn.routing.HttpRoute; -import org.apache.http.util.LangUtils; - -/** - * A route for {@link ManagedClientConnection} along with the state information - * associated with that connection. - * - * @author Oleg Kalnichevski - * - */ -public class ConnRoute { - - private final HttpRoute route; - private final Object state; - - public ConnRoute(final HttpRoute route, final Object state) { - super(); - if (route == null) { - throw new IllegalArgumentException("HTTP route may not be null"); - } - this.route = route; - this.state = state; - } - - public HttpRoute getRoute() { - return this.route; - } - - public Object getState() { - return this.state; - } - - @Override - public boolean equals(final Object obj) { - if (obj == null) return false; - if (this == obj) return true; - if (obj instanceof ConnRoute) { - ConnRoute that = (ConnRoute) obj; - return this.route.equals(that.route) - && LangUtils.equals(this.state, that.state); - } else { - return false; - } - } - - @Override - public int hashCode() { - int hash = LangUtils.HASH_SEED; - hash = LangUtils.hashCode(hash, this.route); - hash = LangUtils.hashCode(hash, this.state); - return hash; - } - - @Override - public String toString() { - StringBuilder buffer = new StringBuilder(); - buffer.append(this.route); - if (this.state != null) { - buffer.append(" ["); - buffer.append(this.state); - buffer.append("]"); - } - return buffer.toString(); - } - -} diff --git a/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java b/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java index 34638bafb..1b45f21a2 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java @@ -239,7 +239,7 @@ public class SingleClientConnManager implements ClientConnectionManager { } } - managedConn = new ConnAdapter(uniquePoolEntry, new ConnRoute(route, state)); + managedConn = new ConnAdapter(uniquePoolEntry, route); return managedConn; } @@ -420,11 +420,12 @@ public class SingleClientConnManager implements ClientConnectionManager { * @param entry the pool entry for the connection being wrapped * @param plan the planned route for this connection */ - protected ConnAdapter(PoolEntry entry, ConnRoute route) { + protected ConnAdapter(PoolEntry entry, HttpRoute route) { super(SingleClientConnManager.this, entry); markReusable(); entry.route = route; } + } diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java index 666a31b77..3214107da 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java @@ -47,9 +47,9 @@ import org.apache.http.conn.ClientConnectionOperator; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.ConnectionPoolTimeoutException; import org.apache.http.conn.OperatedClientConnection; +import org.apache.http.conn.routing.HttpRoute; import org.apache.http.params.HttpParams; import org.apache.http.impl.conn.IdleConnectionHandler; -import org.apache.http.impl.conn.ConnRoute; @@ -209,10 +209,14 @@ public abstract class AbstractConnPool implements RefQueueHandler { * if the calling thread was interrupted */ public final - BasicPoolEntry getEntry(ConnRoute route, long timeout, TimeUnit tunit, - ClientConnectionOperator operator) - throws ConnectionPoolTimeoutException, InterruptedException { - return newPoolEntryRequest().getPoolEntry(route, timeout, tunit, operator); + BasicPoolEntry getEntry( + HttpRoute route, + Object state, + long timeout, + TimeUnit tunit, + ClientConnectionOperator operator) + throws ConnectionPoolTimeoutException, InterruptedException { + return newPoolEntryRequest().getPoolEntry(route, state, timeout, tunit, operator); } /** @@ -247,7 +251,7 @@ public abstract class AbstractConnPool implements RefQueueHandler { //@@@ flag in the BasicPoolEntryRef, to be reset when freed? final boolean lost = issuedConnections.remove(ref); if (lost) { - final ConnRoute route = + final HttpRoute route = ((BasicPoolEntryRef)ref).getRoute(); if (LOG.isDebugEnabled()) { LOG.debug("Connection garbage collected. " + route); @@ -274,7 +278,7 @@ public abstract class AbstractConnPool implements RefQueueHandler { * * @param route the route of the pool entry that was lost */ - protected abstract void handleLostEntry(ConnRoute route) + protected abstract void handleLostEntry(HttpRoute route) ; diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java index dc3ff3ffe..3b1d72d80 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java @@ -35,8 +35,8 @@ import java.lang.ref.ReferenceQueue; import org.apache.http.conn.OperatedClientConnection; import org.apache.http.conn.ClientConnectionOperator; +import org.apache.http.conn.routing.HttpRoute; import org.apache.http.impl.conn.AbstractPoolEntry; -import org.apache.http.impl.conn.ConnRoute; @@ -67,7 +67,7 @@ public class BasicPoolEntry extends AbstractPoolEntry { * or null */ public BasicPoolEntry(ClientConnectionOperator op, - ConnRoute route, + HttpRoute route, ReferenceQueue queue) { //@@@ create connection in base? or delay creation until needed? super(op.createConnection(), route); @@ -92,7 +92,7 @@ public class BasicPoolEntry extends AbstractPoolEntry { return super.connection; } - protected final ConnRoute getPlannedRoute() { + protected final HttpRoute getPlannedRoute() { return super.route; } diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java index ae8bfeb03..e3391792e 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java @@ -34,7 +34,7 @@ package org.apache.http.impl.conn.tsccm; import java.lang.ref.WeakReference; import java.lang.ref.ReferenceQueue; -import org.apache.http.impl.conn.ConnRoute; +import org.apache.http.conn.routing.HttpRoute; @@ -46,7 +46,7 @@ import org.apache.http.impl.conn.ConnRoute; public class BasicPoolEntryRef extends WeakReference { /** The planned route of the entry. */ - private final ConnRoute route; + private final HttpRoute route; /** @@ -72,7 +72,7 @@ public class BasicPoolEntryRef extends WeakReference { * * @return the planned route */ - public final ConnRoute getRoute() { + public final HttpRoute getRoute() { return this.route; } diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java index c685d4f63..6bf16ffa4 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java @@ -46,7 +46,6 @@ import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.ClientConnectionOperator; import org.apache.http.conn.ConnectionPoolTimeoutException; import org.apache.http.conn.params.HttpConnectionManagerParams; -import org.apache.http.impl.conn.ConnRoute; @@ -84,7 +83,7 @@ public class ConnPoolByRoute extends AbstractConnPool { * Keys are of class {@link HttpRoute}, * values of class {@link RouteSpecificPool}. */ - protected final Map routeToPool; + protected final Map routeToPool; @@ -128,8 +127,8 @@ public class ConnPoolByRoute extends AbstractConnPool { * * @return a map */ - protected Map createRouteToPoolMap() { - return new HashMap(); + protected Map createRouteToPoolMap() { + return new HashMap(); } @@ -141,7 +140,7 @@ public class ConnPoolByRoute extends AbstractConnPool { * * @return the new pool */ - protected RouteSpecificPool newRouteSpecificPool(ConnRoute route) { + protected RouteSpecificPool newRouteSpecificPool(HttpRoute route) { return new RouteSpecificPool(route); } @@ -170,7 +169,7 @@ public class ConnPoolByRoute extends AbstractConnPool { * @return the pool for the argument route, * never null if create is true */ - protected RouteSpecificPool getRoutePool(ConnRoute route, + protected RouteSpecificPool getRoutePool(HttpRoute route, boolean create) { RouteSpecificPool rospl = null; @@ -193,7 +192,7 @@ public class ConnPoolByRoute extends AbstractConnPool { //@@@ consider alternatives for gathering statistics - public int getConnectionsInPool(ConnRoute route) { + public int getConnectionsInPool(HttpRoute route) { try { poolLock.lock(); @@ -224,12 +223,13 @@ public class ConnPoolByRoute extends AbstractConnPool { } public BasicPoolEntry getPoolEntry( - ConnRoute route, + HttpRoute route, + Object state, long timeout, TimeUnit tunit, ClientConnectionOperator operator) throws InterruptedException, ConnectionPoolTimeoutException { - return getEntryBlocking(route, timeout, tunit, operator, aborter); + return getEntryBlocking(route, state, timeout, tunit, operator, aborter); } }; @@ -256,14 +256,14 @@ public class ConnPoolByRoute extends AbstractConnPool { * if the calling thread was interrupted */ protected BasicPoolEntry getEntryBlocking( - ConnRoute route, + HttpRoute route, Object state, long timeout, TimeUnit tunit, ClientConnectionOperator operator, Aborter aborter) throws ConnectionPoolTimeoutException, InterruptedException { int maxHostConnections = HttpConnectionManagerParams - .getMaxConnectionsPerHost(this.params, route.getRoute()); + .getMaxConnectionsPerHost(this.params, route); int maxTotalConnections = HttpConnectionManagerParams .getMaxTotalConnections(this.params); @@ -363,7 +363,7 @@ public class ConnPoolByRoute extends AbstractConnPool { @Override public void freeEntry(BasicPoolEntry entry) { - ConnRoute route = entry.getPlannedRoute(); + HttpRoute route = entry.getPlannedRoute(); if (LOG.isDebugEnabled()) { LOG.debug("Freeing connection. " + route); } @@ -493,7 +493,7 @@ public class ConnPoolByRoute extends AbstractConnPool { */ protected void deleteEntry(BasicPoolEntry entry) { - ConnRoute route = entry.getPlannedRoute(); + HttpRoute route = entry.getPlannedRoute(); if (LOG.isDebugEnabled()) { LOG.debug("Deleting connection. " + route); @@ -546,7 +546,7 @@ public class ConnPoolByRoute extends AbstractConnPool { // non-javadoc, see base class AbstractConnPool @Override - protected void handleLostEntry(ConnRoute route) { + protected void handleLostEntry(HttpRoute route) { try { poolLock.lock(); diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/PoolEntryRequest.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/PoolEntryRequest.java index 8f02f6a50..fb81be541 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/PoolEntryRequest.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/PoolEntryRequest.java @@ -35,7 +35,6 @@ import java.util.concurrent.TimeUnit; import org.apache.http.conn.ClientConnectionOperator; import org.apache.http.conn.ConnectionPoolTimeoutException; import org.apache.http.conn.routing.HttpRoute; -import org.apache.http.impl.conn.ConnRoute; /** * Encapsulates a request for a {@link BasicPoolEntry}. @@ -62,7 +61,8 @@ public interface PoolEntryRequest { * if the calling thread was interrupted */ BasicPoolEntry getPoolEntry( - ConnRoute route, + HttpRoute route, + Object state, long timeout, TimeUnit unit, ClientConnectionOperator operator) diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java index a849aaeaf..a80733767 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java @@ -33,7 +33,7 @@ package org.apache.http.impl.conn.tsccm; import java.util.Queue; import java.util.LinkedList; -import org.apache.http.impl.conn.ConnRoute; +import org.apache.http.conn.routing.HttpRoute; /** @@ -44,7 +44,7 @@ import org.apache.http.impl.conn.ConnRoute; public class RouteSpecificPool { /** The route this pool is for. */ - protected final ConnRoute route; + protected final HttpRoute route; /** * The list of free entries. @@ -65,7 +65,7 @@ public class RouteSpecificPool { * * @param r the route for which to pool */ - public RouteSpecificPool(ConnRoute route) { + public RouteSpecificPool(HttpRoute route) { this.route = route; this.freeEntries = new LinkedList(); this.waitingThreads = new LinkedList(); @@ -78,7 +78,7 @@ public class RouteSpecificPool { * * @return the route */ - public final ConnRoute getRoute() { + public final HttpRoute getRoute() { return route; } diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java index 1b18870c7..0a80a25e9 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java @@ -45,7 +45,6 @@ import org.apache.http.conn.ManagedClientConnection; import org.apache.http.conn.OperatedClientConnection; import org.apache.http.params.HttpParams; import org.apache.http.impl.conn.DefaultClientConnectionOperator; -import org.apache.http.impl.conn.ConnRoute; @@ -171,7 +170,7 @@ public class ThreadSafeClientConnManager } final BasicPoolEntry entry = poolRequest.getPoolEntry( - new ConnRoute(route, state), timeout, tunit, connOperator); + route, state, timeout, tunit, connOperator); return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry); } @@ -242,9 +241,9 @@ public class ThreadSafeClientConnManager * * @return the total number of pooled connections for that route */ - public int getConnectionsInPool(HttpRoute route, Object state) { + public int getConnectionsInPool(HttpRoute route) { return ((ConnPoolByRoute)connectionPool).getConnectionsInPool( - new ConnRoute(route, state)); + route); } diff --git a/module-client/src/test/java/org/apache/http/impl/conn/ClientConnAdapterMockup.java b/module-client/src/test/java/org/apache/http/impl/conn/ClientConnAdapterMockup.java index 5ddc3ea31..1c2491a66 100644 --- a/module-client/src/test/java/org/apache/http/impl/conn/ClientConnAdapterMockup.java +++ b/module-client/src/test/java/org/apache/http/impl/conn/ClientConnAdapterMockup.java @@ -75,4 +75,11 @@ public class ClientConnAdapterMockup extends AbstractClientConnAdapter { throw new UnsupportedOperationException("just a mockup"); } + public boolean isStateful() { + throw new UnsupportedOperationException("just a mockup"); + } + + public void setState(Object state) { + throw new UnsupportedOperationException("just a mockup"); + } } diff --git a/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java b/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java index b8e1d70c3..68b0fd0b6 100644 --- a/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java +++ b/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java @@ -406,13 +406,13 @@ public class TestTSCCMNoServer extends TestCase { assertEquals("connectionsInPool", mgr.getConnectionsInPool(), 1); assertEquals("connectionsInPool(host)", - mgr.getConnectionsInPool(route, null), 1); + mgr.getConnectionsInPool(route), 1); mgr.releaseConnection(conn); assertEquals("connectionsInPool", mgr.getConnectionsInPool(), 1); assertEquals("connectionsInPool(host)", - mgr.getConnectionsInPool(route, null), 1); + mgr.getConnectionsInPool(route), 1); // this implicitly deletes them mgr.closeIdleConnections(0L, TimeUnit.MILLISECONDS); @@ -420,7 +420,7 @@ public class TestTSCCMNoServer extends TestCase { assertEquals("connectionsInPool", mgr.getConnectionsInPool(), 0); assertEquals("connectionsInPool(host)", - mgr.getConnectionsInPool(route, null), 0); + mgr.getConnectionsInPool(route), 0); mgr.shutdown(); } diff --git a/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestDumbHelpers.java b/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestDumbHelpers.java index c652b830a..33c27480e 100644 --- a/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestDumbHelpers.java +++ b/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestDumbHelpers.java @@ -50,7 +50,6 @@ import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.scheme.SocketFactory; import org.apache.http.conn.ClientConnectionOperator; import org.apache.http.impl.conn.DefaultClientConnectionOperator; -import org.apache.http.impl.conn.ConnRoute; @@ -114,13 +113,13 @@ public class TestDumbHelpers extends TestCase { // expected } - bpe = new BasicPoolEntry(ccop, new ConnRoute(route, null), null); + bpe = new BasicPoolEntry(ccop, route, null); assertEquals ("wrong operator", ccop, bpe.getOperator()); - assertEquals ("wrong route", route, bpe.getPlannedRoute().getRoute()); + assertEquals ("wrong route", route, bpe.getPlannedRoute()); assertNotNull("missing ref", bpe.getWeakRef()); assertEquals("bad weak ref", bpe, bpe.getWeakRef().get()); - assertEquals("bad ref route", route, bpe.getWeakRef().getRoute().getRoute()); + assertEquals("bad ref route", route, bpe.getWeakRef().getRoute()); } diff --git a/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java b/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java index 6a1a44bd5..1e24be85a 100644 --- a/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java +++ b/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java @@ -40,7 +40,6 @@ import junit.framework.TestSuite; import org.apache.http.HttpHost; import org.apache.http.conn.routing.HttpRoute; -import org.apache.http.impl.conn.ConnRoute; @@ -84,7 +83,7 @@ public class TestWaitingThread extends TestCase { assertNull ("thread from nowhere", wt.getThread()); HttpRoute route = new HttpRoute(TARGET); - RouteSpecificPool rospl = new RouteSpecificPool(new ConnRoute(route, null)); + RouteSpecificPool rospl = new RouteSpecificPool(route); wt = new WaitingThread(cnd, rospl); assertEquals("wrong condition", cnd, wt.getCondition()); assertEquals("wrong pool", rospl, wt.getPool());