|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hbase.util.SizeBasedThrottler
public class SizeBasedThrottler
Utility class that can be used to implement queues with limited capacity (in terms of memory). It maintains internal counter and provides two operations: increase and decrease. Increase blocks until internal counter is lower than given threshold and then increases internal counter. Decrease decreases internal counter and wakes up waiting threads if counter is lower than threshold. This implementation allows you to set the value of internal counter to be greater than threshold. It happens when internal counter is lower than threshold and increase method is called with parameter 'delta' big enough so that sum of delta and internal counter is greater than threshold. This is not a bug, this is a feature. It solves some problems: - thread calling increase with big parameter will not be starved by other threads calling increase with small arguments. - thread calling increase with argument greater than threshold won't deadlock. This is useful when throttling queues - you can submit object that is bigger than limit. This implementation introduces small costs in terms of synchronization (no synchronization in most cases at all), but is vulnerable to races. For details see documentation of increase method.
Constructor Summary | |
---|---|
SizeBasedThrottler(long threshold)
Creates SizeBoundary with provided threshold |
Method Summary | |
---|---|
long |
decrease(long delta)
Decreases value of internal counter. |
long |
getCurrentValue()
|
long |
getThreshold()
|
long |
increase(long delta)
Blocks until internal counter is lower than threshold and then increases value of internal counter. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SizeBasedThrottler(long threshold)
threshold
- threshold used by instanceMethod Detail |
---|
public long increase(long delta) throws InterruptedException
delta
- increase internal counter by this value
InterruptedException
- when interrupted during waitingpublic long decrease(long delta)
delta
- decrease internal counter by this value
public long getCurrentValue()
public long getThreshold()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |