1 |
torben |
1148 |
package dk.thoerup.circuitbreaker.notification; |
2 |
|
|
|
3 |
|
|
import java.util.concurrent.ExecutorService; |
4 |
|
|
|
5 |
|
|
import dk.thoerup.circuitbreaker.CircuitBreaker; |
6 |
|
|
|
7 |
|
|
public abstract class AsyncNotifier implements Notifier { |
8 |
|
|
|
9 |
|
|
CircuitBreaker cb; |
10 |
|
|
|
11 |
|
|
public AsyncNotifier(CircuitBreaker cb) { |
12 |
|
|
this.cb = cb; |
13 |
|
|
} |
14 |
|
|
|
15 |
|
|
public final void sendNotification(String breakerName, Event evnt) { |
16 |
|
|
ExecutorService exec = cb.getExecutor(); |
17 |
|
|
|
18 |
|
|
exec.submit( new AsyncRunnable(breakerName, evnt) ); |
19 |
|
|
} |
20 |
|
|
|
21 |
|
|
public abstract void sendAsync(String breakerName, Event evnt); |
22 |
|
|
|
23 |
|
|
public class AsyncRunnable implements Runnable { |
24 |
|
|
String breakerName; |
25 |
|
|
Event evnt; |
26 |
|
|
|
27 |
|
|
public AsyncRunnable(String breakerName, Event evnt) { |
28 |
|
|
this.breakerName = breakerName; |
29 |
|
|
this.evnt = evnt; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
public void run() { |
34 |
|
|
sendAsync(breakerName, evnt); |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
} |