001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.turbo;
015
016import org.slf4j.Marker;
017
018import ch.qos.logback.classic.Level;
019import ch.qos.logback.classic.Logger;
020import ch.qos.logback.core.spi.ContextAwareBase;
021import ch.qos.logback.core.spi.FilterReply;
022import ch.qos.logback.core.spi.LifeCycle;
023
024/**
025 * TurboFilter is a specialized filter with a decide method that takes a bunch
026 * of parameters instead of a single event object. The latter is cleaner but the
027 * first is much more performant.
028 * <p>
029 * For more information about turbo filters, please refer to the online manual
030 * at http://logback.qos.ch/manual/filters.html#TurboFilter
031 * 
032 * @author Ceki Gulcu
033 */
034public abstract class TurboFilter extends ContextAwareBase implements LifeCycle {
035
036    private String name;
037    boolean start = false;
038
039    /**
040     * Make a decision based on the multiple parameters passed as arguments. The
041     * returned value should be one of <code>{@link FilterReply#DENY}</code>,
042     * <code>{@link FilterReply#NEUTRAL}</code>, or
043     * <code>{@link FilterReply#ACCEPT}</code>.
044     * 
045     * @param marker
046     * @param logger
047     * @param level
048     * @param format
049     * @param params
050     * @param t
051     * @return
052     */
053    public abstract FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params,
054            Throwable t);
055
056    public void start() {
057        this.start = true;
058    }
059
060    public boolean isStarted() {
061        return this.start;
062    }
063
064    public void stop() {
065        this.start = false;
066    }
067
068    public String getName() {
069        return name;
070    }
071
072    public void setName(String name) {
073        this.name = name;
074    }
075}