3 |
import java.util.concurrent.atomic.AtomicInteger; |
import java.util.concurrent.atomic.AtomicInteger; |
4 |
import java.util.concurrent.atomic.AtomicLong; |
import java.util.concurrent.atomic.AtomicLong; |
5 |
|
|
6 |
|
import dk.thoerup.circuitbreaker.config.BreakerConfig; |
7 |
|
|
8 |
public class AccountingCircuitBreaker extends CircuitBreaker { |
public class AccountingCircuitBreaker extends CircuitBreaker { |
9 |
|
|
10 |
private AtomicInteger tripCount = new AtomicInteger(0); // how many times ahs the CB tripped |
private AtomicInteger tripCount = new AtomicInteger(0); // how many times ahs the CB tripped |
11 |
|
private AtomicInteger retripCount = new AtomicInteger(0); |
12 |
private AtomicInteger blockCount = new AtomicInteger(0); //how many times has this CB blocked a call that would otherwise go to the backend |
private AtomicInteger blockCount = new AtomicInteger(0); //how many times has this CB blocked a call that would otherwise go to the backend |
13 |
private AtomicInteger totalFailureCount = new AtomicInteger(0); //how many times has the backend thrown an exception |
private AtomicInteger totalFailureCount = new AtomicInteger(0); //how many times has the backend thrown an exception |
14 |
private AtomicInteger totalCallCount = new AtomicInteger(0); |
private AtomicInteger totalCallCount = new AtomicInteger(0); |
15 |
|
|
16 |
private AtomicLong lastTrip = new AtomicLong(0); |
private AtomicLong lastTrip = new AtomicLong(0); |
17 |
|
private AtomicLong lastRetrip = new AtomicLong(0); |
18 |
private AtomicLong lastFailure = new AtomicLong(0); |
private AtomicLong lastFailure = new AtomicLong(0); |
19 |
private AtomicLong lastReset = new AtomicLong(0); |
private AtomicLong lastReset = new AtomicLong(0); |
20 |
|
|
21 |
private long lastResetCounters = 0; |
private long lastResetCounters = 0; |
22 |
|
|
23 |
public AccountingCircuitBreaker(String name, int threshold, long timeoutMS) { |
public AccountingCircuitBreaker(String name, BreakerConfig config) { |
24 |
super(name, threshold, timeoutMS); |
super(name, config); |
25 |
|
|
26 |
resetCounters(); |
resetCounters(); |
27 |
} |
} |
52 |
lastTrip.set( System.currentTimeMillis() ); |
lastTrip.set( System.currentTimeMillis() ); |
53 |
} |
} |
54 |
|
|
55 |
|
@Override |
56 |
|
public void retripBreaker() { |
57 |
|
super.retripBreaker(); |
58 |
|
retripCount.incrementAndGet(); |
59 |
|
lastRetrip.set( System.currentTimeMillis() ); |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
@Override |
@Override |
70 |
return tripCount.get(); |
return tripCount.get(); |
71 |
} |
} |
72 |
|
|
73 |
|
public int getRetripCount() { |
74 |
|
return retripCount.get(); |
75 |
|
} |
76 |
|
|
77 |
public int getBlockCount() { |
public int getBlockCount() { |
78 |
return blockCount.get(); |
return blockCount.get(); |
79 |
} |
} |
90 |
return lastTrip.get(); |
return lastTrip.get(); |
91 |
} |
} |
92 |
|
|
93 |
|
public long getLastRetrip() { |
94 |
|
return lastRetrip.get(); |
95 |
|
} |
96 |
|
|
97 |
public long getLastFailure() { |
public long getLastFailure() { |
98 |
return lastFailure.get(); |
return lastFailure.get(); |
99 |
} |
} |
108 |
|
|
109 |
public void resetCounters() { |
public void resetCounters() { |
110 |
tripCount.set(0); |
tripCount.set(0); |
111 |
|
retripCount.set(0); |
112 |
blockCount.set(0); |
blockCount.set(0); |
113 |
totalFailureCount.set(0); |
totalFailureCount.set(0); |
114 |
totalCallCount.set(0); |
totalCallCount.set(0); |
115 |
lastTrip.set(0); |
lastTrip.set(0); |
116 |
|
lastRetrip.set(0); |
117 |
lastReset.set(0); |
lastReset.set(0); |
118 |
lastFailure.set(0); |
lastFailure.set(0); |
119 |
|
|