public class ThrottledMeter extends NotifyingMeter
Modifier and Type | Method and Description |
---|---|
static ThrottledMeter |
create(ResourceType type,
long ratePerSec,
ResourceApprover approver)
Create a new meter with a throttle rate and approver.
|
static ThrottledMeter |
create(ResourceType type,
long ratePerSec,
ResourceRequest parent,
ResourceApprover approver)
Create a new meter with a throttle rate, parent and approver.
|
static ThrottledMeter |
create(ResourceType type,
ResourceRequest parent,
ResourceApprover approver)
Create a new meter with unlimited rate, parent and approver.
|
long |
getCurrentRate()
Returns an estimate of the current rate in amount per second.
|
long |
getRatePerSec()
Returns the current throttle rate per second.
|
long |
setRatePerSec(long ratePerSec)
Sets the throttle rate per second.
|
String |
toString()
Returns a string representation of the meter.
|
long |
validate(long previous,
long amount,
ResourceId id)
Validates the amount.
|
create, getApprover, getGranularity, setGranularity
create, create, equals, getAllocated, getParent, getType, getValue, hashCode, request
public static ThrottledMeter create(ResourceType type, long ratePerSec, ResourceApprover approver)
type
- the ResourceTyperatePerSec
- the rate allowed for Throttling; bytes-per sec; must be greater than zeroapprover
- the ResourceApprover to be notified; may be null
IllegalArgumentException
- if ratePerSec is less than or equal to zeropublic static ThrottledMeter create(ResourceType type, ResourceRequest parent, ResourceApprover approver)
type
- the ResourceTypeparent
- a ResourceRequest to request from; may be null
approver
- the ResourceApprover to be notified; may be null
IllegalArgumentException
- if ratePerSec is less than or equal to zeropublic static ThrottledMeter create(ResourceType type, long ratePerSec, ResourceRequest parent, ResourceApprover approver)
type
- the ResourceTyperatePerSec
- the rate allowed for throttling; bytes-per sec; must be greater than zeroparent
- a ResourceRequest to request from; may be null
approver
- the ResourceApprover to be notified; may be null
IllegalArgumentException
- if ratePerSec is less than or equal to zeropublic long validate(long previous, long amount, ResourceId id)
allowance
is maintained of the amount than can be immediately
fulfilled to satisfy a request. The allowance maximum is two seconds
worth at the current rate-per-second. Requests reduce the allowance
by the amount of the request. If the allowance is initially positive,
the request is fulfilled immediately.
If the allowance is negative, the allowance is topped up based
on the elapsed time, waiting until it is positive again.
If multiple threads are contending for the allowance, normal
thread scheduling and synchronization primitives influence the order.
If an InterruptedException is caught, zero is returned, failing the validation.
The throttling of resource use is decoupled from the underlying resource implementation and only delays the start of resource consumption not the rate of consumption.
validate
in class NotifyingMeter
amount
- the amount requestedid
- the ResourceId for the resource instance; may be null
previous
- the previous meter valuepublic final long getCurrentRate()
public final long getRatePerSec()
public final long setRatePerSec(long ratePerSec)
ratePerSec
- the rate per second; must be greater than zeroIllegalArgumentException
- if ratePerSec is less than or equal to zeropublic String toString()
SimpleMeter
toString
in class SimpleMeter
Copyright © 2014, 2015, Oracle and/or its affiliates. All rights reserved.