Class Throttler
- java.lang.Object
-
- org.apache.manifoldcf.connectorcommon.throttler.Throttler
-
public class Throttler extends java.lang.Object
A Throttler object creates a virtual pool of connections to resources whose access needs to be throttled in number, rate of use, and byte rate. This code is modeled on the code for distributed connection pools, and is intended to work in a similar manner. Basically, a periodic assessment is done about what the local throttling parameters should be (on a per-pool basis), and the local throttling activities then adjust what they are doing based on the new parameters. A service model is used to keep track of which pools have what clients working with them. This implementation has the advantage that: (1) Only local throttling ever takes place on a method-by-method basis, which makes it possible to use throttling even in streams and background threads; (2) Throttling resources are apportioned fairly, on average, between all the various cluster members, so it is unlikely that any persistent starvation conditions can arise.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
Throttler.ConnectionThrottler
Connection throttler implementation class.protected static class
Throttler.FetchThrottler
Fetch throttler implementation class.protected static class
Throttler.StreamThrottler
Stream throttler implementation class.protected class
Throttler.ThrottlingGroup
This class represents a throttling group, of a specific throttling group type.protected class
Throttler.ThrottlingGroups
This class represents a throttling group pool
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
_rcsid
protected java.util.Map<java.lang.String,Throttler.ThrottlingGroups>
throttleGroupsHash
Throttle group hash table.
-
Constructor Summary
Constructors Constructor Description Throttler()
Create a throttler instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static java.lang.String
buildThrottlingGroupName(java.lang.String throttlingGroupType, java.lang.String throttlingGroupName)
void
createOrUpdateThrottleGroup(IThreadContext threadContext, java.lang.String throttleGroupType, java.lang.String throttleGroup, IThrottleSpec throttleSpec)
Set or update throttle specification for a throttle group.void
destroy(IThreadContext threadContext)
Shut down all throttlers and deregister them.void
freeUnusedResources(IThreadContext threadContext)
Free unused resources.java.util.Set<java.lang.String>
getThrottleGroups(IThreadContext threadContext, java.lang.String throttleGroupType)
Get all existing throttle groups for a throttle group type.IConnectionThrottler
obtainConnectionThrottler(IThreadContext threadContext, java.lang.String throttleGroupType, java.lang.String throttleGroup, java.lang.String[] binNames)
Construct connection throttler for connections with specific bin names.void
poll(IThreadContext threadContext)
Poll ALL bins periodically.void
poll(IThreadContext threadContext, java.lang.String throttleGroupType)
Poll periodically.void
removeThrottleGroup(IThreadContext threadContext, java.lang.String throttleGroupType, java.lang.String throttleGroup)
Remove a throttle group.
-
-
-
Field Detail
-
_rcsid
public static final java.lang.String _rcsid
- See Also:
- Constant Field Values
-
throttleGroupsHash
protected final java.util.Map<java.lang.String,Throttler.ThrottlingGroups> throttleGroupsHash
Throttle group hash table. Keyed by throttle group type, value is throttling groups
-
-
Method Detail
-
getThrottleGroups
public java.util.Set<java.lang.String> getThrottleGroups(IThreadContext threadContext, java.lang.String throttleGroupType) throws ManifoldCFException
Get all existing throttle groups for a throttle group type. The throttle group type typically describes a connector class, while the throttle group represents a namespace of bin names specific to that connector class.- Parameters:
throttleGroupType
- is the throttle group type.- Returns:
- the set of throttle groups for that group type.
- Throws:
ManifoldCFException
-
removeThrottleGroup
public void removeThrottleGroup(IThreadContext threadContext, java.lang.String throttleGroupType, java.lang.String throttleGroup) throws ManifoldCFException
Remove a throttle group.- Parameters:
throttleGroupType
- is the throttle group type.throttleGroup
- is the throttle group.- Throws:
ManifoldCFException
-
createOrUpdateThrottleGroup
public void createOrUpdateThrottleGroup(IThreadContext threadContext, java.lang.String throttleGroupType, java.lang.String throttleGroup, IThrottleSpec throttleSpec) throws ManifoldCFException
Set or update throttle specification for a throttle group. This creates the throttle group if it does not yet exist.- Parameters:
throttleGroupType
- is the throttle group type.throttleGroup
- is the throttle group.throttleSpec
- is the desired throttle specification object.- Throws:
ManifoldCFException
-
obtainConnectionThrottler
public IConnectionThrottler obtainConnectionThrottler(IThreadContext threadContext, java.lang.String throttleGroupType, java.lang.String throttleGroup, java.lang.String[] binNames) throws ManifoldCFException
Construct connection throttler for connections with specific bin names. This object is meant to be embedded with a connection pool of similar objects, and used to gate the creation of new connections in that pool.- Parameters:
throttleGroupType
- is the throttle group type.throttleGroup
- is the throttle group.binNames
- are the connection type bin names.- Returns:
- the connection throttling object, or null if the pool is being shut down.
- Throws:
ManifoldCFException
-
poll
public void poll(IThreadContext threadContext, java.lang.String throttleGroupType) throws ManifoldCFException
Poll periodically.- Throws:
ManifoldCFException
-
poll
public void poll(IThreadContext threadContext) throws ManifoldCFException
Poll ALL bins periodically.- Throws:
ManifoldCFException
-
freeUnusedResources
public void freeUnusedResources(IThreadContext threadContext) throws ManifoldCFException
Free unused resources.- Throws:
ManifoldCFException
-
destroy
public void destroy(IThreadContext threadContext) throws ManifoldCFException
Shut down all throttlers and deregister them.- Throws:
ManifoldCFException
-
buildThrottlingGroupName
protected static java.lang.String buildThrottlingGroupName(java.lang.String throttlingGroupType, java.lang.String throttlingGroupName)
-
-