- java.lang.Object
-
- jdk.management.resource.SimpleMeter
-
- jdk.management.resource.NotifyingMeter
-
- All Implemented Interfaces:
ResourceMeter
,ResourceRequest
- Direct Known Subclasses:
BoundedMeter
,ThrottledMeter
public class NotifyingMeter extends SimpleMeter
A NotifyingMeter provides an approver callback for changes and allocates from an optional parent. The granularity applies only to the approval callback, the amount requested or freed is the same as the amount requested. The granularity may be set at any time. Approval callbacks occur upon crossing the granularity threshold for either allocations or releases. The callback can return the amount requested or zero to indicate the request is denied. Most applications are not resilient to changes to the size of I/O operations or availability of resources.- Since:
- 8u40
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
NotifyingMeter(ResourceType type, ResourceRequest parent, ResourceApprover approver)
Constructor for subclasses.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static NotifyingMeter
create(ResourceType type, ResourceApprover approver)
Returns a new NotifyingMeter with the type and approver.static NotifyingMeter
create(ResourceType type, ResourceRequest parent, ResourceApprover approver)
Returns a new NotifyingMeter with the type, approver and parent approver.ResourceApprover
getApprover()
Return the ResourceApprover.long
getGranularity()
Returns the granularity.long
setGranularity(long granularity)
Sets the granularity.protected long
validate(long previous, long amount, ResourceId id)
Returns the amount validated by the approver.
-
-
-
Constructor Detail
-
NotifyingMeter
protected NotifyingMeter(ResourceType type, ResourceRequest parent, ResourceApprover approver)
Constructor for subclasses. The granularity is initialized to 1.- Parameters:
type
- the ResourceTypeparent
- a ResourceRequest to request from; may benull
approver
- the ResourceApprover to be notified; may benull
-
-
Method Detail
-
create
public static NotifyingMeter create(ResourceType type, ResourceApprover approver)
Returns a new NotifyingMeter with the type and approver. The granularity is initialized to 1.- Parameters:
type
- the ResourceTypeapprover
- the ResourceApprover to be notified; may benull
- Returns:
- a new NotifyingMeter with the type and notify
-
create
public static NotifyingMeter create(ResourceType type, ResourceRequest parent, ResourceApprover approver)
Returns a new NotifyingMeter with the type, approver and parent approver. The granularity is initialized to 1.- Parameters:
type
- the ResourceTypeapprover
- the ResourceApprover to notify; may benull
parent
- a ResourceRequest to request from; may benull
- Returns:
- a new NotifyingMeter with the type, notify, and parent approver
-
validate
protected long validate(long previous, long amount, ResourceId id)
Returns the amount validated by the approver. TheResourceApprover.request
must 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:
validate
in classSimpleMeter
- 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
-
getGranularity
public final long getGranularity()
Returns the granularity.- Returns:
- the granularity
-
setGranularity
public final long setGranularity(long granularity)
Sets the granularity.- Parameters:
granularity
- Sets the granularity; the granularity must be greater than zero- Returns:
- the previous granularity value
- Throws:
IllegalArgumentException
- if the granularity is less than or equal to zero
-
getApprover
public final ResourceApprover getApprover()
Return the ResourceApprover.- Returns:
- the approver
-
-