| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private final ScheduledExecutorService | |
| private static final Log | |
| private ScheduledFuture | maintenanceFuture
The future allowing control of the background processor. |
| private final ConcurrentHashMap | map
Map to hold the buckets |
| private ScheduledFuture | |
| private final int | numBits
Milliseconds bucket size as a Power of 2 for bit shift math, e.g. 16 for 65_536ms which is about 1:05 minute |
| private final double | ratio
Ratio of actual duration to config duration |
| private final long | |
| private static final StringManager |
| Access | Constructor and Description |
|---|---|
| public | TimeBucketCounter(int
duration in seconds, e.g. for 1 minute pass 60 bucketDuration, ScheduledExecutorService the executor service which will be used to run the maintenance executorService)Creates a new TimeBucketCounter with the specified lifetime. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public int | Returns: the actual bucket duration in millisecondsThe actual duration may differ from the configured duration because it is set to the next power of 2 value in order to perform very fast bit shift arithmetic. |
| public final int | Returns: The current bucket prefix.Calculates the current time bucket prefix by shifting bits for fast division, e.g. shift 16 bits is the same as dividing by 65,536 which is about 1:05m. |
| public long | Returns: the number of milliseconds until the next bucketWhen we want to test a full bucket duration we need to sleep until the next bucket starts. |
| public int | |
| public double | Returns: the ratio, e.g. 1.092 if the actual duration is 65_536 for the configured duration of 60_000Returns the ratio between the configured duration param and the actual duration which will be set to the next power of 2. |
| public final int | |
| pack-priv static int | nextPowerOf2(int value)
Returns the next power of 2 given a value, e.g. 256 for 250, or 1024, for 1000. |
| pack-priv static double |
| executorService | back to summary |
|---|---|
| private final ScheduledExecutorService executorService | |
| log | back to summary |
|---|---|
| private static final Log log | |
| maintenanceFuture | back to summary |
|---|---|
| private ScheduledFuture<?> maintenanceFuture The future allowing control of the background processor. | |
| map | back to summary |
|---|---|
| private final ConcurrentHashMap<String, AtomicInteger> map Map to hold the buckets | |
| monitorFuture | back to summary |
|---|---|
| private ScheduledFuture<?> monitorFuture | |
| numBits | back to summary |
|---|---|
| private final int numBits Milliseconds bucket size as a Power of 2 for bit shift math, e.g. 16 for 65_536ms which is about 1:05 minute | |
| ratio | back to summary |
|---|---|
| private final double ratio Ratio of actual duration to config duration | |
| sleeptime | back to summary |
|---|---|
| private final long sleeptime | |
| sm | back to summary |
|---|---|
| private static final StringManager sm | |
| TimeBucketCounter | back to summary |
|---|---|
| public TimeBucketCounter(int bucketDuration, ScheduledExecutorService executorService) Creates a new TimeBucketCounter with the specified lifetime.
| |
| destroy | back to summary |
|---|---|
| public void destroy() Sets isRunning to false to terminate the maintenance thread. | |
| getActualDuration | back to summary |
|---|---|
| public int getActualDuration() The actual duration may differ from the configured duration because it is set to the next power of 2 value in order to perform very fast bit shift arithmetic.
| |
| getCurrentBucketPrefix | back to summary |
|---|---|
| public final int getCurrentBucketPrefix() Calculates the current time bucket prefix by shifting bits for fast division, e.g. shift 16 bits is the same as dividing by 65,536 which is about 1:05m.
| |
| getMillisUntilNextBucket | back to summary |
|---|---|
| public long getMillisUntilNextBucket() When we want to test a full bucket duration we need to sleep until the next bucket starts.
| |
| getNumBits | back to summary |
|---|---|
| public int getNumBits() | |
| getRatio | back to summary |
|---|---|
| public double getRatio() Returns the ratio between the configured duration param and the actual duration which will be set to the next power of 2. We then multiply the configured requests param by the same ratio in order to compensate for the added time, if any.
| |
| increment | back to summary |
|---|---|
| public final int increment(String identifier) Increments the counter for the passed identifier in the current time bucket and returns the new value.
| |
| nextPowerOf2 | back to summary |
|---|---|
| pack-priv static int nextPowerOf2(int value) Returns the next power of 2 given a value, e.g. 256 for 250, or 1024, for 1000. | |
| ratioToPowerOf2 | back to summary |
|---|---|
| pack-priv static double ratioToPowerOf2(int value) Returns the ratio to the next power of 2 so that we can adjust the value. | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| Maintenance | back to summary |
|---|---|
| private Maintenance() | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| MaintenanceMonitor | back to summary |
|---|---|
| private MaintenanceMonitor() | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |