Author: kwright
Date: Sun Dec 15 21:32:06 2013
New Revision: 1551062
URL: http://svn.apache.org/r1551062
Log:
Flesh out method to decide whether to destroy a connection from the pool.
Modified:
manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java
manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java
Modified:
manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java?rev=1551062&r1=1551061&r2=1551062&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java
(original)
+++
manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionBin.java
Sun Dec 15 21:32:06 2013
@@ -152,6 +152,42 @@ public class ConnectionBin
return inUseConnections > maxActiveConnections;
}
+ public static final int CONNECTION_DESTROY = 0;
+ public static final int CONNECTION_POOLEMPTY = 1;
+ public static final int CONNECTION_WITHINBOUNDS =2;
+
+ /** Figure out whether we are currently over target or not for this bin, and
whether a
+ * connection should be pulled from the pool and destroyed.
+ * Note that this is tricky in conjunction with other bins, because those
other bins
+ * may conclude that we can't destroy a connection. If so, we just return
the stolen
+ * connection back to the pool.
+ *@return CONNECTION_DESTROY, CONNECTION_POOLEMPTY, or
CONNECTION_WITHINBOUNDS.
+ */
+ public synchronized int shouldPooledConnectionBeDestroyed(AtomicInteger
poolCount)
+ {
+ int currentPoolCount = poolCount.get();
+ if (currentPoolCount > 0)
+ {
+ // Consider it removed from the pool for the purposes of consideration.
If we change our minds, we'll
+ // return it, and no harm done.
+ poolCount.set(currentPoolCount-1);
+ // We don't count reserved connections here because those are not yet
committed.
+ if (inUseConnections > maxActiveConnections)
+ {
+ return CONNECTION_DESTROY;
+ }
+ return CONNECTION_WITHINBOUNDS;
+ }
+ return CONNECTION_POOLEMPTY;
+ }
+
+ /** Undo the decision to destroy a pooled connection.
+ */
+ public synchronized void undoPooledConnectionDecision(AtomicInteger
poolCount)
+ {
+ poolCount.set(poolCount.get() + 1);
+ }
+
/** Note a connection returned to the pool.
*/
public synchronized void noteConnectionReturnedToPool(AtomicInteger
poolCount)
Modified:
manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java?rev=1551062&r1=1551061&r2=1551062&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java
(original)
+++
manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/Throttler.java
Sun Dec 15 21:32:06 2013
@@ -482,6 +482,58 @@ public class Throttler
}
}
+ public boolean checkDestroyPooledConnection(String[] binNames,
AtomicInteger poolCount)
+ {
+ // Only if all believe we can destroy a pool connection, will we do it.
+ // This is because some pools may be empty, etc.
+ synchronized (connectionBins)
+ {
+ boolean destroyConnection = false;
+
+ int i = 0;
+ while (i < binNames.length)
+ {
+ String binName = binNames[i];
+ ConnectionBin bin = connectionBins.get(binName);
+ if (bin != null)
+ {
+ int result = bin.shouldPooledConnectionBeDestroyed(poolCount);
+ if (result == ConnectionBin.CONNECTION_POOLEMPTY)
+ {
+ // Give up now, and undo all the other bins
+ while (i > 0)
+ {
+ i--;
+ binName = binNames[i];
+ bin = connectionBins.get(binName);
+ bin.undoPooledConnectionDecision(poolCount);
+ }
+ return false;
+ }
+ else if (result == ConnectionBin.CONNECTION_DESTROY)
+ {
+ destroyConnection = true;
+ }
+ }
+ i++;
+ }
+
+ if (destroyConnection)
+ return true;
+
+ // Undo pool reservation, since everything is apparently within bounds.
+ for (String binName : binNames)
+ {
+ ConnectionBin bin = connectionBins.get(binName);
+ if (bin != null)
+ bin.undoPooledConnectionDecision(poolCount);
+ }
+
+ return false;
+ }
+
+ }
+
public void noteConnectionReturnedToPool(String[] binNames, AtomicInteger
poolCount)
{
synchronized (connectionBins)
@@ -851,8 +903,7 @@ public class Throttler
@Override
public boolean checkDestroyPooledConnection()
{
- // MHL
- return false;
+ return parent.checkDestroyPooledConnection(binNames, poolCount);
}
/** Connection expiration is tricky, because even though a connection may
be identified as