1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.recovery;
15
16 public class RecoveryCoordinator {
17
18 public final static long BACKOFF_COEFFICIENT_MIN = 100;
19 static long BACKOFF_COEFFICIENT_MAX = 409600;
20
21 private long backOffCoefficient = BACKOFF_COEFFICIENT_MIN;
22
23 private static long UNSET = -1;
24 private long currentTime = UNSET;
25 long next = System.currentTimeMillis()+getBackoffCoefficient();
26
27 public boolean isTooSoon() {
28 long now = getCurrentTime();
29 if(now > next) {
30 next = now + getBackoffCoefficient();
31 return false;
32 } else {
33 return true;
34 }
35 }
36
37 void setCurrentTime(long forcedTime) {
38 currentTime = forcedTime;
39 }
40
41 private long getCurrentTime() {
42 if(currentTime != UNSET) {
43 return currentTime;
44 }
45 return System.currentTimeMillis();
46 }
47
48 private long getBackoffCoefficient() {
49 long currentCoeff = backOffCoefficient;
50 if(backOffCoefficient < BACKOFF_COEFFICIENT_MAX) {
51 backOffCoefficient*=4;
52 }
53 return currentCoeff;
54 }
55 }