1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ch.qos.logback.core.util;
16
17 import java.util.concurrent.atomic.AtomicLong;
18 import java.util.function.LongBinaryOperator;
19 import java.util.function.LongUnaryOperator;
20 import java.util.function.UnaryOperator;
21
22
23
24
25
26
27 public class SimpleInvocationGate implements InvocationGate {
28
29
30
31 AtomicLong atomicNext = new AtomicLong(0);
32 final Duration increment;
33
34
35 final public static Duration DEFAULT_INCREMENT = Duration.buildBySeconds(60);
36
37 public SimpleInvocationGate() {
38 this(DEFAULT_INCREMENT);
39 }
40
41 public SimpleInvocationGate(Duration anIncrement) {
42 this.increment = anIncrement;
43 }
44
45 @Override
46 public boolean isTooSoon(long currentTime) {
47 if (currentTime == -1)
48 return false;
49
50 long localNext = atomicNext.get();
51 if (currentTime >= localNext) {
52 long next2 = currentTime+increment.getMilliseconds();
53
54 boolean success = atomicNext.compareAndSet(localNext, next2);
55
56
57 return !success;
58 } else {
59 return true;
60 }
61
62 }
63
64
65 }
66
67
68
69
70
71
72
73
74
75
76
77
78
79