/[projects]/miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/AccountingCircuitBreaker.java
ViewVC logotype

Annotation of /miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/AccountingCircuitBreaker.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 399 - (hide annotations) (download)
Tue Oct 6 13:17:41 2009 UTC (14 years, 7 months ago) by torben
Original Path: CircuitBreaker/src/dk/thoerup/curcuitbreaker/AccountingCircuitBreaker.java
File size: 1414 byte(s)
More features
1 torben 399 package dk.thoerup.curcuitbreaker;
2    
3     import java.util.concurrent.atomic.AtomicInteger;
4    
5     public class AccountingCircuitBreaker extends CircuitBreaker {
6    
7     private AtomicInteger tripCount = new AtomicInteger(0); // how many times ahs the CB tripped
8     private AtomicInteger blockCount = new AtomicInteger(0); //how many times has this CB blocked a call that would otherwise go to the backend
9     private AtomicInteger failureCount = new AtomicInteger(0); //how many times has the backend thrown an exception
10    
11     public AccountingCircuitBreaker(String name, int threshold, long timeoutMS) {
12     super(name, threshold, timeoutMS);
13     }
14    
15     @Override
16     public Object invoke(CircuitInvocation invocation) throws Throwable {
17     Object result;
18     try {
19     result = super.invoke(invocation);
20     } catch (Throwable t) {
21     if (t instanceof CircuitBreakerException) {
22     blockCount.incrementAndGet();
23     } else {
24     failureCount.incrementAndGet();
25     }
26     throw t;
27     }
28    
29     return result;
30     }
31    
32     @Override
33     public void tripBreaker() {
34     super.tripBreaker();
35     tripCount.incrementAndGet();
36     }
37    
38     public int getTripCount() {
39     return tripCount.get();
40     }
41    
42     public int getBlockCount() {
43     return blockCount.get();
44     }
45    
46     public int getFailureCount() {
47     return failureCount.get();
48     }
49    
50     public void resetCounters() {
51     tripCount.set(0);
52     blockCount.set(0);
53     failureCount.set(0);
54     }
55    
56     }

  ViewVC Help
Powered by ViewVC 1.1.20