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.status.StatusManager;
24  
25  /**
26   * A context is the main anchorage point of all logback components.
27   * 
28   * @author Ceki Gulcu
29   * 
30   */
31  public interface Context extends PropertyContainer {
32  
33      /**
34       * Return the StatusManager instance in use.
35       * 
36       * @return the {@link StatusManager} instance in use.
37       */
38      StatusManager getStatusManager();
39  
40      /**
41       * A Context can act as a store for various objects used by LOGBack
42       * 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
58       * cop might be a copy not the original. Thus, modifying the returned Map will
59       * have 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       * @return
77       * @since 0.9.20
78       */
79      Map<String, String> getCopyOfPropertyMap();
80  
81      /**
82       * Contexts are named objects.
83       * 
84       * @return the name for this context
85       */
86      String getName();
87  
88      /**
89       * The name of the context can be set only once.
90       * 
91       * @param name
92       */
93      void setName(String name);
94  
95      /**
96       * The time at which this context was created, expressed in
97       * millisecond elapsed since the epoch (1.1.1970).
98       * 
99       * @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 }