1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * 
4    * Copyright (C) 1999-2006, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  
11  package ch.qos.logback.classic.net;
12  
13  import ch.qos.logback.core.boolex.EvaluationException;
14  import ch.qos.logback.core.boolex.EventEvaluator;
15  import ch.qos.logback.core.spi.ContextAwareBase;
16  
17  /**
18   * A simple EventEvaluator implementation that triggers email transmission after
19   * a given number of events occur, regardless of event level.
20   * 
21   * <p>By default, the limit is 1024.
22   */
23  public class CounterBasedEvaluator extends ContextAwareBase implements EventEvaluator {
24  
25    static int DEFAULT_LIMIT = 1024;
26    int limit = DEFAULT_LIMIT;
27    int counter = 0;
28    String name;
29    boolean started;
30  
31    public boolean evaluate(Object event) throws NullPointerException,
32        EvaluationException {
33      counter++;
34  
35      if (counter == limit) {
36        counter = 0;
37        return true;
38      } else {
39        return false;
40      }
41    }
42  
43    public String getName() {
44      return name;
45    }
46  
47    public void setName(String name) {
48      this.name = name;
49    }
50  
51    public boolean isStarted() {
52      return started;
53    }
54  
55    public void start() {
56      started = true;
57    }
58  
59    public void stop() {
60      started = false;
61    }
62  
63    public int getLimit() {
64      return limit;
65    }
66  
67    public void setLimit(int limit) {
68      this.limit = limit;
69    }
70    
71    
72  }