3 |
import java.util.Date; |
import java.util.Date; |
4 |
import java.util.LinkedList; |
import java.util.LinkedList; |
5 |
|
|
6 |
|
import dk.thoerup.circuitbreaker.config.BreakerConfig; |
7 |
import dk.thoerup.circuitbreaker.notification.Notifier; |
import dk.thoerup.circuitbreaker.notification.Notifier; |
8 |
|
|
9 |
public class LoggingCircuitBreaker extends AccountingCircuitBreaker { |
public class LoggingCircuitBreaker extends AccountingCircuitBreaker { |
15 |
public class LogEntry { |
public class LogEntry { |
16 |
public long time; |
public long time; |
17 |
public Notifier.Event event; |
public Notifier.Event event; |
18 |
public int count = 0; |
public int count = 1; |
19 |
|
|
20 |
public LogEntry(Notifier.Event evnt) { |
public LogEntry(Notifier.Event evnt) { |
21 |
this.event = evnt; |
this.event = evnt; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
public LoggingCircuitBreaker(String name, int threshold, long timeoutMS) { |
public LoggingCircuitBreaker(String name, BreakerConfig config) { |
46 |
super(name, threshold, timeoutMS); |
super(name, config); |
47 |
|
|
48 |
} |
} |
49 |
|
|
69 |
|
|
70 |
private void addEntry(Notifier.Event event) { |
private void addEntry(Notifier.Event event) { |
71 |
synchronized(this) { |
synchronized(this) { |
72 |
|
|
73 |
if (log.getFirst().event != Notifier.Event.BreakerRetripped) { |
if (event != Notifier.Event.BreakerRetripped ) { |
74 |
|
log.addFirst( new LogEntry(event) ); //trip and reset are added unconditionally |
|
log.addFirst( new LogEntry(event) ); |
|
|
if(log.size() > maxSize) { |
|
|
log.removeLast(); |
|
|
} |
|
|
|
|
75 |
} else { |
} else { |
76 |
log.getFirst().newRetrip(); |
|
77 |
|
if (log.size() == 0 || log.getFirst().event != Notifier.Event.BreakerRetripped) { |
78 |
|
log.addFirst( new LogEntry(event) ); |
79 |
|
} else { |
80 |
|
log.getFirst().newRetrip(); |
81 |
|
} |
82 |
|
} |
83 |
|
|
84 |
|
if(log.size() > maxSize) { |
85 |
|
log.removeLast(); |
86 |
} |
} |
87 |
|
|
88 |
} |
} |
89 |
} |
} |
90 |
|
|