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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2448 - (show annotations) (download)
Fri Mar 20 08:52:49 2015 UTC (9 years, 2 months ago) by torben
Original Path: miscJava/CircuitBreaker/src/dk/thoerup/circuitbreaker/ClosedState.java
File size: 1136 byte(s)
move java components to java folder
1 package dk.thoerup.circuitbreaker;
2
3 import java.util.concurrent.atomic.AtomicInteger;
4
5 import dk.thoerup.circuitbreaker.config.BreakerConfig;
6
7
8
9 public final class ClosedState implements CircuitBreakerState {
10
11 final AtomicInteger failureCount = new AtomicInteger(0);
12
13
14 BreakerConfig config;
15
16 public void setThreshold(BreakerConfig config) {
17 this.config = config;
18 }
19
20 public void preInvoke(CircuitBreaker circuitBreaker) throws Exception
21 {
22 // NO OP
23 }
24
25 public void postInvoke(CircuitBreaker circuitBreaker) throws Exception
26 {
27 resetFailureCount();
28 }
29
30 public void onError(CircuitBreaker circuitBreaker, Exception t) throws Exception
31 {
32 int currentCount = failureCount.incrementAndGet();
33 int threshold = config.getTreshold();
34 if(currentCount >= threshold)
35 circuitBreaker.tripBreaker();
36 }
37
38 public void resetFailureCount() {
39 failureCount.set(0);
40 }
41
42 public String getName() {
43 return "Closed";
44 }
45
46 public int getFailureCount() {
47 return failureCount.get();
48 }
49
50 public int getThreshold() {
51 return config.getTreshold();
52 }
53 }

Properties

Name Value
svn:mergeinfo

  ViewVC Help
Powered by ViewVC 1.1.20