-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface ResourceApprover
A ResourceApprover is a callback to approve resource requests. TheResourceMeter
is the source of the allocation or release. To limit the rate of consumption, the approver may delay returning but should not do so excessively. Neither locking nor synchronization is used during the call torequest
so the value of the meter may change asynchronously due to requests from other threads.- Since:
- 8u40
- See Also:
NotifyingMeter
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description long
request(ResourceMeter meter, long previous, long amount, ResourceId id)
Requests approval to allocate or release a resource from a ResourceMeter.
-
-
-
Method Detail
-
request
long request(ResourceMeter meter, long previous, long amount, ResourceId id)
Requests approval to allocate or release a resource from a ResourceMeter. For allocation, an amount greater than zero, the amount is applied to the meter before the request so it is immediately visible. For releasing a resource, an amount less than zero, the amount is applied after the request to avoid premature release of the resource.If the
ResourceApprover
wishes to deny the request it should throw aResourceRequestDeniedException
.- Parameters:
meter
- the ResourceMeterprevious
- the value of the meter before the requestamount
- the amount of resource being requested (positive) or released (negative)id
- the ResourceId making the request; may be null- Returns:
- the amount consumed (positive) or released (negative) or zero if the request is denied
- Throws:
ResourceRequestDeniedException
- is thrown to indicate the request must be denied.
-
-