- java.lang.Object
-
- jdk.management.resource.SimpleMeter
-
- jdk.management.resource.NotifyingMeter
-
- jdk.management.resource.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 Summary
Constructors Modifier Constructor Description protectedBoundedMeter(ResourceType type, long bound, ResourceRequest parent, ResourceApprover approver)Constructor of a BoundedMeter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BoundedMetercreate(ResourceType type, long bound)Returns a new BoundedMeter with the type and upper bound.static BoundedMetercreate(ResourceType type, long bound, ResourceApprover approver)Returns a new BoundedMeter with the type, upper bound, and approver.static BoundedMetercreate(ResourceType type, long bound, ResourceRequest parent)Returns a new BoundedMeter with the type, upper bound, and parent.static BoundedMetercreate(ResourceType type, long bound, ResourceRequest parent, ResourceApprover approver)Returns a new BoundedMeter with the type, upper bound, parent, and approver.longgetBound()Returns the upper bound for the meter.longsetBound(long bound)Sets the bound.StringtoString()Returns a string representation of the meter.protected longvalidate(long previous, long amount, ResourceId id)Returns the amount validated by the approver.-
Methods inherited from class jdk.management.resource.NotifyingMeter
create, create, getApprover, getGranularity, setGranularity
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jdk.management.resource.ResourceMeter
getAllocated, getType, getValue
-
Methods inherited from interface jdk.management.resource.ResourceRequest
request
-
Methods inherited from class jdk.management.resource.SimpleMeter
create, create, equals, getAllocated, getParent, getType, getValue, hashCode, request
-
-
-
-
Constructor Detail
-
BoundedMeter
protected BoundedMeter(ResourceType type, long bound, ResourceRequest parent, ResourceApprover approver)
Constructor of a BoundedMeter.- Parameters:
type- the ResourceType of the meterbound- the initial upper boundparent- a ResourceRequest to request from; may benullapprover- the ResourceApprover to be notified; may benull
-
-
Method Detail
-
create
public static BoundedMeter create(ResourceType type, long bound)
Returns a new BoundedMeter with the type and upper bound.- Parameters:
type- the ResourceTypebound- 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 ResourceTypebound- the upper bound; must be zero or greaterparent- a ResourceRequest to request from; may benull- 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 ResourceTypebound- the upper bound; must be zero or greaterparent- a ResourceRequest to request from; may benullapprover- the ResourceApprover to be notified; may benull- 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 ResourceTypebound- the upper bound; must be zero or greaterapprover- the ResourceApprover to be notified; may benull- 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:NotifyingMeterReturns the amount validated by the approver. TheResourceApprover.requestmust return only the amount requested, zero, or throw aResourceRequestDeniedException. If the amount returned is any other value, it is ignored and the requested amount is returned.- Overrides:
validatein classNotifyingMeter- Parameters:
previous- the previous meter valueamount- the amount to validate; if zero nothing is doneid- the ResourceId for the resource instance; may benull- 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:SimpleMeterReturns a string representation of the meter.- Overrides:
toStringin classSimpleMeter- Returns:
- a string representation of the meter
-
-