1 /** 2 * Logback: the reliable, generic, fast and flexible logging framework. 3 * Copyright (C) 1999-2015, 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.core; 15 16 import java.util.Map; 17 import java.util.concurrent.ExecutorService; 18 import java.util.concurrent.ScheduledExecutorService; 19 import java.util.concurrent.ScheduledFuture; 20 import java.util.concurrent.ThreadPoolExecutor; 21 22 import ch.qos.logback.core.spi.ConfigurationEvent; 23 import ch.qos.logback.core.spi.ConfigurationEventListener; 24 import ch.qos.logback.core.spi.LifeCycle; 25 import ch.qos.logback.core.spi.PropertyContainer; 26 import ch.qos.logback.core.spi.SequenceNumberGenerator; 27 import ch.qos.logback.core.status.StatusManager; 28 29 /** 30 * A context is the main anchorage point of all logback components. 31 * 32 * @author Ceki Gulcu 33 * 34 */ 35 public interface Context extends PropertyContainer { 36 37 /** 38 * Return the StatusManager instance in use. 39 * 40 * @return the {@link StatusManager} instance in use. 41 */ 42 StatusManager getStatusManager(); 43 44 /** 45 * A Context can act as a store for various objects used by LOGBack components. 46 * 47 * @return The object stored under 'key'. 48 */ 49 Object getObject(String key); 50 51 /** 52 * Store an object under 'key'. If no object can be found, null is returned. 53 * 54 * @param key 55 * @param value 56 */ 57 void putObject(String key, Object value); 58 59 /** 60 * Get all the properties for this context as a Map. Note that the returned cop 61 * might be a copy not the original. Thus, modifying the returned Map will have 62 * no effect (on the original.) 63 * 64 * @return 65 */ 66 // public Map<String, String> getPropertyMap(); 67 /** 68 * Get the property of this context. 69 */ 70 String getProperty(String key); 71 72 /** 73 * Set a property of this context. 74 */ 75 void putProperty(String key, String value); 76 77 /** 78 * Get a copy of the property map 79 * 80 * @return 81 * @since 0.9.20 82 */ 83 Map<String, String> getCopyOfPropertyMap(); 84 85 /** 86 * Contexts are named objects. 87 * 88 * @return the name for this context 89 */ 90 String getName(); 91 92 /** 93 * The name of the context can be set only once. 94 * 95 * @param name 96 */ 97 void setName(String name); 98 99 /** 100 * The time at which this context was created, expressed in millisecond elapsed 101 * since the epoch (1.1.1970). 102 * 103 * @return The time as measured when this class was created. 104 */ 105 long getBirthTime(); 106 107 /** 108 * Object used for synchronization purposes. INTENDED FOR INTERNAL USAGE. 109 */ 110 Object getConfigurationLock(); 111 112 /** 113 * Returns the ScheduledExecutorService for this context. 114 * 115 * @return ScheduledExecutorService 116 * @since 1.1.7 117 */ 118 // Apparently ScheduledThreadPoolExecutor has limitation where a task cannot be 119 // submitted from within a running task. ThreadPoolExecutor does not have this limitation. 120 // This causes tests failures in 121 // SocketReceiverTest.testDispatchEventForEnabledLevel and 122 // ServerSocketReceiverFunctionalTest.testLogEventFromClient. 123 ScheduledExecutorService getScheduledExecutorService(); 124 125 /** 126 * Every context has an ExecutorService which be invoked to execute certain 127 * tasks in a separate thread. 128 * 129 * @return the executor for this context. 130 * @since 1.0.00 (undeprecated in 1.4.7) 131 * 132 */ 133 ExecutorService getExecutorService(); 134 135 /** 136 * Return an alternate {@link ExecutorService} used for one task per thread execution. 137 * @return ExecutorService 138 */ 139 default ExecutorService getAlternateExecutorService() { 140 return getExecutorService(); 141 } 142 143 /** 144 * Register a component that participates in the context's life cycle. 145 * <p> 146 * All components registered via this method will be stopped and removed from 147 * the context when the context is reset. 148 * 149 * @param component the subject component 150 */ 151 void register(LifeCycle component); 152 153 /** 154 * Add scheduledFuture parameter to the list of known futures. 155 * 156 * @param scheduledFuture 157 */ 158 void addScheduledFuture(ScheduledFuture<?> scheduledFuture); 159 160 SequenceNumberGenerator getSequenceNumberGenerator(); 161 162 void setSequenceNumberGenerator(SequenceNumberGenerator sequenceNumberGenerator); 163 164 /** 165 * Add a {@link ConfigurationEventListener} to this context. 166 * 167 * <p>Configuration events are supposed to be rare and listeners to such events rarer still.</p> 168 * 169 * <p>The propagation of {@link ConfigurationEvent configuration events} is intended for internal testing 170 * as well as some coordination between configurators.</p> 171 * 172 * 173 * @param listener 174 * @since 1.3.6/1.4.6 175 */ 176 void addConfigurationEventListener(ConfigurationEventListener listener); 177 178 /** 179 * Fire {@link ConfigurationEvent} by invoking {@link #addConfigurationEventListener registered listeners}. 180 * 181 * <p>Note that it is the role of configurators to invoke this method as a context does 182 * not necessarily know when it is being configured.</p> 183 * 184 * @param configurationEvent 185 * @since 1.3.6/1.4.6 186 */ 187 void fireConfigurationEvent(ConfigurationEvent configurationEvent); 188 189 }