1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.blackbox.net;
15
16 import ch.qos.logback.core.boolex.EvaluationException;
17 import ch.qos.logback.core.boolex.EventEvaluator;
18 import ch.qos.logback.core.spi.ContextAwareBase;
19
20
21
22
23
24
25
26
27 public class CounterBasedEvaluator extends ContextAwareBase implements EventEvaluator<Object> {
28
29 static int DEFAULT_LIMIT = 1024;
30 int limit = DEFAULT_LIMIT;
31 int counter = 0;
32 String name;
33 boolean started;
34
35 public boolean evaluate(Object event) throws NullPointerException, EvaluationException {
36 counter++;
37
38 if (counter == limit) {
39 counter = 0;
40 return true;
41 } else {
42 return false;
43 }
44 }
45
46 public String getName() {
47 return name;
48 }
49
50 public void setName(String name) {
51 this.name = name;
52 }
53
54 public boolean isStarted() {
55 return started;
56 }
57
58 public void start() {
59 started = true;
60 }
61
62 public void stop() {
63 started = false;
64 }
65
66 public int getLimit() {
67 return limit;
68 }
69
70 public void setLimit(int limit) {
71 this.limit = limit;
72 }
73
74 }