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.spi.SequenceNumberGenerator; 024import ch.qos.logback.core.status.StatusManager; 025 026/** 027 * A context is the main anchorage point of all logback components. 028 * 029 * @author Ceki Gulcu 030 * 031 */ 032public interface Context extends PropertyContainer { 033 034 /** 035 * Return the StatusManager instance in use. 036 * 037 * @return the {@link StatusManager} instance in use. 038 */ 039 StatusManager getStatusManager(); 040 041 /** 042 * A Context can act as a store for various objects used by LOGBack 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 cop 058 * might be a copy not the original. Thus, modifying the returned Map will have 059 * 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 * 077 * @return 078 * @since 0.9.20 079 */ 080 Map<String, String> getCopyOfPropertyMap(); 081 082 /** 083 * Contexts are named objects. 084 * 085 * @return the name for this context 086 */ 087 String getName(); 088 089 /** 090 * The name of the context can be set only once. 091 * 092 * @param name 093 */ 094 void setName(String name); 095 096 /** 097 * The time at which this context was created, expressed in millisecond elapsed 098 * since the epoch (1.1.1970). 099 * 100 * @return The time as measured when this class was created. 101 */ 102 long getBirthTime(); 103 104 /** 105 * Object used for synchronization purposes. INTENDED FOR INTERNAL USAGE. 106 */ 107 Object getConfigurationLock(); 108 109 /** 110 * Returns the ScheduledExecutorService for this context. 111 * 112 * @return 113 * @since 1.1.7 114 */ 115 // Apparently ScheduledThreadPoolExecutor has limitation where a task cannot be 116 // submitted from 117 // within a running task. ThreadPoolExecutor does not have this limitation. 118 // This causes tests failures in 119 // SocketReceiverTest.testDispatchEventForEnabledLevel and 120 // ServerSocketReceiverFunctionalTest.testLogEventFromClient. 121 ScheduledExecutorService getScheduledExecutorService(); 122 123 /** 124 * Every context has an ExecutorService which be invoked to execute certain 125 * tasks in a separate thread. 126 * 127 * @return the executor for this context. 128 * @since 1.0.0 129 * @deprecated use {@link#getScheduledExecutorService()} instead 130 */ 131 ExecutorService getExecutorService(); 132 133 /** 134 * Register a component that participates in the context's life cycle. 135 * <p> 136 * All components registered via this method will be stopped and removed from 137 * the context when the context is reset. 138 * 139 * @param component the subject component 140 */ 141 void register(LifeCycle component); 142 143 /** 144 * Add scheduledFuture parameter to the list of known futures. 145 * 146 * @param scheduledFuture 147 */ 148 void addScheduledFuture(ScheduledFuture<?> scheduledFuture); 149 150 SequenceNumberGenerator getSequenceNumberGenerator(); 151 152 void setSequenceNumberGenerator(SequenceNumberGenerator sequenceNumberGenerator); 153 154}