Package ratpack.exec

Interface Throttle


  • public interface Throttle
    Limits the concurrency of operations, typically access to an external resource.

    A given throttle limits the amount of concurrently executing promise, effectively limiting concurrency.

    The queueing employed by the throttle is generally fair (i.e. oldest promises execute first), but this is not completely guaranteed.

    See Also:
    Promise.throttled(Throttle)
    • Method Detail

      • ofSize

        static Throttle ofSize​(int size)
        Create a new throttle of the given size.
        Parameters:
        size - the desired size
        Returns:
        a new throttle of the given size
      • unlimited

        static Throttle unlimited()
        Create a new throttle that does not limit concurrency.
        Returns:
        an unlimited throttle
      • throttle

        <T> Promise<T> throttle​(Promise<T> promise)
        Throttles the given promise.
        Type Parameters:
        T - the type of promised value
        Parameters:
        promise - the promise to throttle
        Returns:
        the throttled promise
      • getSize

        int getSize()
        The size of this throttle.

        The throttle guarantees that no more than this number of promises that were throttled via throttle(Promise) will execute at the same time.

        Returns < 1 if the throttle is unlimited.

        Returns:
        the throttle size
      • getActive

        int getActive()
        How many throttled promises are currently executing.
        Returns:
        how many throttled promises are currently executing
      • getWaiting

        int getWaiting()
        The number of throttled promises that are waiting to execute (that is, the queue size).
        Returns:
        the number of promises waiting to execute