Class FailureLogThrottle
- java.lang.Object
-
- org.opends.server.util.FailureLogThrottle
-
public final class FailureLogThrottle extends Object
Bounds how often a repeating failure is reported, so that a failure which a retry loop or a stream of unwanted connections reproduces many times a second is still visible in the error log without filling it.One failure is logged per interval and the failures in between are counted, so that the next one logged reports how many it stands for and a single line cannot be mistaken for a single failure. That count looks backwards only: the failures following the last one logged of a burst are counted but never reported, as nothing flushes the count when the failures stop.
The first failure is always logged, however long the throttle has existed before it.
Safe to record from several threads, and exact for one: a failure recorded while another thread is opening a new interval may be counted in the interval which is closing or in the one which opens, so the count a caller reports can be off by the failures which raced with it. It is a count of failures, not a ledger.
-
-
Constructor Summary
Constructors Constructor Description FailureLogThrottle(long interval, TimeUnit unit)Creates a throttle logging at most one failure per provided interval.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longrecord(long nowNanos)Records a failure which happened at the provided time and tells how it must be logged, together with the number of failures suppressed since the previous one logged.
-
-
-
Constructor Detail
-
FailureLogThrottle
public FailureLogThrottle(long interval, TimeUnit unit)Creates a throttle logging at most one failure per provided interval.- Parameters:
interval- The interval between two failures logged.unit- The unit the interval is expressed in.
-
-
Method Detail
-
record
public long record(long nowNanos)
Records a failure which happened at the provided time and tells how it must be logged, together with the number of failures suppressed since the previous one logged.- Parameters:
nowNanos- The value ofSystem.nanoTime()at which the failure happened.- Returns:
- A number greater than or equal to zero if this failure is to be logged, which is
then the number of failures suppressed since the previous one logged, or
-count - 1if this failure is itself to be suppressed, wherecountis the number of failures suppressed since the previous one logged, this one included.
-
-