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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1288 - (hide annotations) (download)
Mon Apr 11 09:51:59 2011 UTC (13 years, 1 month ago) by torben
Original Path: CircuitBreaker/src/dk/thoerup/circuitbreaker/LoggingCircuitBreaker.java
File size: 1400 byte(s)
don't log retrips
1 torben 1285 package dk.thoerup.circuitbreaker;
2    
3     import java.util.*;
4     import dk.thoerup.circuitbreaker.notification.*;
5    
6     public class LoggingCircuitBreaker extends AccountingCircuitBreaker {
7    
8     private LinkedList<LogEntry> log = new LinkedList<LogEntry>();
9    
10     final int maxSize = 50;
11    
12     public class LogEntry {
13     public long time;
14     public Notifier.Event event;
15    
16     public LogEntry(Notifier.Event evnt) {
17     this.event = evnt;
18     this.time = System.currentTimeMillis();
19     }
20     }
21    
22    
23    
24     public LoggingCircuitBreaker(String name, int threshold, long timeoutMS) {
25     super(name, threshold, timeoutMS);
26    
27     }
28    
29     @Override
30     public void tripBreaker() {
31     super.tripBreaker();
32     addEntry(Notifier.Event.BreakerTripped);
33     }
34 torben 1288
35     /* don't log retrips - they are not as interesting as trips and resets
36 torben 1285 @Override
37     public void retripBreaker() {
38     super.retripBreaker();
39     addEntry(Notifier.Event.BreakerRetripped);
40     }
41 torben 1288 */
42 torben 1285
43     @Override
44     public void reset() {
45     super.reset();
46     addEntry(Notifier.Event.BreakerReset);
47     }
48    
49     private void addEntry(Notifier.Event event) {
50     synchronized(this) {
51     log.addFirst( new LogEntry(event) );
52     if(log.size() > maxSize) {
53     log.removeLast();
54     }
55     }
56     }
57    
58     public LinkedList<LogEntry> getLog() {
59     synchronized(this) {
60     return new LinkedList<LogEntry>(log); //return a copy so caller can to whatever he wants, when he wants
61     }
62     }
63    
64     }

  ViewVC Help
Powered by ViewVC 1.1.20