--- CircuitBreaker/src/dk/thoerup/curcuitbreaker/CircuitBreaker.java 2009/10/07 17:56:13 413 +++ CircuitBreaker/src/dk/thoerup/curcuitbreaker/CircuitBreaker.java 2009/10/09 06:45:40 426 @@ -48,9 +48,9 @@ private CircuitBreakerState currentState; - private OpenState open = new OpenState(); - private HalfOpenState halfOpen = new HalfOpenState(); - private ClosedState closed = new ClosedState(); + private final OpenState open = new OpenState(); + private final HalfOpenState halfOpen = new HalfOpenState(); + private final ClosedState closed = new ClosedState(); private String name; @@ -85,25 +85,31 @@ public void tripBreaker() { synchronized(this) { - open.trip(); - currentState = open; + if (currentState != open) { // TODO:Is this conditional necessary ?? + open.trip(); + currentState = open; - notifier.sendNotification(name, Notifier.Event.BreakerTripped); + notifier.sendNotification(name, Notifier.Event.BreakerTripped); + } } } public void attemptReset() { synchronized(this) { - currentState = halfOpen; - notifier.sendNotification(name, Notifier.Event.BreakerAttemptReset); + if (currentState != halfOpen) { // TODO:Is this conditional necessary ?? + currentState = halfOpen; + notifier.sendNotification(name, Notifier.Event.BreakerAttemptReset); + } } } public void reset() { synchronized(this) { - currentState = closed; - notifier.sendNotification(name, Notifier.Event.BreakerReset); + if (currentState != closed) { // TODO: Is this conditional necessary ?? + currentState = closed; + notifier.sendNotification(name, Notifier.Event.BreakerReset); + } } }