View Javadoc

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 chapter4.mail;
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   * 1024 events regardless of event level.
20   */
21  public class CounterBasedEvaluator extends ContextAwareBase implements EventEvaluator {
22  
23    static int LIMIT = 1024;
24    int counter = 0;
25    String name;
26    boolean started;
27  
28    public boolean evaluate(Object event) throws NullPointerException,
29        EvaluationException {
30      counter++;
31  
32      if (counter == LIMIT) {
33        counter = 0;
34  
35        return true;
36      } else {
37        return false;
38      }
39    }
40  
41    public String getName() {
42      return name;
43    }
44  
45    public void setName(String name) {
46      this.name = name;
47    }
48  
49    public boolean isStarted() {
50      return started;
51    }
52  
53    public void start() {
54      started = true;
55    }
56  
57    public void stop() {
58      started = false;
59    }
60  }