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

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

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

revision 397 by torben, Tue Oct 6 05:22:40 2009 UTC revision 409 by torben, Wed Oct 7 07:07:00 2009 UTC
# Line 2  package dk.thoerup.curcuitbreaker; Line 2  package dk.thoerup.curcuitbreaker;
2    
3  import java.util.logging.Logger;  import java.util.logging.Logger;
4    
5    import dk.thoerup.curcuitbreaker.notification.Notifier;
6    import dk.thoerup.curcuitbreaker.notification.NullNotifier;
7    
8  /* Simple CircuitBreaker implementation - snipped from http://www.jroller.com/kenwdelong/entry/circuit_breaker_in_java  /* Simple CircuitBreaker implementation - snipped from http://www.jroller.com/kenwdelong/entry/circuit_breaker_in_java
9   *   *
10   *  example of how it can be used   *  example of how it can be used
# Line 51  public class CircuitBreaker{ Line 54  public class CircuitBreaker{
54                    
55          private String name;          private String name;
56                    
57            private Notifier notifier = new NullNotifier();
58            
59          public CircuitBreaker(String name, int threshold, long timeoutMS) {          public CircuitBreaker(String name, int threshold, long timeoutMS) {
60                  closed.setThreshold(threshold);                  closed.setThreshold(threshold);
61                  open.setTimeout(timeoutMS);                  open.setTimeout(timeoutMS);
# Line 82  public class CircuitBreaker{ Line 87  public class CircuitBreaker{
87          synchronized(this) {          synchronized(this) {
88                  open.trip();                  open.trip();
89                  currentState = open;                  currentState = open;
   
90                                    
91                  logger.warning("Circuitbreaker tripBreaker - " + name);                  notifier.sendNotification(name, Notifier.Event.BreakerTripped);
92          }          }    
       
93      }      }
94            
95      public void attemptReset() {      public void attemptReset() {
96          synchronized(this) {          synchronized(this) {
97                  currentState = halfOpen;                  currentState = halfOpen;
98                                    notifier.sendNotification(name, Notifier.Event.BreakerAttemptReset);
                 logger.warning("Circuitbreaker attemptReset - " + name);  
99          }          }
100            
101      }      }
102            
103      public void reset() {      public void reset() {
104          synchronized(this) {          synchronized(this) {
105                  currentState = closed;                  currentState = closed;
106                                    notifier.sendNotification(name, Notifier.Event.BreakerReset);
                 logger.warning("Circuitbreaker reset - " + name);  
107          }          }
108      }      }
109            
# Line 139  public class CircuitBreaker{ Line 141  public class CircuitBreaker{
141                  return -1;                  return -1;
142          }          }
143      }      }
144        
145        public void setNotifier(Notifier notifier) {
146            this.notifier = notifier;
147        }
148        
149        public String getNotifierName() {
150            return notifier.toString();
151        }
152    
153  }  }

Legend:
Removed from v.397  
changed lines
  Added in v.409

  ViewVC Help
Powered by ViewVC 1.1.20