--- CircuitBreaker/src/dk/thoerup/curcuitbreaker/AccountingCircuitBreaker.java 2009/10/06 13:21:12 400 +++ CircuitBreaker/src/dk/thoerup/curcuitbreaker/AccountingCircuitBreaker.java 2009/10/07 04:17:45 404 @@ -6,9 +6,10 @@ private AtomicInteger tripCount = new AtomicInteger(0); // how many times ahs the CB tripped private AtomicInteger blockCount = new AtomicInteger(0); //how many times has this CB blocked a call that would otherwise go to the backend - private AtomicInteger failureCount = 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 + private AtomicInteger totalCallCount = new AtomicInteger(0); - private long lastReset = 0; + private long lastResetCounters = 0; public AccountingCircuitBreaker(String name, int threshold, long timeoutMS) { super(name, threshold, timeoutMS); @@ -18,12 +19,13 @@ public Object invoke(CircuitInvocation invocation) throws Throwable { Object result; try { + totalCallCount.incrementAndGet(); result = super.invoke(invocation); } catch (Throwable t) { if (t instanceof CircuitBreakerException) { blockCount.incrementAndGet(); } else { - failureCount.incrementAndGet(); + totalFailureCount.incrementAndGet(); } throw t; } @@ -45,20 +47,25 @@ return blockCount.get(); } - public int getFailureCount() { - return failureCount.get(); + public int getTotalFailureCount() { + return totalFailureCount.get(); } - public long getLastReset() { - return lastReset; + public long getLastResetCounters() { + return lastResetCounters; + } + + public int getTotalCallCount() { + return totalCallCount.get(); } public void resetCounters() { tripCount.set(0); blockCount.set(0); - failureCount.set(0); + totalFailureCount.set(0); + totalCallCount.set(0); - lastReset = System.currentTimeMillis(); + lastResetCounters = System.currentTimeMillis(); } }