/[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

CircuitBreaker/src/dk/thoerup/curcuitbreaker/CircuitBreaker.java revision 450 by torben, Tue Oct 20 10:26:50 2009 UTC CircuitBreaker/src/dk/thoerup/circuitbreaker/CircuitBreaker.java revision 627 by torben, Mon Mar 8 10:12:59 2010 UTC
# Line 1  Line 1 
1  package dk.thoerup.curcuitbreaker;  package dk.thoerup.circuitbreaker;
2    
3    
4  import dk.thoerup.curcuitbreaker.notification.Notifier;  import dk.thoerup.circuitbreaker.notification.Notifier;
5  import dk.thoerup.curcuitbreaker.notification.NullNotifier;  import dk.thoerup.circuitbreaker.notification.NullNotifier;
6    
7  /* 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
8   *   *
# Line 31  import dk.thoerup.curcuitbreaker.notific Line 31  import dk.thoerup.curcuitbreaker.notific
31                  try {                  try {
32                          String s = (String) cb.invoke(new TestInvocation("http://rafiki/test"));                          String s = (String) cb.invoke(new TestInvocation("http://rafiki/test"));
33                          response.getWriter().print(s);                          response.getWriter().print(s);
34                  } catch (Throwable e) {                  } catch (Exception e) {
35                          logger.warning( e.getMessage() );                          logger.warning( e.getMessage() );
36                          response.sendError(500);                          response.sendError(500);
37                          return;                          return;
# Line 58  public class CircuitBreaker{ Line 58  public class CircuitBreaker{
58                  open.setTimeout(timeoutMS);                  open.setTimeout(timeoutMS);
59                                    
60                  this.name = name;                  this.name = name;
61                            
62                  reset();                  //set correct intial state
63                    internalReset();
64          }          }
65                    
66                    
# Line 104  public class CircuitBreaker{ Line 105  public class CircuitBreaker{
105      public void reset() {      public void reset() {
106          synchronized(this) {          synchronized(this) {
107                  if (currentState != closed) { // TODO: Is this conditional necessary ??                  if (currentState != closed) { // TODO: Is this conditional necessary ??
108                          currentState = closed;                          internalReset();
109                          notifier.sendNotification(name, Notifier.Event.BreakerReset);                          notifier.sendNotification(name, Notifier.Event.BreakerReset);
110                  }                  }
111          }          }
112      }      }
113            
114        //This one actually sets the correct closed/reset state
115        private void internalReset() {
116                    closed.resetFailureCount();
117                    currentState = closed;          
118        }
119        
120            
121      private CircuitBreakerState getState() {      private CircuitBreakerState getState() {
122          synchronized(this) {          synchronized(this) {

Legend:
Removed from v.450  
changed lines
  Added in v.627

  ViewVC Help
Powered by ViewVC 1.1.20