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.core;
015
016import java.util.Map;
017import java.util.concurrent.ExecutorService;
018import java.util.concurrent.ScheduledExecutorService;
019import java.util.concurrent.ScheduledFuture;
020
021import ch.qos.logback.core.spi.LifeCycle;
022import ch.qos.logback.core.spi.PropertyContainer;
023import ch.qos.logback.core.status.StatusManager;
024
025/**
026 * A context is the main anchorage point of all logback components.
027 * 
028 * @author Ceki Gulcu
029 * 
030 */
031public interface Context extends PropertyContainer {
032
033    /**
034     * Return the StatusManager instance in use.
035     * 
036     * @return the {@link StatusManager} instance in use.
037     */
038    StatusManager getStatusManager();
039
040    /**
041     * A Context can act as a store for various objects used by LOGBack
042     * components.
043     * 
044     * @return The object stored under 'key'.
045     */
046    Object getObject(String key);
047
048    /**
049     * Store an object under 'key'. If no object can be found, null is returned.
050     * 
051     * @param key
052     * @param value
053     */
054    void putObject(String key, Object value);
055
056    /**
057     * Get all the properties for this context as a Map. Note that the returned
058     * cop might be a copy not the original. Thus, modifying the returned Map will
059     * have no effect (on the original.)
060     * 
061     * @return
062     */
063    // public Map<String, String> getPropertyMap();
064    /**
065     * Get the property of this context.
066     */
067    String getProperty(String key);
068
069    /**
070     * Set a property of this context.
071     */
072    void putProperty(String key, String value);
073
074    /**
075     * Get a copy of the property map
076     * @return
077     * @since 0.9.20
078     */
079    Map<String, String> getCopyOfPropertyMap();
080
081    /**
082     * Contexts are named objects.
083     * 
084     * @return the name for this context
085     */
086    String getName();
087
088    /**
089     * The name of the context can be set only once.
090     * 
091     * @param name
092     */
093    void setName(String name);
094
095    /**
096     * The time at which this context was created, expressed in
097     * millisecond elapsed since the epoch (1.1.1970).
098     * 
099     * @return The time as measured when this class was created.
100     */
101    long getBirthTime();
102
103    /**
104     * Object used for synchronization purposes. 
105     * INTENDED FOR INTERNAL USAGE.
106     */
107    Object getConfigurationLock();
108
109
110    /**
111     * Returns the ScheduledExecutorService for this context.
112     * @return
113     * @since 1.1.7
114     */
115    // Apparently ScheduledThreadPoolExecutor has limitation where a task cannot be submitted from 
116    // within a running task. ThreadPoolExecutor does not have this limitation.
117    // This causes tests failures in SocketReceiverTest.testDispatchEventForEnabledLevel and
118    // ServerSocketReceiverFunctionalTest.testLogEventFromClient.
119    ScheduledExecutorService getScheduledExecutorService();
120
121    /**
122     * Every context has an ExecutorService which be invoked to execute certain
123     * tasks in a separate thread.
124     *
125     * @return the executor for this context.
126     * @since 1.0.0
127     * @deprecated use {@link#getScheduledExecutorService()} instead
128     */
129    ExecutorService getExecutorService();
130    /**
131     * Register a component that participates in the context's life cycle.
132     * <p>
133     * All components registered via this method will be stopped and removed
134     * from the context when the context is reset.
135     * 
136     * @param component the subject component
137     */
138    void register(LifeCycle component);
139
140    void addScheduledFuture(ScheduledFuture<?> scheduledFuture);
141
142}