/[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 1285 - (hide annotations) (download)
Mon Apr 11 07:52:15 2011 UTC (13 years, 2 months ago) by torben
Original Path: CircuitBreaker/src/dk/thoerup/circuitbreaker/LoggingCircuitBreaker.java
File size: 1325 byte(s)
add LoggingCircuitBreaker
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    
35     @Override
36     public void retripBreaker() {
37     super.retripBreaker();
38     addEntry(Notifier.Event.BreakerRetripped);
39     }
40    
41     @Override
42     public void reset() {
43     super.reset();
44     addEntry(Notifier.Event.BreakerReset);
45     }
46    
47     private void addEntry(Notifier.Event event) {
48     synchronized(this) {
49     log.addFirst( new LogEntry(event) );
50     if(log.size() > maxSize) {
51     log.removeLast();
52     }
53     }
54     }
55    
56     public LinkedList<LogEntry> getLog() {
57     synchronized(this) {
58     return new LinkedList<LogEntry>(log); //return a copy so caller can to whatever he wants, when he wants
59     }
60     }
61    
62     }

  ViewVC Help
Powered by ViewVC 1.1.20