--- CircuitBreaker/src/dk/thoerup/curcuitbreaker/AccountingCircuitBreaker.java 2009/10/20 10:26:50 450 +++ CircuitBreaker/src/dk/thoerup/circuitbreaker/AccountingCircuitBreaker.java 2010/06/20 21:54:53 864 @@ -1,14 +1,21 @@ -package dk.thoerup.curcuitbreaker; +package dk.thoerup.circuitbreaker; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; public class AccountingCircuitBreaker extends CircuitBreaker { private AtomicInteger tripCount = new AtomicInteger(0); // how many times ahs the CB tripped + private AtomicInteger retripCount = new AtomicInteger(0); private AtomicInteger blockCount = new AtomicInteger(0); //how many times has this CB blocked a call that would otherwise go to the backend private AtomicInteger totalFailureCount = new AtomicInteger(0); //how many times has the backend thrown an exception private AtomicInteger totalCallCount = new AtomicInteger(0); + private AtomicLong lastTrip = new AtomicLong(0); + private AtomicLong lastRetrip = new AtomicLong(0); + private AtomicLong lastFailure = new AtomicLong(0); + private AtomicLong lastReset = new AtomicLong(0); + private long lastResetCounters = 0; public AccountingCircuitBreaker(String name, int threshold, long timeoutMS) { @@ -28,6 +35,7 @@ blockCount.incrementAndGet(); } else { totalFailureCount.incrementAndGet(); + lastFailure.set( System.currentTimeMillis() ); } throw e; } @@ -39,12 +47,31 @@ public void tripBreaker() { super.tripBreaker(); tripCount.incrementAndGet(); + lastTrip.set( System.currentTimeMillis() ); } + @Override + public void retripBreaker() { + super.retripBreaker(); + retripCount.incrementAndGet(); + lastRetrip.set( System.currentTimeMillis() ); + } + + + @Override + public void reset() { + super.reset(); + lastReset.set( System.currentTimeMillis()); + } + public int getTripCount() { return tripCount.get(); } + public int getRetripCount() { + return retripCount.get(); + } + public int getBlockCount() { return blockCount.get(); } @@ -57,15 +84,36 @@ return lastResetCounters; } + public long getLastTrip() { + return lastTrip.get(); + } + + public long getLastRetrip() { + return lastRetrip.get(); + } + + public long getLastFailure() { + return lastFailure.get(); + } + + public long getLastReset() { + return lastReset.get(); + } + public int getTotalCallCount() { return totalCallCount.get(); } public void resetCounters() { tripCount.set(0); + retripCount.set(0); blockCount.set(0); totalFailureCount.set(0); totalCallCount.set(0); + lastTrip.set(0); + lastRetrip.set(0); + lastReset.set(0); + lastFailure.set(0); lastResetCounters = System.currentTimeMillis(); }