Class BoundedMeter

  • All Implemented Interfaces:
    ResourceMeter, ResourceRequest


    public class BoundedMeter
    extends NotifyingMeter
    implements ResourceMeter, ResourceRequest
    A BoundedMeter enforces an upper bound, provides an approver callback for changes and allocates from an optional parent. Approval callbacks occur upon crossing the granularity threshold and when the bound is exceeded; the approval callback occurs before the bounds check. All requests are granted in full or not granted. Requests that are denied are not allocated from the parent.
    Since:
    8u40
    • Constructor Detail

      • BoundedMeter

        protected BoundedMeter​(ResourceType type,
                               long bound,
                               ResourceRequest parent,
                               ResourceApprover approver)
        Constructor of a BoundedMeter.
        Parameters:
        type - the ResourceType of the meter
        bound - the initial upper bound
        parent - a ResourceRequest to request from; may be null
        approver - the ResourceApprover to be notified; may be null
    • Method Detail

      • create

        public static BoundedMeter create​(ResourceType type,
                                          long bound)
        Returns a new BoundedMeter with the type and upper bound.
        Parameters:
        type - the ResourceType
        bound - the upper bound; must be zero or greater
        Returns:
        a new BoundedMeter with the type and bound
        Throws:
        IllegalArgumentException - if the bound is less than zero
      • create

        public static BoundedMeter create​(ResourceType type,
                                          long bound,
                                          ResourceRequest parent)
        Returns a new BoundedMeter with the type, upper bound, and parent.
        Parameters:
        type - the ResourceType
        bound - the upper bound; must be zero or greater
        parent - a ResourceRequest to request from; may be null
        Returns:
        a new BoundedMeter with the type, bound, and parent approver
        Throws:
        IllegalArgumentException - if the bound is less than zero
      • create

        public static BoundedMeter create​(ResourceType type,
                                          long bound,
                                          ResourceRequest parent,
                                          ResourceApprover approver)
        Returns a new BoundedMeter with the type, upper bound, parent, and approver.
        Parameters:
        type - the ResourceType
        bound - the upper bound; must be zero or greater
        parent - a ResourceRequest to request from; may be null
        approver - the ResourceApprover to be notified; may be null
        Returns:
        a new BoundedMeter with the type, bound, parent, and approver
        Throws:
        IllegalArgumentException - if the bound is less than zero
      • create

        public static BoundedMeter create​(ResourceType type,
                                          long bound,
                                          ResourceApprover approver)
        Returns a new BoundedMeter with the type, upper bound, and approver.
        Parameters:
        type - the ResourceType
        bound - the upper bound; must be zero or greater
        approver - the ResourceApprover to be notified; may be null
        Returns:
        a new BoundedMeter with the type, bound, parent, and approver
        Throws:
        IllegalArgumentException - if the bound is less than zero
      • validate

        protected long validate​(long previous,
                                long amount,
                                ResourceId id)
        Description copied from class: NotifyingMeter
        Returns the amount validated by the approver. The ResourceApprover.request must return only the amount requested, zero, or throw a ResourceRequestDeniedException. If the amount returned is any other value, it is ignored and the requested amount is returned.
        Overrides:
        validate in class NotifyingMeter
        Parameters:
        previous - the previous meter value
        amount - the amount to validate; if zero nothing is done
        id - the ResourceId for the resource instance; may be null
        Returns:
        the value validated zero, positive or negative
      • getBound

        public final long getBound​()
        Returns the upper bound for the meter.
        Returns:
        the upper bound
      • setBound

        public final long setBound​(long bound)
        Sets the bound.
        Parameters:
        bound - the bound; must be zero or greater
        Returns:
        the previous upper bound
        Throws:
        IllegalArgumentException - if the bound is less than zero
      • toString

        public String toString​()
        Description copied from class: SimpleMeter
        Returns a string representation of the meter.
        Overrides:
        toString in class SimpleMeter
        Returns:
        a string representation of the meter