Class 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.
    • Field Detail

      • 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
    • Constructor Detail

      • Throttler

        public Throttler()
        Create a throttler instance. Usually there will be one of these per connector type that needs throttling.
    • 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
      • buildThrottlingGroupName

        protected static java.lang.String buildThrottlingGroupName​(java.lang.String throttlingGroupType,
                                                                   java.lang.String throttlingGroupName)