public class SimpleMeter extends Object implements ResourceMeter, ResourceRequest
| Modifier | Constructor | Description |
|---|---|---|
protected |
SimpleMeter(ResourceType type,
ResourceRequest parent) |
Constructor for subclasses.
|
| Modifier and Type | Method | Description |
|---|---|---|
static SimpleMeter |
create(ResourceType type) |
Returns a new SimpleMeter with the ResourceType.
|
static SimpleMeter |
create(ResourceType type,
ResourceRequest parent) |
Returns a new SimpleMeter with the ResourceType and allocating from a parent.
|
boolean |
equals(Object obj) |
Indicates whether some other object is the same object as this one.
|
long |
getAllocated() |
Returns the cumulative total of allocations from the ResourceMeter.
|
ResourceRequest |
getParent() |
Returns the parent ResourceRequest.
|
ResourceType |
getType() |
Returns the
ResourceType. |
long |
getValue() |
Returns the current net value of the ResourceMeter.
|
int |
hashCode() |
Returns the hashcode from for this object.
|
long |
request(long amount,
ResourceId id) |
Returns the validated and allocated amount and adjusts the meter.
|
String |
toString() |
Returns a string representation of the meter.
|
protected long |
validate(long previous,
long amount,
ResourceId id) |
Validate the amount returning the validated amount.
|
protected SimpleMeter(ResourceType type, ResourceRequest parent)
type - the ResourceType for the meterparent - a ResourceRequest used as the parent to allocate from; may be nullpublic static SimpleMeter create(ResourceType type)
type - the ResourceTypepublic static SimpleMeter create(ResourceType type, ResourceRequest parent)
type - the ResourceTypeparent - the parent ResourceMeter; may be nullpublic final long getValue()
ResourceMetergetValue in interface ResourceMeterpublic final long getAllocated()
ResourceMetergetAllocated in interface ResourceMeterpublic final ResourceType getType()
ResourceMeterResourceType.getType in interface ResourceMeterpublic final ResourceRequest getParent()
public final long request(long amount,
ResourceId id)
request in interface ResourceRequestamount - the amount to allocate; if zero nothing is doneid - the ResourceId for the resource instance; may be nullprotected long validate(long previous,
long amount,
ResourceId id)
throws ResourceRequestDeniedException
For allocation, positive amounts, the amount is applied to the meter before validation so it is immediately visible. For releasing a resource, negative amounts, the amount is applied after validation to avoid premature release of the resource. If the amount returned is different than requested the meter will be corrected with the difference.
previous - the meter value before the current requestamount - an amount, positive to allocate, negative to releaseid - the ResourceId for the resource instance; may be nullamountResourceRequestDeniedException - if the amount cannot be satisfiedpublic String toString()
public final int hashCode()
hashCode in class ObjectObject.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)public final boolean equals(Object obj)
equals in class Objectobj - the reference object with which to comparetrue if this object is the same as the obj argument;
false otherwiseObject.hashCode(),
HashMap
Copyright © 2014, 2025, Oracle and/or its affiliates. All rights reserved.