Class BatchedFixedIntervalInvocationGate
- All Implemented Interfaces:
InvocationGate
InvocationGate that allows a fixed number of successive callers to
proceed, then enforces a lull of a fixed Duration.
Callers on a hot path use isTooSoon(long) to decide whether to skip a
costly operation. Up to N invocations may receive
false (proceed) in succession. After the N-th success, the gate enters
a lull of increment milliseconds during which all
callers receive true (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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault batch size: number of successive allowed passages before a lull.static final DurationDefault 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
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionbooleanisTooSoon(long currentTime) Returnstrueif the caller should skip further work;falseif this call is allowed to proceed.
-
Field Details
-
DEFAULT_BATCH_SIZE
Default batch size: number of successive allowed passages before a lull.- See Also:
-
DEFAULT_INCREMENT
Default lull duration after a batch is exhausted (same asFixedIntervalInvocationGate.DEFAULT_INCREMENT).
-
-
Constructor Details
-
BatchedFixedIntervalInvocationGate
public BatchedFixedIntervalInvocationGate()Creates a gate withDEFAULT_BATCH_SIZEandDEFAULT_INCREMENT. -
BatchedFixedIntervalInvocationGate
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
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 Details
-
isTooSoon
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
-