Class Throttler.ThrottlingGroup

  • Enclosing class:
    Throttler

    protected class Throttler.ThrottlingGroup
    extends java.lang.Object
    This class represents a throttling group, of a specific throttling group type. It basically describes an entire self-consistent throttling environment.
    • Field Detail

      • throttlingGroupName

        protected final java.lang.String throttlingGroupName
        The throttling group name
      • throttleSpec

        protected IThrottleSpec throttleSpec
        The current throttle spec
      • connectionBins

        protected final java.util.Map<java.lang.String,​ConnectionBin> connectionBins
        The connection bins
      • fetchBins

        protected final java.util.Map<java.lang.String,​FetchBin> fetchBins
        The fetch bins
      • throttleBins

        protected final java.util.Map<java.lang.String,​ThrottleBin> throttleBins
        The throttle bins
    • Method Detail

      • obtainConnectionThrottler

        public IConnectionThrottler obtainConnectionThrottler​(IThreadContext threadContext,
                                                              java.lang.String[] binNames)
                                                       throws ManifoldCFException
        Create a bunch of bins, corresponding to the bin names specified. Note that this also registers them as services etc.
        Parameters:
        binNames - describes the set of bins to create.
        Throws:
        ManifoldCFException
      • updateThrottleSpecification

        public void updateThrottleSpecification​(IThrottleSpec throttleSpec)
                                         throws ManifoldCFException
        Update the throttle spec.
        Parameters:
        throttleSpec - is the new throttle spec for this throttle group.
        Throws:
        ManifoldCFException
      • waitConnectionAvailable

        public int waitConnectionAvailable​(java.lang.String[] binNames,
                                           java.util.concurrent.atomic.AtomicInteger[] poolCounts,
                                           IBreakCheck breakCheck)
                                    throws java.lang.InterruptedException,
                                           BreakException
        Wait for a connection to become available.
        Parameters:
        poolCounts - is a description of how many connections are available in the current pool, across all bins.
        Returns:
        the IConnectionThrottler codes for results.
        Throws:
        java.lang.InterruptedException
        BreakException
      • getNewConnectionFetchThrottler

        public IFetchThrottler getNewConnectionFetchThrottler​(java.lang.String[] binNames)
      • noteReturnedConnection

        public boolean noteReturnedConnection​(java.lang.String[] binNames)
      • checkDestroyPooledConnection

        public boolean checkDestroyPooledConnection​(java.lang.String[] binNames,
                                                    java.util.concurrent.atomic.AtomicInteger[] poolCounts)
      • checkExpireConnection

        public boolean checkExpireConnection​(java.lang.String[] binNames,
                                             java.util.concurrent.atomic.AtomicInteger[] poolCounts)
        Connection expiration is tricky, because even though a connection may be identified as being expired, at the very same moment it could be handed out in another thread. So there is a natural race condition present. The way the connection throttler deals with that is to allow the caller to reserve a connection for expiration. This must be called BEFORE the actual identified connection is removed from the connection pool. If the value returned by this method is "true", then a connection MUST be removed from the pool and destroyed, whether or not the identified connection is actually still available for destruction or not.
        Returns:
        true if a connection from the pool can be expired. If true is returned, noteConnectionDestruction() MUST be called once the connection has actually been destroyed.
      • noteConnectionReturnedToPool

        public void noteConnectionReturnedToPool​(java.lang.String[] binNames,
                                                 java.util.concurrent.atomic.AtomicInteger[] poolCounts)
      • noteConnectionDestroyed

        public void noteConnectionDestroyed​(java.lang.String[] binNames)
      • obtainFetchDocumentPermission

        public boolean obtainFetchDocumentPermission​(java.lang.String[] binNames,
                                                     IBreakCheck breakCheck)
                                              throws java.lang.InterruptedException,
                                                     BreakException
        Get permission to fetch a document. This grants permission to start fetching a single document, within the connection that has already been granted permission that created this object.
        Parameters:
        binNames - are the names of the bins.
        Returns:
        false if being shut down
        Throws:
        java.lang.InterruptedException
        BreakException
      • createFetchStream

        public IStreamThrottler createFetchStream​(java.lang.String[] binNames)
      • obtainReadPermission

        public boolean obtainReadPermission​(java.lang.String[] binNames,
                                            int byteCount,
                                            IBreakCheck breakCheck)
                                     throws java.lang.InterruptedException,
                                            BreakException
        Obtain permission to read a block of bytes. This method may wait until it is OK to proceed. The throttle group, bin names, etc are already known to this specific interface object, so it is unnecessary to include them here.
        Parameters:
        byteCount - is the number of bytes to get permissions to read.
        Returns:
        true if the wait took place as planned, or false if the system is being shut down.
        Throws:
        java.lang.InterruptedException
        BreakException
      • releaseReadPermission

        public void releaseReadPermission​(java.lang.String[] binNames,
                                          int origByteCount,
                                          int actualByteCount)
        Note the completion of the read of a block of bytes. Call this after obtainReadPermission() was successfully called, and bytes were successfully read.
        Parameters:
        origByteCount - is the originally requested number of bytes to get permissions to read.
        actualByteCount - is the number of bytes actually read.
      • closeStream

        public void closeStream​(java.lang.String[] binNames)
        Note the stream being closed.