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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1161 - (hide annotations) (download)
Mon Oct 4 17:36:43 2010 UTC (13 years, 8 months ago) by torben
Original Path: CircuitBreaker/src/dk/thoerup/circuitbreaker/notification/AsyncNotifier.java
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 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    
10 torben 1161 public final void sendNotification(CircuitBreaker breaker, Event evnt) {
11     ExecutorService exec = breaker.getExecutor();
12 torben 1148
13 torben 1161 exec.submit( new AsyncRunnable(breaker, evnt) );
14 torben 1148 }
15    
16 torben 1161 public abstract void sendAsync(CircuitBreaker breaker, Event evnt);
17 torben 1148
18     public class AsyncRunnable implements Runnable {
19 torben 1161 CircuitBreaker breaker;
20 torben 1148 Event evnt;
21    
22 torben 1161 public AsyncRunnable(CircuitBreaker breaker, Event evnt) {
23     this.breaker = breaker;
24 torben 1148 this.evnt = evnt;
25     }
26    
27    
28     public void run() {
29 torben 1161 sendAsync(breaker, evnt);
30 torben 1148 }
31    
32    
33     }
34    
35     }

  ViewVC Help
Powered by ViewVC 1.1.20