public class SimpleMeter extends Object implements ResourceMeter, ResourceRequest
Modifier | Constructor and Description |
---|---|
protected |
SimpleMeter(ResourceType type,
ResourceRequest parent)
Constructor for subclasses.
|
Modifier and Type | Method and 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 null
public static SimpleMeter create(ResourceType type)
type
- the ResourceTypepublic static SimpleMeter create(ResourceType type, ResourceRequest parent)
type
- the ResourceTypeparent
- the parent ResourceMeter; may be null
public final long getValue()
ResourceMeter
getValue
in interface ResourceMeter
public final long getAllocated()
ResourceMeter
getAllocated
in interface ResourceMeter
public final ResourceType getType()
ResourceMeter
ResourceType
.getType
in interface ResourceMeter
public final ResourceRequest getParent()
public final long request(long amount, ResourceId id)
request
in interface ResourceRequest
amount
- the amount to allocate; if zero nothing is doneid
- the ResourceId for the resource instance; may be null
protected 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 null
amount
ResourceRequestDeniedException
- if the amount cannot be satisfiedpublic String toString()
public final int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public final boolean equals(Object obj)
equals
in class Object
obj
- the reference object with which to comparetrue
if this object is the same as the obj argument;
false
otherwiseObject.hashCode()
,
HashMap
Copyright © 2014, 2015, Oracle and/or its affiliates. All rights reserved.