/[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

CircuitBreaker/src/dk/thoerup/curcuitbreaker/AccountingCircuitBreaker.java revision 460 by torben, Wed Oct 21 07:56:37 2009 UTC CircuitBreaker/src/dk/thoerup/circuitbreaker/AccountingCircuitBreaker.java revision 624 by torben, Mon Mar 8 09:46:10 2010 UTC
# Line 1  Line 1 
1  package dk.thoerup.curcuitbreaker;  package dk.thoerup.circuitbreaker;
2    
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;
# Line 9  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            
13          private AtomicLong lastTrip = new AtomicLong(0);          private AtomicLong lastTrip = new AtomicLong(0);
14            private AtomicLong lastFailure = new AtomicLong(0);
15            private AtomicLong lastReset = new AtomicLong(0);
16            
17          private long lastResetCounters = 0;          private long lastResetCounters = 0;
18                    
19          public AccountingCircuitBreaker(String name, int threshold, long timeoutMS) {          public AccountingCircuitBreaker(String name, int threshold, long timeoutMS) {
# Line 29  public class AccountingCircuitBreaker ex Line 33  public class AccountingCircuitBreaker ex
33                                  blockCount.incrementAndGet();                                  blockCount.incrementAndGet();
34                          } else {                          } else {
35                                  totalFailureCount.incrementAndGet();                                  totalFailureCount.incrementAndGet();
36                                    lastFailure.set( System.currentTimeMillis() );
37                          }                          }
38                          throw e;                          throw e;
39                  }                  }
# Line 43  public class AccountingCircuitBreaker ex Line 48  public class AccountingCircuitBreaker ex
48                  lastTrip.set( System.currentTimeMillis() );                  lastTrip.set( System.currentTimeMillis() );
49          }          }
50                    
51            
52            
53            @Override
54            public void reset() {
55                    super.reset();
56                    lastReset.set( System.currentTimeMillis());
57            }
58    
59          public int getTripCount() {          public int getTripCount() {
60                  return tripCount.get();                  return tripCount.get();
61          }          }
# Line 63  public class AccountingCircuitBreaker ex Line 76  public class AccountingCircuitBreaker ex
76                  return lastTrip.get();                  return lastTrip.get();
77          }          }
78                    
79            public long getLastFailure() {
80                    return lastFailure.get();
81            }
82            
83            public long getLastReset() {
84                    return lastReset.get();
85            }
86            
87          public int getTotalCallCount() {          public int getTotalCallCount() {
88                  return totalCallCount.get();                  return totalCallCount.get();
89          }          }
# Line 73  public class AccountingCircuitBreaker ex Line 94  public class AccountingCircuitBreaker ex
94                  totalFailureCount.set(0);                  totalFailureCount.set(0);
95                  totalCallCount.set(0);                  totalCallCount.set(0);
96                  lastTrip.set(0);                  lastTrip.set(0);
97                    lastReset.set(0);
98                    lastFailure.set(0);
99                                    
100                  lastResetCounters = System.currentTimeMillis();                  lastResetCounters = System.currentTimeMillis();
101          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.20