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

CircuitBreaker/src/dk/thoerup/curcuitbreaker/ClosedState.java revision 393 by torben, Mon Oct 5 19:44:40 2009 UTC CircuitBreaker/src/dk/thoerup/circuitbreaker/ClosedState.java revision 467 by torben, Thu Oct 22 06:01:35 2009 UTC
# Line 1  Line 1 
1  package dk.thoerup.curcuitbreaker;  package dk.thoerup.circuitbreaker;
2    
3  import java.util.concurrent.atomic.*;  import java.util.concurrent.atomic.*;
4    
5    
6    
7  public class ClosedState implements CircuitBreakerState {  public final class ClosedState implements CircuitBreakerState {
8    
9          AtomicInteger failureCount = new AtomicInteger(0);          final AtomicInteger failureCount = new AtomicInteger(0);
10          AtomicInteger failureThreshold = new AtomicInteger(0);          final AtomicInteger failureThreshold = new AtomicInteger(0);
11                    
12          public void setThreshold(int threshold) {          public void setThreshold(int threshold) {
13                  failureThreshold.set( threshold );                  failureThreshold.set( threshold );
14          }          }
15    
16      public void preInvoke(CircuitBreaker circuitBreaker) throws Throwable      public void preInvoke(CircuitBreaker circuitBreaker) throws Exception
17      {      {
18          // NO OP          // NO OP
19      }      }
20    
21      public void postInvoke(CircuitBreaker circuitBreaker) throws Throwable      public void postInvoke(CircuitBreaker circuitBreaker) throws Exception
22      {      {
23          resetFailureCount();          resetFailureCount();
24      }      }
25    
26      public void onError(CircuitBreaker circuitBreaker, Throwable t) throws Throwable      public void onError(CircuitBreaker circuitBreaker, Exception t) throws Exception
27      {      {
28          int currentCount = failureCount.incrementAndGet();          int currentCount = failureCount.incrementAndGet();
29          int threshold = failureThreshold.get();          int threshold = failureThreshold.get();
# Line 31  public class ClosedState implements Circ Line 31  public class ClosedState implements Circ
31              circuitBreaker.tripBreaker();              circuitBreaker.tripBreaker();
32      }      }
33            
34      private void resetFailureCount() {      public void resetFailureCount() {
35          failureCount.set(0);          failureCount.set(0);
36      }      }
37    
38            public String getName() {
39                    return "Closed";
40            }
41            
42            public int getFailureCount() {
43                    return failureCount.get();
44            }
45            
46            public int getThreshold() {
47                    return failureThreshold.get();
48            }
49  }  }

Legend:
Removed from v.393  
changed lines
  Added in v.467

  ViewVC Help
Powered by ViewVC 1.1.20