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

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

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

revision 1305 by torben, Thu Oct 22 06:01:35 2009 UTC revision 1306 by torben, Tue Apr 19 15:22:09 2011 UTC
# Line 1  Line 1 
1  package dk.thoerup.circuitbreaker;  package dk.thoerup.circuitbreaker;
2    
3  import java.util.concurrent.atomic.*;  import java.util.concurrent.atomic.AtomicInteger;
4    
5    import dk.thoerup.circuitbreaker.config.BreakerConfig;
6    
7    
8    
9  public final class ClosedState implements CircuitBreakerState {  public final class ClosedState implements CircuitBreakerState {
10    
11          final AtomicInteger failureCount = new AtomicInteger(0);          final AtomicInteger failureCount = new AtomicInteger(0);
         final AtomicInteger failureThreshold = new AtomicInteger(0);  
12                    
13          public void setThreshold(int threshold) {          
14                  failureThreshold.set( threshold );          BreakerConfig config;
15            
16            public void setThreshold(BreakerConfig config) {
17                    this.config = config;
18          }          }
19    
20      public void preInvoke(CircuitBreaker circuitBreaker) throws Exception      public void preInvoke(CircuitBreaker circuitBreaker) throws Exception
# Line 26  public final class ClosedState implement Line 30  public final class ClosedState implement
30      public void onError(CircuitBreaker circuitBreaker, Exception t) throws Exception      public void onError(CircuitBreaker circuitBreaker, Exception t) throws Exception
31      {      {
32          int currentCount = failureCount.incrementAndGet();          int currentCount = failureCount.incrementAndGet();
33          int threshold = failureThreshold.get();          int threshold = config.getTreshold();
34          if(currentCount >= threshold)          if(currentCount >= threshold)
35              circuitBreaker.tripBreaker();              circuitBreaker.tripBreaker();
36      }      }
# Line 44  public final class ClosedState implement Line 48  public final class ClosedState implement
48          }          }
49                    
50          public int getThreshold() {          public int getThreshold() {
51                  return failureThreshold.get();                  return config.getTreshold();
52          }          }
53  }  }

Legend:
Removed from v.1305  
changed lines
  Added in v.1306

  ViewVC Help
Powered by ViewVC 1.1.20