- java.lang.Object
-
- ch.qos.logback.core.util.FixedIntervalInvocationGate
-
- All Implemented Interfaces:
InvocationGate
- Direct Known Subclasses:
SimpleInvocationGate
public class FixedIntervalInvocationGate extends Object implements InvocationGate
A time-basedInvocationGatewith 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. receivesfalse); other threads in the same window receivetrueand 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 fixedDuration.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:
InvocationGate,DefaultInvocationGate,BatchedFixedIntervalInvocationGate,SizeBasedTriggeringPolicy
-
-
Field Summary
Fields Modifier and Type Field Description static DurationDEFAULT_INCREMENTDefault increment: 60 seconds.-
Fields inherited from interface ch.qos.logback.core.util.InvocationGate
TIME_UNAVAILABLE
-
-
Constructor Summary
Constructors Constructor Description FixedIntervalInvocationGate()Creates a gate withDEFAULT_INCREMENT.FixedIntervalInvocationGate(Duration anIncrement)Creates a gate that allows at most one successful passage peranIncrementperiod.
-
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_INCREMENT
public static final Duration DEFAULT_INCREMENT
Default increment: 60 seconds.
-
-
Constructor Detail
-
FixedIntervalInvocationGate
public FixedIntervalInvocationGate()
Creates a gate withDEFAULT_INCREMENT.
-
FixedIntervalInvocationGate
public FixedIntervalInvocationGate(Duration anIncrement)
Creates a gate that allows at most one successful passage peranIncrementperiod.- Parameters:
anIncrement- duration between allowed invocations; 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), 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
-
-