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

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

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

revision 624 by torben, Mon Mar 8 09:46:10 2010 UTC revision 1376 by torben, Sat Apr 23 10:43:40 2011 UTC
# Line 3  package dk.thoerup.circuitbreaker; Line 3  package dk.thoerup.circuitbreaker;
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    import dk.thoerup.circuitbreaker.config.StaticConfig;
8    
9  public class AccountingCircuitBreaker extends CircuitBreaker {  public class AccountingCircuitBreaker extends CircuitBreaker {
10    
11          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  
12            private AtomicInteger retripCount = new AtomicInteger(0);  
13          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
14          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
15          private AtomicInteger totalCallCount = new AtomicInteger(0);          private AtomicInteger totalCallCount = new AtomicInteger(0);
16                    
17          private AtomicLong lastTrip = new AtomicLong(0);          private AtomicLong lastTrip = new AtomicLong(0);
18            private AtomicLong lastRetrip = new AtomicLong(0);
19          private AtomicLong lastFailure = new AtomicLong(0);          private AtomicLong lastFailure = new AtomicLong(0);
20          private AtomicLong lastReset = new AtomicLong(0);          private AtomicLong lastReset = new AtomicLong(0);
21                    
22          private long lastResetCounters = 0;          private long lastResetCounters = 0;
23                    
24          public AccountingCircuitBreaker(String name, int threshold, long timeoutMS) {          @Deprecated
25                  super(name, threshold, timeoutMS);          public AccountingCircuitBreaker(String name, int treshold, int timeout) {
26                    this(name,  new StaticConfig(treshold, timeout) ) ;
27            }
28            
29            public AccountingCircuitBreaker(String name, BreakerConfig config) {
30                    super(name, config);
31    
32                  resetCounters();                  resetCounters();
33          }          }
# Line 48  public class AccountingCircuitBreaker ex Line 58  public class AccountingCircuitBreaker ex
58                  lastTrip.set( System.currentTimeMillis() );                  lastTrip.set( System.currentTimeMillis() );
59          }          }
60                    
61            @Override
62            public void retripBreaker() {
63                    super.retripBreaker();
64                    retripCount.incrementAndGet();
65                    lastRetrip.set( System.currentTimeMillis() );
66            }
67                    
68                    
69          @Override          @Override
# Line 60  public class AccountingCircuitBreaker ex Line 76  public class AccountingCircuitBreaker ex
76                  return tripCount.get();                  return tripCount.get();
77          }          }
78                    
79            public int getRetripCount() {
80                    return retripCount.get();
81            }
82    
83          public int getBlockCount() {          public int getBlockCount() {
84                  return blockCount.get();                          return blockCount.get();        
85          }          }
# Line 76  public class AccountingCircuitBreaker ex Line 96  public class AccountingCircuitBreaker ex
96                  return lastTrip.get();                  return lastTrip.get();
97          }          }
98                    
99            public long getLastRetrip() {
100                    return lastRetrip.get();
101            }
102    
103          public long getLastFailure() {          public long getLastFailure() {
104                  return lastFailure.get();                  return lastFailure.get();
105          }          }
# Line 90  public class AccountingCircuitBreaker ex Line 114  public class AccountingCircuitBreaker ex
114                    
115          public void resetCounters() {          public void resetCounters() {
116                  tripCount.set(0);                  tripCount.set(0);
117                    retripCount.set(0);
118                  blockCount.set(0);                  blockCount.set(0);
119                  totalFailureCount.set(0);                  totalFailureCount.set(0);
120                  totalCallCount.set(0);                  totalCallCount.set(0);
121                  lastTrip.set(0);                  lastTrip.set(0);
122                    lastRetrip.set(0);
123                  lastReset.set(0);                  lastReset.set(0);
124                  lastFailure.set(0);                  lastFailure.set(0);
125                                    

Legend:
Removed from v.624  
changed lines
  Added in v.1376

  ViewVC Help
Powered by ViewVC 1.1.20