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

Annotation of /miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/ClosedState.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 393 - (hide annotations) (download)
Mon Oct 5 19:44:40 2009 UTC (14 years, 8 months ago) by torben
Original Path: CircuitBreaker/src/dk/thoerup/curcuitbreaker/ClosedState.java
File size: 913 byte(s)
First CircuitBreaker impl.
1 torben 393 package dk.thoerup.curcuitbreaker;
2    
3     import java.util.concurrent.atomic.*;
4    
5    
6    
7     public class ClosedState implements CircuitBreakerState {
8    
9     AtomicInteger failureCount = new AtomicInteger(0);
10     AtomicInteger failureThreshold = new AtomicInteger(0);
11    
12     public void setThreshold(int threshold) {
13     failureThreshold.set( threshold );
14     }
15    
16     public void preInvoke(CircuitBreaker circuitBreaker) throws Throwable
17     {
18     // NO OP
19     }
20    
21     public void postInvoke(CircuitBreaker circuitBreaker) throws Throwable
22     {
23     resetFailureCount();
24     }
25    
26     public void onError(CircuitBreaker circuitBreaker, Throwable t) throws Throwable
27     {
28     int currentCount = failureCount.incrementAndGet();
29     int threshold = failureThreshold.get();
30     if(currentCount >= threshold)
31     circuitBreaker.tripBreaker();
32     }
33    
34     private void resetFailureCount() {
35     failureCount.set(0);
36     }
37     }

  ViewVC Help
Powered by ViewVC 1.1.20