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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1292 - (show annotations) (download)
Fri Apr 15 10:27:04 2011 UTC (13 years, 1 month ago) by torben
Original Path: CircuitBreaker/src/dk/thoerup/circuitbreaker/LoggingCircuitBreaker.java
File size: 1479 byte(s)
make it possible to clear the log from web UI
1 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 /* don't log retrips - they are not as interesting as trips and resets
36 @Override
37 public void retripBreaker() {
38 super.retripBreaker();
39 addEntry(Notifier.Event.BreakerRetripped);
40 }
41 */
42
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 void clearLog() {
59 synchronized(this) {
60 log.clear();
61 }
62 }
63
64 public LinkedList<LogEntry> getLog() {
65 synchronized(this) {
66 return new LinkedList<LogEntry>(log); //return a copy so caller can to whatever he wants, when he wants
67 }
68 }
69
70 }

  ViewVC Help
Powered by ViewVC 1.1.20