/[projects]/CircuitBreaker/src/dk/thoerup/curcuitbreaker/AccountingCircuitBreaker.java
ViewVC logotype

Diff of /CircuitBreaker/src/dk/thoerup/curcuitbreaker/AccountingCircuitBreaker.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 399 by torben, Tue Oct 6 13:17:41 2009 UTC revision 403 by torben, Wed Oct 7 04:14:14 2009 UTC
# Line 6  public class AccountingCircuitBreaker ex Line 6  public class AccountingCircuitBreaker ex
6    
7          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  
8          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
9          private AtomicInteger failureCount = 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
10            private AtomicInteger totalCallCount = new AtomicInteger(0);
11            
12            private long lastReset = 0;
13                    
14          public AccountingCircuitBreaker(String name, int threshold, long timeoutMS) {          public AccountingCircuitBreaker(String name, int threshold, long timeoutMS) {
15                  super(name, threshold, timeoutMS);                  super(name, threshold, timeoutMS);
# Line 16  public class AccountingCircuitBreaker ex Line 19  public class AccountingCircuitBreaker ex
19          public Object invoke(CircuitInvocation invocation) throws Throwable {          public Object invoke(CircuitInvocation invocation) throws Throwable {
20                  Object result;                  Object result;
21                  try {                  try {
22                            totalCallCount.incrementAndGet();
23                          result = super.invoke(invocation);                          result = super.invoke(invocation);
24                  } catch (Throwable t) {                  } catch (Throwable t) {
25                          if (t instanceof CircuitBreakerException) {                          if (t instanceof CircuitBreakerException) {
26                                  blockCount.incrementAndGet();                                  blockCount.incrementAndGet();
27                          } else {                          } else {
28                                  failureCount.incrementAndGet();                                  totalFailureCount.incrementAndGet();
29                          }                          }
30                          throw t;                          throw t;
31                  }                  }
# Line 43  public class AccountingCircuitBreaker ex Line 47  public class AccountingCircuitBreaker ex
47                  return blockCount.get();                          return blockCount.get();        
48          }          }
49                    
50          public int getFailureCount() {          public int getTotalFailureCount() {
51                  return failureCount.get();                  return totalFailureCount.get();
52            }
53            
54            public long getLastReset() {
55                    return lastReset;
56            }
57            
58            public int getTotalCallCount() {
59                    return totalCallCount.get();
60          }          }
61                    
62          public void resetCounters() {          public void resetCounters() {
63                  tripCount.set(0);                  tripCount.set(0);
64                  blockCount.set(0);                  blockCount.set(0);
65                  failureCount.set(0);                  totalFailureCount.set(0);
66                    totalCallCount.set(0);
67                    
68                    lastReset = System.currentTimeMillis();
69          }          }
70                    
71  }  }

Legend:
Removed from v.399  
changed lines
  Added in v.403

  ViewVC Help
Powered by ViewVC 1.1.20