1 |
package dk.thoerup.circuitbreaker; |
package dk.thoerup.circuitbreaker; |
2 |
|
|
3 |
|
|
4 |
|
import java.util.concurrent.ExecutorService; |
5 |
|
import java.util.concurrent.Executors; |
6 |
|
|
7 |
import dk.thoerup.circuitbreaker.notification.Notifier; |
import dk.thoerup.circuitbreaker.notification.Notifier; |
8 |
import dk.thoerup.circuitbreaker.notification.NullNotifier; |
import dk.thoerup.circuitbreaker.notification.NullNotifier; |
9 |
|
|
54 |
|
|
55 |
private String name; |
private String name; |
56 |
|
|
57 |
|
private ExecutorService executor = null; |
58 |
private Notifier notifier = new NullNotifier(); |
private Notifier notifier = new NullNotifier(); |
59 |
|
|
60 |
public CircuitBreaker(String name, int threshold, long timeoutMS) { |
public CircuitBreaker(String name, int threshold, long timeoutMS) { |
67 |
internalReset(); |
internalReset(); |
68 |
} |
} |
69 |
|
|
70 |
|
public synchronized void shutdown() { |
71 |
|
if (executor != null) { |
72 |
|
executor.shutdown(); |
73 |
|
} |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
public Object invoke(CircuitInvocation invocation) throws Exception |
public Object invoke(CircuitInvocation invocation) throws Exception |
78 |
{ |
{ |
190 |
public String getNotifierName() { |
public String getNotifierName() { |
191 |
return notifier.getClass().getName(); |
return notifier.getClass().getName(); |
192 |
} |
} |
193 |
|
|
194 |
|
public synchronized ExecutorService getExecutor() { |
195 |
|
|
196 |
|
if (executor == null) { |
197 |
|
executor = Executors.newFixedThreadPool(1); |
198 |
|
} |
199 |
|
|
200 |
|
return executor; |
201 |
|
|
202 |
|
} |
203 |
|
|
204 |
} |
} |