Package dev.failsafe.internal
Class TimedCircuitStats
- java.lang.Object
-
- dev.failsafe.internal.TimedCircuitStats
-
- All Implemented Interfaces:
CircuitStats
class TimedCircuitStats extends java.lang.Object implements CircuitStats
A CircuitStats implementation that counts execution results within a time period, and buckets results to minimize overhead.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
TimedCircuitStats.Bucket
(package private) static class
TimedCircuitStats.Clock
(package private) static class
TimedCircuitStats.Stat
-
Field Summary
Fields Modifier and Type Field Description (package private) TimedCircuitStats.Bucket[]
buckets
private long
bucketSizeMillis
private TimedCircuitStats.Clock
clock
(package private) int
currentIndex
(package private) static int
DEFAULT_BUCKET_COUNT
private TimedCircuitStats.Stat
summary
private long
windowSizeMillis
-
Constructor Summary
Constructors Constructor Description TimedCircuitStats(int bucketCount, java.time.Duration thresholdingPeriod, TimedCircuitStats.Clock clock, CircuitStats oldStats)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
copyStats(CircuitStats oldStats)
Copies the most recent stats from theoldStats
into this in order from oldest to newest and orders buckets from oldest to newest, with uninitialized buckets counting as oldest.(package private) TimedCircuitStats.Bucket
getCurrentBucket()
Returns the current bucket based on the current time, moving the internal storage to the current bucket if necessary, resetting bucket stats along the way.int
getExecutionCount()
int
getFailureCount()
int
getFailureRate()
int
getSuccessCount()
int
getSuccessRate()
private int
indexAfter(int index)
Returns the index after theindex
.private int
indexBefore(int index)
Returns the index before theindex
.private int
nextIndex()
Returns the next index.void
recordFailure()
void
recordSuccess()
void
reset()
java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface dev.failsafe.internal.CircuitStats
copyExecutions
-
-
-
-
Field Detail
-
DEFAULT_BUCKET_COUNT
static final int DEFAULT_BUCKET_COUNT
- See Also:
- Constant Field Values
-
clock
private final TimedCircuitStats.Clock clock
-
bucketSizeMillis
private final long bucketSizeMillis
-
windowSizeMillis
private final long windowSizeMillis
-
buckets
final TimedCircuitStats.Bucket[] buckets
-
summary
private final TimedCircuitStats.Stat summary
-
currentIndex
volatile int currentIndex
-
-
Constructor Detail
-
TimedCircuitStats
public TimedCircuitStats(int bucketCount, java.time.Duration thresholdingPeriod, TimedCircuitStats.Clock clock, CircuitStats oldStats)
-
-
Method Detail
-
copyStats
void copyStats(CircuitStats oldStats)
Copies the most recent stats from theoldStats
into this in order from oldest to newest and orders buckets from oldest to newest, with uninitialized buckets counting as oldest.
-
recordSuccess
public void recordSuccess()
- Specified by:
recordSuccess
in interfaceCircuitStats
-
recordFailure
public void recordFailure()
- Specified by:
recordFailure
in interfaceCircuitStats
-
getExecutionCount
public int getExecutionCount()
- Specified by:
getExecutionCount
in interfaceCircuitStats
-
getFailureCount
public int getFailureCount()
- Specified by:
getFailureCount
in interfaceCircuitStats
-
getFailureRate
public int getFailureRate()
- Specified by:
getFailureRate
in interfaceCircuitStats
-
getSuccessCount
public int getSuccessCount()
- Specified by:
getSuccessCount
in interfaceCircuitStats
-
getSuccessRate
public int getSuccessRate()
- Specified by:
getSuccessRate
in interfaceCircuitStats
-
reset
public void reset()
- Specified by:
reset
in interfaceCircuitStats
-
getCurrentBucket
TimedCircuitStats.Bucket getCurrentBucket()
Returns the current bucket based on the current time, moving the internal storage to the current bucket if necessary, resetting bucket stats along the way.
-
nextIndex
private int nextIndex()
Returns the next index.
-
indexAfter
private int indexAfter(int index)
Returns the index after theindex
.
-
indexBefore
private int indexBefore(int index)
Returns the index before theindex
.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-