You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2013/12/14 15:43:09 UTC
svn commit: r1550935 - in
/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core:
interfaces/IConnectionThrottler.java throttler/Throttler.java
Author: kwright
Date: Sat Dec 14 14:43:09 2013
New Revision: 1550935
URL: http://svn.apache.org/r1550935
Log:
Structure is now all in place
Modified:
manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IConnectionThrottler.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/interfaces/IConnectionThrottler.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IConnectionThrottler.java?rev=1550935&r1=1550934&r2=1550935&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IConnectionThrottler.java (original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IConnectionThrottler.java Sat Dec 14 14:43:09 2013
@@ -41,7 +41,7 @@ public interface IConnectionThrottler
* characteristics should be released.
* NOTE WELL: This method cannot judge which is the best connection to be released to meet
* quotas. The caller needs to do that based on the highest number of bins matched.
- *@return the number of bins that are over quota, or zero if none of them are.
+ *@return the number of bins that are over quota, or zero if none of them are. Returns Integer.MAX_VALUE if shutting down.
*/
public int overConnectionQuotaCount();
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=1550935&r1=1550934&r2=1550935&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 Sat Dec 14 14:43:09 2013
@@ -127,8 +127,14 @@ public class Throttler
*/
public IConnectionThrottler obtainConnectionThrottler(String throttleGroupType, String throttleGroup, String[] binNames)
{
- // MHL
- return null;
+ // No waiting, so lock the entire tree.
+ synchronized (throttleGroupsHash)
+ {
+ ThrottlingGroups tg = throttleGroupsHash.get(throttleGroupType);
+ if (tg != null)
+ return tg.obtainConnectionThrottler(throttleGroup, binNames);
+ return null;
+ }
}
/** Poll periodically.
@@ -204,8 +210,6 @@ public class Throttler
this.throttlingGroupTypeName = throttlingGroupTypeName;
}
- // MHL
-
/** Update throttle specification */
public void createOrUpdateThrottleGroup(IThreadContext threadContext, String throttleGroup, IThrottleSpec throttleSpec)
throws ManifoldCFException
@@ -225,23 +229,20 @@ public class Throttler
}
}
- /** Obtain connection permission.
- *@return null if the hierarchy has changed!
+ /** Obtain connection throttler.
+ *@return the throttler, or null of the hierarchy has changed.
*/
- public IFetchThrottler obtainConnectionPermission(String throttleGroup, String[] binNames)
- throws InterruptedException
+ public IConnectionThrottler obtainConnectionThrottler(String throttleGroup, String[] binNames)
{
- // Can't lock the hierarchy here.
- ThrottlingGroup g;
synchronized (groups)
{
- g = groups.get(throttleGroup);
+ ThrottlingGroup g = groups.get(throttleGroup);
+ if (g == null)
+ return null;
+ return g.obtainConnectionThrottler(binNames);
}
- if (g == null)
- return null;
- return g.obtainConnectionPermission(binNames);
}
-
+
/** Remove specified throttle group */
public void removeThrottleGroup(IThreadContext threadContext, String throttleGroup)
throws ManifoldCFException
@@ -355,7 +356,13 @@ public class Throttler
this.throttleSpec = throttleSpec;
}
- // Connection acquisition methods
+ /** Obtain a connection throttler */
+ public IConnectionThrottler obtainConnectionThrottler(String[] binNames)
+ {
+ return new ConnectionThrottler(this, binNames);
+ }
+
+ // IConnectionThrottler support methods
/** Obtain connection permission.
*@return null if we are marked as 'not alive'.
@@ -372,6 +379,21 @@ public class Throttler
return new FetchThrottler(this, binNames);
}
+ /** Count the number of bins that are over quota.
+ *@return Integer.MAX_VALUE if shutting down.
+ */
+ public int overConnectionQuotaCount(String[] binNames)
+ {
+ // MHL
+ return Integer.MAX_VALUE;
+ }
+
+ /** Release connection */
+ public void releaseConnectionPermission(String[] binNames)
+ {
+ // MHL
+ }
+
// IFetchThrottler support methods
/** Get permission to fetch a document. This grants permission to start
@@ -484,6 +506,57 @@ public class Throttler
}
}
+ /** Connection throttler implementation class.
+ * This basically stores some parameters and links back to ThrottlingGroup.
+ */
+ protected static class ConnectionThrottler implements IConnectionThrottler
+ {
+ protected final ThrottlingGroup parent;
+ protected final String[] binNames;
+
+ public ConnectionThrottler(ThrottlingGroup parent, String[] binNames)
+ {
+ this.parent = parent;
+ this.binNames = binNames;
+ }
+
+ /** Get permission to use a connection, which is described by the passed array of bin names.
+ * This method may block until a connection slot is available.
+ * The connection can be used multiple times until the releaseConnectionPermission() method is called.
+ * This persistence feature is meant to allow connections to be pooled locally by the caller.
+ *@return the fetch throttler to use when performing fetches from the corresponding connection, or null if the system is being shut down.
+ */
+ @Override
+ public IFetchThrottler obtainConnectionPermission()
+ throws InterruptedException
+ {
+ return parent.obtainConnectionPermission(binNames);
+ }
+
+ /** Determine whether to release a pooled connection. This method returns the number of bins
+ * where the outstanding connection exceeds current quotas, indicating whether at least one with the specified
+ * characteristics should be released.
+ * NOTE WELL: This method cannot judge which is the best connection to be released to meet
+ * quotas. The caller needs to do that based on the highest number of bins matched.
+ *@return the number of bins that are over quota, or zero if none of them are.
+ */
+ @Override
+ public int overConnectionQuotaCount()
+ {
+ return parent.overConnectionQuotaCount(binNames);
+ }
+
+ /** Release permission to use one connection. This presumes that obtainConnectionPermission()
+ * was called earlier by someone and was successful.
+ */
+ @Override
+ public void releaseConnectionPermission()
+ {
+ parent.releaseConnectionPermission(binNames);
+ }
+
+ }
+
/** Fetch throttler implementation class.
* This basically stores some parameters and links back to ThrottlingGroup.
*/