- All Implemented Interfaces:
InvocationGate
- Direct Known Subclasses:
SimpleInvocationGate
InvocationGate with fixed-interval logic.
Callers on a hot path use isTooSoon(long) to decide whether to skip
a costly operation. At most one thread per increment
interval is allowed to proceed (i.e. receives false); other threads
in the same window receive true and should skip the work.
Compared to DefaultInvocationGate, this implementation does not adapt
a sampling mask. It only advances an atomic next-allowed timestamp by a fixed
Duration.
Typical use is size checks in rolling policies where file length is expensive relative to the logging call.
- Since:
- 1.3.6/1.4.6 (formerly
SimpleInvocationGate) - Author:
- Ceki Gülcü
- See Also:
-
Field Summary
FieldsFields inherited from interface ch.qos.logback.core.util.InvocationGate
TIME_UNAVAILABLE -
Constructor Summary
ConstructorsConstructorDescriptionCreates a gate withDEFAULT_INCREMENT.FixedIntervalInvocationGate(Duration anIncrement) Creates a gate that allows at most one successful passage peranIncrementperiod. -
Method Summary
Modifier and TypeMethodDescriptionbooleanisTooSoon(long currentTime) Returnstrueif the caller should skip further work;falseif this call is allowed to proceed.
-
Field Details
-
DEFAULT_INCREMENT
Default increment: 60 seconds.
-
-
Constructor Details
-
FixedIntervalInvocationGate
public FixedIntervalInvocationGate()Creates a gate withDEFAULT_INCREMENT. -
FixedIntervalInvocationGate
Creates a gate that allows at most one successful passage peranIncrementperiod.- Parameters:
anIncrement- duration between allowed invocations; 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), this method returnsfalseso the caller can still perform the work when the clock is unavailable.Otherwise, when
currentTimeis strictly before the next allowed time, the method returnstrue(too soon). WhencurrentTimehas reached the next allowed time, this thread tries to advance that time byincrement. On success it returnsfalse(proceed); if another thread already advanced it, this thread returnstrueso that only one passage per interval is granted.- 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
-