View Javadoc
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  
21  import ch.qos.logback.core.spi.LifeCycle;
22  import ch.qos.logback.core.spi.PropertyContainer;
23  import ch.qos.logback.core.spi.SequenceNumberGenerator;
24  import ch.qos.logback.core.status.StatusManager;
25  
26  /**
27   * A context is the main anchorage point of all logback components.
28   * 
29   * @author Ceki Gulcu
30   * 
31   */
32  public interface Context extends PropertyContainer {
33  
34      /**
35       * Return the StatusManager instance in use.
36       * 
37       * @return the {@link StatusManager} instance in use.
38       */
39      StatusManager getStatusManager();
40  
41      /**
42       * A Context can act as a store for various objects used by LOGBack components.
43       * 
44       * @return The object stored under 'key'.
45       */
46      Object getObject(String key);
47  
48      /**
49       * Store an object under 'key'. If no object can be found, null is returned.
50       * 
51       * @param key
52       * @param value
53       */
54      void putObject(String key, Object value);
55  
56      /**
57       * Get all the properties for this context as a Map. Note that the returned cop
58       * might be a copy not the original. Thus, modifying the returned Map will have
59       * no effect (on the original.)
60       * 
61       * @return
62       */
63      // public Map<String, String> getPropertyMap();
64      /**
65       * Get the property of this context.
66       */
67      String getProperty(String key);
68  
69      /**
70       * Set a property of this context.
71       */
72      void putProperty(String key, String value);
73  
74      /**
75       * Get a copy of the property map
76       * 
77       * @return
78       * @since 0.9.20
79       */
80      Map<String, String> getCopyOfPropertyMap();
81  
82      /**
83       * Contexts are named objects.
84       * 
85       * @return the name for this context
86       */
87      String getName();
88  
89      /**
90       * The name of the context can be set only once.
91       * 
92       * @param name
93       */
94      void setName(String name);
95  
96      /**
97       * The time at which this context was created, expressed in millisecond elapsed
98       * since the epoch (1.1.1970).
99       * 
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     void addScheduledFuture(ScheduledFuture<?> scheduledFuture);
144 
145     SequenceNumberGenerator getSequenceNumberGenerator();
146 
147     void setSequenceNumberGenerator(SequenceNumberGenerator sequenceNumberGenerator);
148 
149 }