/[projects]/CircuitBreaker/src/dk/thoerup/circuitbreaker/notification/AsyncNotifier.java
ViewVC logotype

Contents of /CircuitBreaker/src/dk/thoerup/circuitbreaker/notification/AsyncNotifier.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1161 - (show annotations) (download)
Mon Oct 4 17:36:43 2010 UTC (13 years, 7 months ago) by torben
File size: 738 byte(s)
If the Notifier gets a reference to the CircuitBreaker itself instead of the circuitbreaker's name then the same notifier instance can easily 
be shared across several circuitbreakers
1 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
10 public final void sendNotification(CircuitBreaker breaker, Event evnt) {
11 ExecutorService exec = breaker.getExecutor();
12
13 exec.submit( new AsyncRunnable(breaker, evnt) );
14 }
15
16 public abstract void sendAsync(CircuitBreaker breaker, Event evnt);
17
18 public class AsyncRunnable implements Runnable {
19 CircuitBreaker breaker;
20 Event evnt;
21
22 public AsyncRunnable(CircuitBreaker breaker, Event evnt) {
23 this.breaker = breaker;
24 this.evnt = evnt;
25 }
26
27
28 public void run() {
29 sendAsync(breaker, evnt);
30 }
31
32
33 }
34
35 }

  ViewVC Help
Powered by ViewVC 1.1.20