Class BatchedFixedIntervalInvocationGate
- java.lang.Object
-
- ch.qos.logback.core.util.BatchedFixedIntervalInvocationGate
-
- All Implemented Interfaces:
InvocationGate
public class BatchedFixedIntervalInvocationGate extends Object implements InvocationGate
AnInvocationGatethat allows a fixed number of successive callers to proceed, then enforces a lull of a fixedDuration.Callers on a hot path use
isTooSoon(long)to decide whether to skip a costly operation. Up to N invocations may receivefalse(proceed) in succession. After the N-th success, the gate enters a lull of increment milliseconds during which all callers receivetrue(skip). When the lull ends, another batch of N is available.This extends the idea of
FixedIntervalInvocationGate(at most one success per interval) to batches of size N. Token accounting and the lull deadline use atomics so concurrent callers share one batch.- Since:
- 1.6.3
- Author:
- Ceki Gülcü
- See Also:
InvocationGate,FixedIntervalInvocationGate
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BATCH_SIZEDefault batch size: number of successive allowed passages before a lull.static DurationDEFAULT_INCREMENTDefault lull duration after a batch is exhausted (same asFixedIntervalInvocationGate.DEFAULT_INCREMENT).-
Fields inherited from interface ch.qos.logback.core.util.InvocationGate
TIME_UNAVAILABLE
-
-
Constructor Summary
Constructors Constructor Description BatchedFixedIntervalInvocationGate()Creates a gate withDEFAULT_BATCH_SIZEandDEFAULT_INCREMENT.BatchedFixedIntervalInvocationGate(int batchSize)Creates a gate with the given batch size andDEFAULT_INCREMENT.BatchedFixedIntervalInvocationGate(int batchSize, Duration anIncrement)Creates a gate that allowsbatchSizesuccessive passages, then lulls foranIncrement.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisTooSoon(long currentTime)Returnstrueif the caller should skip further work;falseif this call is allowed to proceed.
-
-
-
Field Detail
-
DEFAULT_BATCH_SIZE
public static final int DEFAULT_BATCH_SIZE
Default batch size: number of successive allowed passages before a lull.- See Also:
- Constant Field Values
-
DEFAULT_INCREMENT
public static final Duration DEFAULT_INCREMENT
Default lull duration after a batch is exhausted (same asFixedIntervalInvocationGate.DEFAULT_INCREMENT).
-
-
Constructor Detail
-
BatchedFixedIntervalInvocationGate
public BatchedFixedIntervalInvocationGate()
Creates a gate withDEFAULT_BATCH_SIZEandDEFAULT_INCREMENT.
-
BatchedFixedIntervalInvocationGate
public BatchedFixedIntervalInvocationGate(int batchSize)
Creates a gate with the given batch size andDEFAULT_INCREMENT.- Parameters:
batchSize- number of successive allowed invocations per batch; must be at least 1
-
BatchedFixedIntervalInvocationGate
public BatchedFixedIntervalInvocationGate(int batchSize, Duration anIncrement)
Creates a gate that allowsbatchSizesuccessive passages, then lulls foranIncrement.- Parameters:
batchSize- number of successive allowed invocations per batch; must be at least 1anIncrement- lull duration after a batch is exhausted; must not benull
-
-
Method Detail
-
isTooSoon
public boolean isTooSoon(long currentTime)
Returnstrueif the caller should skip further work;falseif this call is allowed to proceed.If
currentTimeisInvocationGate.TIME_UNAVAILABLE(-1), returnsfalseso work can still run when the clock is unavailable.During a lull (
currentTimebefore the next open time), returnstrue. Otherwise tries to consume one batch token. The firstbatchSizesuccessful consumptions returnfalse. The caller that takes the last token starts a lull ofincrementand re-arms the batch for after the lull.- Specified by:
isTooSoonin interfaceInvocationGate- Parameters:
currentTime- current time in milliseconds, orInvocationGate.TIME_UNAVAILABLEif unknown- Returns:
trueif further work should be skipped;falseif the caller may proceed
-
-