/[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 403 by torben, Wed Oct 7 04:14:14 2009 UTC revision 450 by torben, Tue Oct 20 10:26:50 2009 UTC
# Line 9  public class AccountingCircuitBreaker ex Line 9  public class AccountingCircuitBreaker ex
9          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
10          private AtomicInteger totalCallCount = new AtomicInteger(0);          private AtomicInteger totalCallCount = new AtomicInteger(0);
11                    
12          private long lastReset = 0;          private long lastResetCounters = 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);
16    
17                    resetCounters();
18          }          }
19    
20          @Override          @Override
21          public Object invoke(CircuitInvocation invocation) throws Throwable {          public Object invoke(CircuitInvocation invocation) throws Exception {
22                  Object result;                  Object result;
23                  try {                  try {
24                          totalCallCount.incrementAndGet();                          totalCallCount.incrementAndGet();
25                          result = super.invoke(invocation);                          result = super.invoke(invocation);
26                  } catch (Throwable t) {                  } catch (Exception e) {
27                          if (t instanceof CircuitBreakerException) {                          if (e instanceof CircuitBreakerException) {
28                                  blockCount.incrementAndGet();                                  blockCount.incrementAndGet();
29                          } else {                          } else {
30                                  totalFailureCount.incrementAndGet();                                  totalFailureCount.incrementAndGet();
31                          }                          }
32                          throw t;                          throw e;
33                  }                  }
34                                    
35                  return result;                  return result;
# Line 51  public class AccountingCircuitBreaker ex Line 53  public class AccountingCircuitBreaker ex
53                  return totalFailureCount.get();                  return totalFailureCount.get();
54          }          }
55                    
56          public long getLastReset() {          public long getLastResetCounters() {
57                  return lastReset;                  return lastResetCounters;
58          }          }
59                    
60          public int getTotalCallCount() {          public int getTotalCallCount() {
# Line 65  public class AccountingCircuitBreaker ex Line 67  public class AccountingCircuitBreaker ex
67                  totalFailureCount.set(0);                  totalFailureCount.set(0);
68                  totalCallCount.set(0);                  totalCallCount.set(0);
69                                    
70                  lastReset = System.currentTimeMillis();                  lastResetCounters = System.currentTimeMillis();
71          }          }
72                    
73  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20