public class TimeBucketCounter
extends java.lang.Object
| Constructor and Description |
|---|
TimeBucketCounter(int bucketDuration,
java.util.concurrent.ScheduledExecutorService executorService)
Creates a new TimeBucketCounter with the specified lifetime.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Sets isRunning to false to terminate the maintenance thread.
|
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.
|
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.
|
long |
getMillisUntilNextBucket()
When we want to test a full bucket duration we need to sleep until the next bucket starts.
|
int |
getNumBits() |
double |
getRatio()
Returns the ratio between the configured duration param and the actual duration which will be set to the next
power of 2.
|
int |
increment(java.lang.String identifier)
Increments the counter for the passed identifier in the current time bucket and returns the new value.
|
public TimeBucketCounter(int bucketDuration,
java.util.concurrent.ScheduledExecutorService executorService)
bucketDuration - duration in seconds, e.g. for 1 minute pass 60executorService - the executor service which will be used to run the maintenancepublic final int increment(java.lang.String identifier)
identifier - an identifier for which we want to maintain count, e.g. IP Addresspublic final int getCurrentBucketPrefix()
public int getNumBits()
public int getActualDuration()
public double getRatio()
public long getMillisUntilNextBucket()
public void destroy()
Copyright © 2000-2024 Apache Software Foundation.
Apache Tomcat, Tomcat, Apache, the Apache Tomcat logo and the Apache logo are either registered trademarks or trademarks of the Apache Software Foundation.