1 /**
2 * Logback: the reliable, generic, fast and flexible logging framework.
3 * Copyright (C) 1999-2013, QOS.ch. All rights reserved.
4 *
5 * This program and the accompanying materials are dual-licensed under
6 * either the terms of the Eclipse Public License v1.0 as published by
7 * the Eclipse Foundation
8 *
9 * or (per the licensee's choosing)
10 *
11 * under the terms of the GNU Lesser General Public License version 2.1
12 * as published by the Free Software Foundation.
13 */
14 package ch.qos.logback.classic.spi;
15
16 import java.util.concurrent.CopyOnWriteArrayList;
17
18 import org.slf4j.Marker;
19
20 import ch.qos.logback.classic.Level;
21 import ch.qos.logback.classic.Logger;
22 import ch.qos.logback.classic.turbo.TurboFilter;
23 import ch.qos.logback.core.spi.FilterReply;
24
25 /**
26 * Implementation of TurboFilterAttachable.
27 *
28 * @author Ceki Gülcü
29 */
30 final public class TurboFilterList extends CopyOnWriteArrayList<TurboFilter> {
31
32 private static final long serialVersionUID = 1L;
33
34 /**
35 * Loop through the filters in the chain. As soon as a filter decides on
36 * ACCEPT or DENY, then that value is returned. If all of the filters return
37 * NEUTRAL, then NEUTRAL is returned.
38 */
39 public FilterReply getTurboFilterChainDecision(final Marker marker,
40 final Logger logger, final Level level, final String format,
41 final Object[] params, final Throwable t) {
42
43
44 final int size = size();
45 // if (size == 0) {
46 // return FilterReply.NEUTRAL;
47 // }
48 if (size == 1) {
49 try {
50 TurboFilter tf = get(0);
51 return tf.decide(marker, logger, level, format, params, t);
52 } catch (IndexOutOfBoundsException iobe) {
53 return FilterReply.NEUTRAL;
54 }
55 }
56
57 Object[] tfa = toArray();
58 final int len = tfa.length;
59 for (int i = 0; i < len; i++) {
60 //for (TurboFilter tf : this) {
61 final TurboFilter tf = (TurboFilter) tfa[i];
62 final FilterReply r = tf.decide(marker, logger, level, format, params, t);
63 if (r == FilterReply.DENY || r == FilterReply.ACCEPT) {
64 return r;
65 }
66 }
67 return FilterReply.NEUTRAL;
68 }
69
70 // public boolean remove(TurboFilter turboFilter) {
71 // return tfList.remove(turboFilter);
72 // }
73 //
74 // public TurboFilter remove(int index) {
75 // return tfList.remove(index);
76 // }
77 //
78 // final public int size() {
79 // return tfList.size();
80 // }
81
82 }