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

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

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

revision 450 by torben, Tue Oct 20 10:26:50 2009 UTC revision 460 by torben, Wed Oct 21 07:56:37 2009 UTC
# Line 1  Line 1 
1  package dk.thoerup.curcuitbreaker;  package dk.thoerup.curcuitbreaker;
2    
3  import java.util.concurrent.atomic.AtomicInteger;  import java.util.concurrent.atomic.AtomicInteger;
4    import java.util.concurrent.atomic.AtomicLong;
5    
6  public class AccountingCircuitBreaker extends CircuitBreaker {  public class AccountingCircuitBreaker extends CircuitBreaker {
7    
# Line 8  public class AccountingCircuitBreaker ex Line 9  public class AccountingCircuitBreaker ex
9          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
10          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
11          private AtomicInteger totalCallCount = new AtomicInteger(0);          private AtomicInteger totalCallCount = new AtomicInteger(0);
12                    private AtomicLong lastTrip = new AtomicLong(0);
13          private long lastResetCounters = 0;          private long lastResetCounters = 0;
14                    
15          public AccountingCircuitBreaker(String name, int threshold, long timeoutMS) {          public AccountingCircuitBreaker(String name, int threshold, long timeoutMS) {
# Line 39  public class AccountingCircuitBreaker ex Line 40  public class AccountingCircuitBreaker ex
40          public void tripBreaker() {          public void tripBreaker() {
41                  super.tripBreaker();                  super.tripBreaker();
42                  tripCount.incrementAndGet();                  tripCount.incrementAndGet();
43                    lastTrip.set( System.currentTimeMillis() );
44          }          }
45                    
46          public int getTripCount() {          public int getTripCount() {
# Line 57  public class AccountingCircuitBreaker ex Line 59  public class AccountingCircuitBreaker ex
59                  return lastResetCounters;                  return lastResetCounters;
60          }          }
61                    
62            public long getLastTrip() {
63                    return lastTrip.get();
64            }
65            
66          public int getTotalCallCount() {          public int getTotalCallCount() {
67                  return totalCallCount.get();                  return totalCallCount.get();
68          }          }
# Line 66  public class AccountingCircuitBreaker ex Line 72  public class AccountingCircuitBreaker ex
72                  blockCount.set(0);                  blockCount.set(0);
73                  totalFailureCount.set(0);                  totalFailureCount.set(0);
74                  totalCallCount.set(0);                  totalCallCount.set(0);
75                    lastTrip.set(0);
76                                    
77                  lastResetCounters = System.currentTimeMillis();                  lastResetCounters = System.currentTimeMillis();
78          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.20