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.access.spi;
015
016import java.util.Iterator;
017import java.util.List;
018
019import ch.qos.logback.core.Appender;
020import ch.qos.logback.core.ContextBase;
021import ch.qos.logback.core.filter.Filter;
022import ch.qos.logback.core.spi.AppenderAttachable;
023import ch.qos.logback.core.spi.AppenderAttachableImpl;
024import ch.qos.logback.core.spi.FilterAttachable;
025import ch.qos.logback.core.spi.FilterAttachableImpl;
026import ch.qos.logback.core.spi.FilterReply;
027
028/**
029 * A minimal context implementation used by certain logback-access components,
030 * mainly SocketServer.
031 * 
032 * @author Sébastien Pennec
033 */
034public class AccessContext extends ContextBase implements AppenderAttachable<IAccessEvent>, FilterAttachable<IAccessEvent> {
035
036    AppenderAttachableImpl<IAccessEvent> aai = new AppenderAttachableImpl<IAccessEvent>();
037    FilterAttachableImpl<IAccessEvent> fai = new FilterAttachableImpl<IAccessEvent>();
038
039    public void callAppenders(IAccessEvent event) {
040        aai.appendLoopOnAppenders(event);
041    }
042
043    @Override
044    public void addAppender(Appender<IAccessEvent> newAppender) {
045        aai.addAppender(newAppender);
046    }
047
048    @Override
049    public void detachAndStopAllAppenders() {
050        aai.detachAndStopAllAppenders();
051    }
052
053    @Override
054    public boolean detachAppender(Appender<IAccessEvent> appender) {
055        return aai.detachAppender(appender);
056    }
057
058    @Override
059    public boolean detachAppender(String name) {
060        return aai.detachAppender(name);
061    }
062
063    @Override
064    public Appender<IAccessEvent> getAppender(String name) {
065        return aai.getAppender(name);
066    }
067
068    @Override
069    public boolean isAttached(Appender<IAccessEvent> appender) {
070        return aai.isAttached(appender);
071    }
072
073    @Override
074    public Iterator<Appender<IAccessEvent>> iteratorForAppenders() {
075        return aai.iteratorForAppenders();
076    }
077
078    @Override
079    public void addFilter(Filter<IAccessEvent> newFilter) {
080        fai.addFilter(newFilter);
081    }
082
083    @Override
084    public void clearAllFilters() {
085        fai.clearAllFilters();
086    }
087
088    @Override
089    public List<Filter<IAccessEvent>> getCopyOfAttachedFiltersList() {
090        return fai.getCopyOfAttachedFiltersList();
091    }
092
093    @Override
094    public FilterReply getFilterChainDecision(IAccessEvent event) {
095        return fai.getFilterChainDecision(event);
096    }
097}