1 package org.apache.commons.jcs3;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Properties;
23
24 import org.apache.commons.jcs3.access.CacheAccess;
25 import org.apache.commons.jcs3.access.GroupCacheAccess;
26 import org.apache.commons.jcs3.access.exception.CacheException;
27 import org.apache.commons.jcs3.engine.behavior.ICompositeCacheAttributes;
28 import org.apache.commons.jcs3.engine.behavior.IElementAttributes;
29 import org.apache.commons.jcs3.engine.control.CompositeCache;
30 import org.apache.commons.jcs3.engine.control.CompositeCacheManager;
31 import org.apache.commons.jcs3.engine.control.group.GroupAttrName;
32 import org.apache.commons.jcs3.log.LogManager;
33
34
35
36
37
38
39
40
41 public abstract class JCS
42 {
43
44 private static String configFilename;
45
46
47 private static Properties configProps;
48
49
50 private static CompositeCacheManager cacheMgr;
51
52
53
54
55
56
57
58 public static void setConfigFilename( final String configFilename )
59 {
60 JCS.configFilename = configFilename;
61 }
62
63
64
65
66
67
68
69 public static void setConfigProperties( final Properties configProps )
70 {
71 JCS.configProps = configProps;
72 }
73
74
75
76
77
78
79
80
81 public static void setLogSystem(final String logSystem)
82 {
83 LogManager.setLogSystem(logSystem);
84 }
85
86
87
88
89 public static void shutdown()
90 {
91 synchronized ( JCS.class )
92 {
93 if ( cacheMgr != null && cacheMgr.isInitialized())
94 {
95 cacheMgr.shutDown();
96 }
97
98 cacheMgr = null;
99 }
100 }
101
102
103
104
105
106
107
108 private static CompositeCacheManager getCacheManager() throws CacheException
109 {
110 synchronized ( JCS.class )
111 {
112 if ( cacheMgr == null || !cacheMgr.isInitialized())
113 {
114 if ( configProps != null )
115 {
116 cacheMgr = CompositeCacheManager.getUnconfiguredInstance();
117 cacheMgr.configure( configProps );
118 }
119 else if ( configFilename != null )
120 {
121 cacheMgr = CompositeCacheManager.getUnconfiguredInstance();
122 cacheMgr.configure( configFilename );
123 }
124 else
125 {
126 cacheMgr = CompositeCacheManager.getInstance();
127 }
128 }
129
130 return cacheMgr;
131 }
132 }
133
134
135
136
137
138
139
140
141 public static <K, V> CacheAccess<K, V> getInstance( final String region )
142 throws CacheException
143 {
144 final CompositeCache<K, V> cache = getCacheManager().getCache( region );
145 return new CacheAccess<>( cache );
146 }
147
148
149
150
151
152
153
154
155
156 public static <K, V> CacheAccess<K, V> getInstance( final String region, final ICompositeCacheAttributes icca )
157 throws CacheException
158 {
159 final CompositeCache<K, V> cache = getCacheManager().getCache( region, icca );
160 return new CacheAccess<>( cache );
161 }
162
163
164
165
166
167
168
169
170
171
172 public static <K, V> CacheAccess<K, V> getInstance( final String region, final ICompositeCacheAttributes icca, final IElementAttributes eattr )
173 throws CacheException
174 {
175 final CompositeCache<K, V> cache = getCacheManager().getCache( region, icca, eattr );
176 return new CacheAccess<>( cache );
177 }
178
179
180
181
182
183
184
185
186 public static <K, V> GroupCacheAccess<K, V> getGroupCacheInstance( final String region )
187 throws CacheException
188 {
189 final CompositeCache<GroupAttrName<K>, V> cache = getCacheManager().getCache( region );
190 return new GroupCacheAccess<>( cache );
191 }
192
193
194
195
196
197
198
199
200
201 public static <K, V> GroupCacheAccess<K, V> getGroupCacheInstance( final String region, final ICompositeCacheAttributes icca )
202 throws CacheException
203 {
204 final CompositeCache<GroupAttrName<K>, V> cache = getCacheManager().getCache( region, icca );
205 return new GroupCacheAccess<>( cache );
206 }
207
208
209
210
211
212
213
214
215
216
217 public static <K, V> GroupCacheAccess<K, V> getGroupCacheInstance( final String region, final ICompositeCacheAttributes icca, final IElementAttributes eattr )
218 throws CacheException
219 {
220 final CompositeCache<GroupAttrName<K>, V> cache = getCacheManager().getCache( region, icca, eattr );
221 return new GroupCacheAccess<>( cache );
222 }
223 }