Class FixedIntervalInvocationGate

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-based 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 Details

  • Constructor Details

  • Method Details

    • isTooSoon

      public boolean isTooSoon(long currentTime)
      Returns true if the caller should skip further work; false if this call is allowed to proceed.

      If currentTime is InvocationGate.TIME_UNAVAILABLE (-1), this method returns false so the caller can still perform the work when the clock is unavailable.

      Otherwise, when currentTime is strictly before the next allowed time, the method returns true (too soon). When currentTime has reached the next allowed time, this thread tries to advance that time by increment. On success it returns false (proceed); if another thread already advanced it, this thread returns true so that only one passage per interval is granted.

      Specified by:
      isTooSoon in interface InvocationGate
      Parameters:
      currentTime - current time in milliseconds, or InvocationGate.TIME_UNAVAILABLE if unknown
      Returns:
      true if further work should be skipped; false if the caller may proceed