1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core;
15
16 import java.util.HashMap;
17 import java.util.Map;
18 import java.util.concurrent.*;
19
20 import ch.qos.logback.core.status.StatusManager;
21
22 import static ch.qos.logback.core.CoreConstants.CONTEXT_NAME_KEY;
23
24 public class ContextBase implements Context {
25
26 private long birthTime = System.currentTimeMillis();
27
28 private String name;
29 private StatusManager sm = new BasicStatusManager();
30
31
32
33 Map<String, String> propertyMap = new HashMap<String, String>();
34 Map<String, Object> objectMap = new HashMap<String, Object>();
35
36 Object configurationLock = new Object();
37
38
39 ExecutorService executorService = new ThreadPoolExecutor(0, 2,
40 0L, TimeUnit.MILLISECONDS,
41 new LinkedBlockingQueue<Runnable>());
42
43 public StatusManager getStatusManager() {
44 return sm;
45 }
46
47
48
49
50
51
52
53
54
55
56
57 public void setStatusManager(StatusManager statusManager) {
58
59 if (sm == null) {
60 throw new IllegalArgumentException("null StatusManager not allowed");
61 }
62 this.sm = statusManager;
63 }
64
65 public Map<String, String> getCopyOfPropertyMap() {
66 return new HashMap<String, String>(propertyMap);
67 }
68
69 public void putProperty(String key, String val) {
70 this.propertyMap.put(key, val);
71 }
72
73
74
75
76
77
78
79
80 public String getProperty(String key) {
81 if (CONTEXT_NAME_KEY.equals(key))
82 return getName();
83
84 return (String) this.propertyMap.get(key);
85 }
86
87 public Object getObject(String key) {
88 return objectMap.get(key);
89 }
90
91 public void putObject(String key, Object value) {
92 objectMap.put(key, value);
93 }
94
95 public String getName() {
96 return name;
97 }
98
99
100
101
102 public void reset() {
103 propertyMap.clear();
104 objectMap.clear();
105 }
106
107
108
109
110
111
112
113
114 public void setName(String name) throws IllegalStateException {
115 if (name != null && name.equals(this.name)) {
116 return;
117 }
118 if (this.name == null
119 || CoreConstants.DEFAULT_CONTEXT_NAME.equals(this.name)) {
120 this.name = name;
121 } else {
122 throw new IllegalStateException("Context has been already given a name");
123 }
124 }
125
126 public long getBirthTime() {
127 return birthTime;
128 }
129
130 public Object getConfigurationLock() {
131 return configurationLock;
132 }
133
134 public ExecutorService getExecutorService() {
135 return executorService;
136 }
137 }