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 01:31:52 UTC
svn commit: r1550860 - in
/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core:
interfaces/IConnectionThrottler.java throttler/ConnectionThrottler.java
throttler/Throttler.java
Author: kwright
Date: Sat Dec 14 00:31:52 2013
New Revision: 1550860
URL: http://svn.apache.org/r1550860
Log:
More work
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/ConnectionThrottler.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=1550860&r1=1550859&r2=1550860&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 00:31:52 2013
@@ -34,13 +34,15 @@ public interface IConnectionThrottler
*@param throttleGroupType is the throttle group type.
*@return the set of throttle groups for that group type.
*/
- public Set<String> getThrottleGroups(String throttleGroupType);
+ public Set<String> getThrottleGroups(String throttleGroupType)
+ throws ManifoldCFException;
/** Remove a throttle group.
*@param throttleGroupType is the throttle group type.
*@param throttleGroup is the throttle group.
*/
- public void removeThrottleGroup(String throttleGroupType, String throttleGroup);
+ public void removeThrottleGroup(String throttleGroupType, String throttleGroup)
+ throws ManifoldCFException;
/** Set or update throttle specification for a throttle group. This creates the
* throttle group if it does not yet exist.
@@ -48,7 +50,8 @@ public interface IConnectionThrottler
*@param throttleGroup is the throttle group.
*@param throttleSpec is the desired throttle specification object.
*/
- public void updateThrottleSpecification(String throttleGroupType, String throttleGroup, IThrottleSpec throttleSpec);
+ public void updateThrottleSpecification(String throttleGroupType, String throttleGroup, IThrottleSpec throttleSpec)
+ throws ManifoldCFException;
/** 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.
@@ -61,7 +64,7 @@ public interface IConnectionThrottler
*/
public IFetchThrottler obtainConnectionPermission(String throttleGroupType , String throttleGroup,
String[] binNames)
- throws InterruptedException;
+ throws ManifoldCFException;
/** 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
@@ -73,7 +76,8 @@ public interface IConnectionThrottler
*@param binNames is the set of bin names to throttle for, within the throttle group.
*@return the number of bins that are over quota, or zero if none of them are.
*/
- public int overConnectionQuotaCount(String throttleGroupType, String throttleGroup, String[] binNames);
+ public int overConnectionQuotaCount(String throttleGroupType, String throttleGroup, String[] binNames)
+ throws ManifoldCFException;
/** Release permission to use one connection. This presumes that obtainConnectionPermission()
* was called earlier by someone and was successful.
@@ -81,7 +85,8 @@ public interface IConnectionThrottler
*@param throttleGroup is the throttle group.
*@param binNames is the set of bin names to throttle for, within the throttle group.
*/
- public void releaseConnectionPermission(String throttleGroupType, String throttleGroup, String[] binNames);
+ public void releaseConnectionPermission(String throttleGroupType, String throttleGroup, String[] binNames)
+ throws ManifoldCFException;
/** Poll periodically, to update cluster-wide statistics and allocation.
*@param throttleGroupType is the throttle group type to update.
Modified: manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionThrottler.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionThrottler.java?rev=1550860&r1=1550859&r2=1550860&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionThrottler.java (original)
+++ manifoldcf/branches/CONNECTORS-829/framework/core/src/main/java/org/apache/manifoldcf/core/throttler/ConnectionThrottler.java Sat Dec 14 00:31:52 2013
@@ -50,9 +50,9 @@ public class ConnectionThrottler impleme
*/
@Override
public Set<String> getThrottleGroups(String throttleGroupType)
+ throws ManifoldCFException
{
- // MHL
- return null;
+ return throttler.getThrottleGroups(threadContext, throttleGroupType);
}
/** Remove a throttle group.
@@ -61,8 +61,9 @@ public class ConnectionThrottler impleme
*/
@Override
public void removeThrottleGroup(String throttleGroupType, String throttleGroup)
+ throws ManifoldCFException
{
- // MHL
+ throttler.removeThrottleGroup(threadContext, throttleGroupType, throttleGroup);
}
/** Set or update throttle specification for a throttle group. This creates the
@@ -73,8 +74,9 @@ public class ConnectionThrottler impleme
*/
@Override
public void updateThrottleSpecification(String throttleGroupType, String throttleGroup, IThrottleSpec throttleSpec)
+ throws ManifoldCFException
{
- // MHL
+ throttler.updateThrottleSpecification(threadContext, throttleGroupType, throttleGroup, throttleSpec);
}
/** Get permission to use a connection, which is described by the passed array of bin names.
@@ -89,10 +91,9 @@ public class ConnectionThrottler impleme
@Override
public IFetchThrottler obtainConnectionPermission(String throttleGroupType , String throttleGroup,
String[] binNames)
- throws InterruptedException
+ throws ManifoldCFException
{
- // MHL
- return null;
+ return throttler.obtainConnectionPermission(threadContext, throttleGroupType, throttleGroup, binNames);
}
/** Determine whether to release a pooled connection. This method returns the number of bins
@@ -107,9 +108,9 @@ public class ConnectionThrottler impleme
*/
@Override
public int overConnectionQuotaCount(String throttleGroupType, String throttleGroup, String[] binNames)
+ throws ManifoldCFException
{
- // MHL
- return 0;
+ return throttler.overConnectionQuotaCount(threadContext, throttleGroupType, throttleGroup, binNames);
}
/** Release permission to use one connection. This presumes that obtainConnectionPermission()
@@ -120,8 +121,9 @@ public class ConnectionThrottler impleme
*/
@Override
public void releaseConnectionPermission(String throttleGroupType, String throttleGroup, String[] binNames)
+ throws ManifoldCFException
{
- // MHL
+ throttler.releaseConnectionPermission(threadContext, throttleGroupType, throttleGroup, binNames);
}
/** Poll periodically, to update cluster-wide statistics and allocation.
@@ -131,7 +133,7 @@ public class ConnectionThrottler impleme
public void poll(String throttleGroupType)
throws ManifoldCFException
{
- // MHL
+ throttler.poll(threadContext, throttleGroupType);
}
/** Free unused resources.
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=1550860&r1=1550859&r2=1550860&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 00:31:52 2013
@@ -58,19 +58,32 @@ public class Throttler
*@param throttleGroupType is the throttle group type.
*@return the set of throttle groups for that group type.
*/
- public Set<String> getThrottleGroups(String throttleGroupType)
+ public Set<String> getThrottleGroups(IThreadContext threadContext, String throttleGroupType)
+ throws ManifoldCFException
{
- // MHL
- return null;
+ synchronized (throttleGroupsHash)
+ {
+ return throttleGroupsHash.keySet();
+ }
}
/** Remove a throttle group.
*@param throttleGroupType is the throttle group type.
*@param throttleGroup is the throttle group.
*/
- public void removeThrottleGroup(String throttleGroupType, String throttleGroup)
+ public void removeThrottleGroup(IThreadContext threadContext, String throttleGroupType, String throttleGroup)
+ throws ManifoldCFException
{
- // MHL
+ ThrottlingGroups tg;
+ synchronized (throttleGroupsHash)
+ {
+ tg = throttleGroupsHash.get(throttleGroupType);
+ }
+
+ if (tg != null)
+ {
+ tg.removeThrottleGroup(threadContext, throttleGroup);
+ }
}
/** Set or update throttle specification for a throttle group. This creates the
@@ -79,9 +92,21 @@ public class Throttler
*@param throttleGroup is the throttle group.
*@param throttleSpec is the desired throttle specification object.
*/
- public void updateThrottleSpecification(String throttleGroupType, String throttleGroup, IThrottleSpec throttleSpec)
+ public void updateThrottleSpecification(IThreadContext threadContext, String throttleGroupType, String throttleGroup, IThrottleSpec throttleSpec)
+ throws ManifoldCFException
{
- // MHL
+ ThrottlingGroups tg;
+ synchronized (throttleGroupsHash)
+ {
+ tg = throttleGroupsHash.get(throttleGroupType);
+ if (tg == null)
+ {
+ tg = new ThrottlingGroups(throttleGroupType);
+ throttleGroupsHash.put(throttleGroupType, tg);
+ }
+ }
+
+ tg.updateThrottleSpecification(threadContext, throttleGroup, throttleSpec);
}
/** Get permission to use a connection, which is described by the passed array of bin names.
@@ -93,9 +118,9 @@ public class Throttler
*@param binNames is the set of bin names to throttle for, within the throttle group.
*@return the fetch throttler to use when performing fetches from the corresponding connection.
*/
- public IFetchThrottler obtainConnectionPermission(String throttleGroupType , String throttleGroup,
+ public IFetchThrottler obtainConnectionPermission(IThreadContext threadContext, String throttleGroupType , String throttleGroup,
String[] binNames)
- throws InterruptedException
+ throws ManifoldCFException
{
// MHL
return null;
@@ -111,7 +136,8 @@ public class Throttler
*@param binNames is the set of bin names to throttle for, within the throttle group.
*@return the number of bins that are over quota, or zero if none of them are.
*/
- public int overConnectionQuotaCount(String throttleGroupType, String throttleGroup, String[] binNames)
+ public int overConnectionQuotaCount(IThreadContext threadContext, String throttleGroupType, String throttleGroup, String[] binNames)
+ throws ManifoldCFException
{
// MHL
return 0;
@@ -123,7 +149,8 @@ public class Throttler
*@param throttleGroup is the throttle group.
*@param binNames is the set of bin names to throttle for, within the throttle group.
*/
- public void releaseConnectionPermission(String throttleGroupType, String throttleGroup, String[] binNames)
+ public void releaseConnectionPermission(IThreadContext threadContext, String throttleGroupType, String throttleGroup, String[] binNames)
+ throws ManifoldCFException
{
// MHL
}
@@ -203,41 +230,85 @@ public class Throttler
// MHL
+ /** Update throttle specification */
+ public void updateThrottleSpecification(IThreadContext threadContext, String throttleGroup, IThrottleSpec throttleSpec)
+ throws ManifoldCFException
+ {
+ synchronized (groups)
+ {
+ ThrottlingGroup g = groups.get(throttleGroup);
+ if (g == null)
+ {
+ g = new ThrottlingGroup(threadContext, throttlingGroupTypeName, throttleGroup, throttleSpec);
+ groups.put(throttleGroup, g);
+ }
+ else
+ {
+ g.updateThrottleSpecification(throttleSpec);
+ }
+ }
+ }
+
+ /** Remove specified throttle group */
+ public synchronized void removeThrottleGroup(IThreadContext threadContext, String throttleGroup)
+ throws ManifoldCFException
+ {
+ // Must synch the whole thing, because otherwise there would be a risk of someone recreating the
+ // group right after we removed it from the map, and before we destroyed it.
+ synchronized (groups)
+ {
+ ThrottlingGroup g = groups.remove(throttleGroup);
+ if (g != null)
+ {
+ g.destroy(threadContext);
+ }
+ }
+ }
+
/** Poll this set of throttle groups */
- public synchronized void poll(IThreadContext threadContext)
+ public void poll(IThreadContext threadContext)
throws ManifoldCFException
{
- Iterator<String> iter = groups.keySet().iterator();
- while (iter.hasNext())
+ synchronized (groups)
{
- String throttleGroup = iter.next();
- ThrottlingGroup p = groups.get(throttleGroup);
- p.poll(threadContext);
+ Iterator<String> iter = groups.keySet().iterator();
+ while (iter.hasNext())
+ {
+ String throttleGroup = iter.next();
+ ThrottlingGroup p = groups.get(throttleGroup);
+ p.poll(threadContext);
+ }
}
}
/** Free unused resources */
- public synchronized void freeUnusedResources(IThreadContext threadContext)
+ public void freeUnusedResources(IThreadContext threadContext)
throws ManifoldCFException
{
- Iterator<ThrottlingGroup> iter = groups.values().iterator();
- while (iter.hasNext())
+ synchronized (groups)
{
- ThrottlingGroup g = iter.next();
- g.freeUnusedResources(threadContext);
+ Iterator<ThrottlingGroup> iter = groups.values().iterator();
+ while (iter.hasNext())
+ {
+ ThrottlingGroup g = iter.next();
+ g.freeUnusedResources(threadContext);
+ }
}
}
/** Destroy and shutdown all */
- public synchronized void destroy(IThreadContext threadContext)
+ public void destroy(IThreadContext threadContext)
throws ManifoldCFException
{
- Iterator<ThrottlingGroup> iter = groups.values().iterator();
- while (iter.hasNext())
+ synchronized (groups)
{
- ThrottlingGroup p = iter.next();
- p.destroy(threadContext);
- iter.remove();
+ Iterator<ThrottlingGroup> iter = groups.values().iterator();
+ while (iter.hasNext())
+ {
+ ThrottlingGroup p = iter.next();
+ p.destroy(threadContext);
+ iter.remove();
+ }
}
}
}
@@ -277,7 +348,7 @@ public class Throttler
/** Update the throttle spec.
*@param throttleSpec is the new throttle spec for this throttle group.
*/
- public synchronized void updateThrottleSpec(IThreadContext threadContext, IThrottleSpec throttleSpec)
+ public synchronized void updateThrottleSpecification(IThrottleSpec throttleSpec)
throws ManifoldCFException
{
this.throttleSpec = throttleSpec;