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

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

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

revision 412 by torben, Wed Oct 7 16:42:10 2009 UTC revision 426 by torben, Fri Oct 9 06:45:40 2009 UTC
# Line 48  public class CircuitBreaker{ Line 48  public class CircuitBreaker{
48                    
49          private CircuitBreakerState currentState;          private CircuitBreakerState currentState;
50                    
51          private OpenState open = new OpenState();          private final OpenState open = new OpenState();
52          private HalfOpenState halfOpen = new HalfOpenState();          private final HalfOpenState halfOpen = new HalfOpenState();
53          private ClosedState closed = new ClosedState();          private final ClosedState closed = new ClosedState();
54                    
55          private String name;          private String name;
56                    
# Line 85  public class CircuitBreaker{ Line 85  public class CircuitBreaker{
85            
86      public void tripBreaker() {      public void tripBreaker() {
87          synchronized(this) {          synchronized(this) {
88                  open.trip();                  if (currentState != open) { // TODO:Is this conditional necessary ??
89                  currentState = open;                          open.trip();
90                            currentState = open;
91                                    
92                  notifier.sendNotification(name, Notifier.Event.BreakerTripped);                          notifier.sendNotification(name, Notifier.Event.BreakerTripped);
93                    }
94          }              }    
95      }      }
96            
97      public void attemptReset() {      public void attemptReset() {
98          synchronized(this) {          synchronized(this) {
99                  currentState = halfOpen;                  if (currentState != halfOpen) { // TODO:Is this conditional necessary ??
100                  notifier.sendNotification(name, Notifier.Event.BreakerAttemptReset);                          currentState = halfOpen;
101                            notifier.sendNotification(name, Notifier.Event.BreakerAttemptReset);
102                    }
103          }          }
104                    
105      }      }
106            
107      public void reset() {      public void reset() {
108          synchronized(this) {          synchronized(this) {
109                  currentState = closed;                  if (currentState != closed) { // TODO: Is this conditional necessary ??
110                  notifier.sendNotification(name, Notifier.Event.BreakerReset);                          currentState = closed;
111                            notifier.sendNotification(name, Notifier.Event.BreakerReset);
112                    }
113          }          }
114      }      }
115            
# Line 126  public class CircuitBreaker{ Line 132  public class CircuitBreaker{
132          return closed.getThreshold();          return closed.getThreshold();
133      }      }
134            
135        public int getTimeout() {
136            return (int)open.getTimeout();
137        }
138        
139      public int getFailureCount() {      public int getFailureCount() {
140          if (getState() == closed) {          if (getState() == closed) {
141                  return closed.getFailureCount();                  return closed.getFailureCount();

Legend:
Removed from v.412  
changed lines
  Added in v.426

  ViewVC Help
Powered by ViewVC 1.1.20