1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.management;
18
19 import java.io.Serializable;
20
21 import javax.management.MalformedObjectNameException;
22 import javax.management.ObjectName;
23
24 import net.sf.ehcache.CacheException;
25 import net.sf.ehcache.config.TerracottaConfiguration.Consistency;
26 import net.sf.ehcache.hibernate.management.impl.EhcacheHibernateMbeanNames;
27
28
29 /***
30 * A JMX MBean implementation and decorator to net.sf.ehcache.CacheConfiguration
31 *
32 * @author Greg Luck
33 * @version $Id: CacheConfiguration.html 13146 2011-08-01 17:12:39Z oletizi $
34 * @since 1.3
35 */
36 public class CacheConfiguration implements CacheConfigurationMBean, Serializable {
37
38 private static final long serialVersionUID = -8944774509593267228L;
39
40 private final transient net.sf.ehcache.config.CacheConfiguration cacheConfiguration;
41
42 private final ObjectName objectName;
43
44 /***
45 * Constructs using a backing CacheConfiguration
46 *
47 * @param cache
48 */
49 public CacheConfiguration(net.sf.ehcache.Ehcache cache) {
50 cacheConfiguration = cache.getCacheConfiguration();
51 objectName = createObjectName(cache.getCacheManager().toString(), cache.getName());
52 }
53
54 /***
55 * Creates an object name using the scheme "net.sf.ehcache:type=CacheConfiguration,CacheManager=<cacheManagerName>,name=<cacheName>"
56 */
57 static ObjectName createObjectName(String cacheManagerName, String cacheName) {
58 ObjectName objectName;
59 try {
60 objectName = new ObjectName("net.sf.ehcache:type=CacheConfiguration,CacheManager=" + cacheManagerName + ",name="
61 + EhcacheHibernateMbeanNames.mbeanSafe(cacheName));
62 } catch (MalformedObjectNameException e) {
63 throw new CacheException(e);
64 }
65 return objectName;
66 }
67
68 /***
69 * Accessor
70 */
71 public String getName() {
72 return cacheConfiguration.getName();
73 }
74
75 /***
76 * Accessor
77 */
78 public boolean isLoggingEnabled() {
79 return cacheConfiguration.getLogging();
80 }
81
82 /***
83 * setLoggingEnabled
84 *
85 * @param enable
86 */
87 public void setLoggingEnabled(boolean enable) {
88 cacheConfiguration.setLogging(enable);
89 }
90 /***
91 * Accessor
92 *
93 * @deprecated use {@link #getMaxEntriesLocalHeap()}
94 */
95 @Deprecated
96 public int getMaxElementsInMemory() {
97 return cacheConfiguration.getMaxElementsInMemory();
98 }
99
100 /***
101 * setMaxElementsInMemory
102 *
103 * @param maxElements
104 * @deprecated use {@link #setMaxEntriesLocalHeap(long)}
105 */
106 @Deprecated
107 public void setMaxElementsInMemory(int maxElements) {
108 cacheConfiguration.setMaxElementsInMemory(maxElements);
109 }
110
111 /***
112 * Accessor
113 *
114 * @deprecated use {@link #getMaxEntriesLocalDisk()}
115 */
116 @Deprecated
117 public int getMaxElementsOnDisk() {
118 return cacheConfiguration.getMaxElementsOnDisk();
119 }
120
121 /***
122 * setMaxElementsOnDisk
123 *
124 * @param maxElements
125 * @deprecated use {@link #setMaxEntriesLocalDisk(long)}
126 */
127 @Deprecated
128 public void setMaxElementsOnDisk(int maxElements) {
129 cacheConfiguration.setMaxElementsOnDisk(maxElements);
130 }
131
132 /***
133 * Accessor
134 * @return a String representation of the policy
135 */
136 public String getMemoryStoreEvictionPolicy() {
137 return cacheConfiguration.getMemoryStoreEvictionPolicy().toString();
138 }
139
140 /***
141 * setMemoryStoreEvictionPolicy
142 *
143 * @param memoryStoreEvictionPolicy
144 */
145 public void setMemoryStoreEvictionPolicy(String memoryStoreEvictionPolicy) {
146 cacheConfiguration.setMemoryStoreEvictionPolicy(memoryStoreEvictionPolicy);
147 }
148
149 /***
150 * Accessor
151 */
152 public boolean isEternal() {
153 return cacheConfiguration.isEternal();
154 }
155
156 /***
157 * setEternal
158 *
159 * @param eternal
160 */
161 public void setEternal(boolean eternal) {
162 cacheConfiguration.setEternal(eternal);
163 }
164
165 /***
166 * Accessor
167 */
168 public long getTimeToIdleSeconds() {
169 return cacheConfiguration.getTimeToIdleSeconds();
170 }
171
172 /***
173 * setTimeToIdleSeconds
174 *
175 * @param tti
176 */
177 public void setTimeToIdleSeconds(long tti) {
178 cacheConfiguration.setTimeToIdleSeconds(tti);
179 }
180
181 /***
182 * Accessor
183 */
184 public long getTimeToLiveSeconds() {
185 return cacheConfiguration.getTimeToLiveSeconds();
186 }
187
188 /***
189 * setTimeToLiveSeconds
190 *
191 * @param ttl
192 */
193 public void setTimeToLiveSeconds(long ttl) {
194 cacheConfiguration.setTimeToLiveSeconds(ttl);
195 }
196
197 /***
198 * Accessor
199 */
200 public boolean isOverflowToDisk() {
201 return cacheConfiguration.isOverflowToDisk();
202 }
203
204 /***
205 * setOverflowToDisk
206 *
207 * @param overflowToDisk
208 */
209 public void setOverflowToDisk(boolean overflowToDisk) {
210 cacheConfiguration.setOverflowToDisk(overflowToDisk);
211 }
212
213 /***
214 * Accessor
215 */
216 public boolean isDiskPersistent() {
217 return cacheConfiguration.isDiskPersistent();
218 }
219
220 /***
221 * setDiskPersistent
222 *
223 * @param diskPersistent
224 */
225 public void setDiskPersistent(boolean diskPersistent) {
226 cacheConfiguration.setDiskPersistent(diskPersistent);
227 }
228
229 /***
230 * Accessor
231 */
232 public int getDiskSpoolBufferSizeMB() {
233 return cacheConfiguration.getDiskSpoolBufferSizeMB();
234 }
235
236 /***
237 * setDiskSpoolBufferSizeMB
238 *
239 * @param diskSpoolBufferSizeMB
240 */
241 public void setDiskSpoolBufferSizeMB(int diskSpoolBufferSizeMB) {
242 cacheConfiguration.setDiskSpoolBufferSizeMB(diskSpoolBufferSizeMB);
243 }
244
245 /***
246 * Accessor
247 */
248 public long getDiskExpiryThreadIntervalSeconds() {
249 return cacheConfiguration.getDiskExpiryThreadIntervalSeconds();
250 }
251
252 /***
253 * setDiskExpiryThreadIntervalSeconds
254 *
255 * @param diskExpiryThreadIntervalSeconds
256 */
257 public final void setDiskExpiryThreadIntervalSeconds(long diskExpiryThreadIntervalSeconds) {
258 cacheConfiguration.setDiskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds);
259 }
260
261 /***
262 * Accessor
263 */
264 public boolean isTerracottaClustered() {
265 return cacheConfiguration.isTerracottaClustered();
266 }
267
268 /***
269 * Accessor
270 */
271 public String getTerracottaConsistency() {
272 Consistency consistency = cacheConfiguration.getTerracottaConsistency();
273 return consistency != null ? consistency.name() : "na";
274 }
275
276 /***
277 * @return the object name for this MBean
278 */
279 ObjectName getObjectName() {
280 return objectName;
281 }
282
283 /***
284 * Accessor
285 */
286 public boolean isOverflowToOffHeap() {
287 return cacheConfiguration.isOverflowToOffHeap();
288 }
289
290 /***
291 * Accessor
292 * @deprecated use {@link #getMaxBytesLocalOffHeap()}
293 */
294 @Deprecated
295 public long getMaxMemoryOffHeapInBytes() {
296 return cacheConfiguration.getMaxMemoryOffHeapInBytes();
297 }
298
299 /***
300 * Maximum number of entries that may be stored in the local disk store.
301 */
302 public long getMaxEntriesLocalDisk() {
303 return cacheConfiguration.getMaxEntriesLocalDisk();
304 }
305
306 /***
307 * Maximum number of entries that may be stored in local heap memory store.
308 */
309 public long getMaxEntriesLocalHeap() {
310 return cacheConfiguration.getMaxEntriesLocalHeap();
311 }
312
313 /***
314 * Maximum number of entries that may be stores in the local disk store.
315 */
316 public void setMaxEntriesLocalDisk(long maxEntries) {
317 cacheConfiguration.setMaxEntriesLocalDisk(maxEntries);
318 }
319
320 /***
321 * Maximum number of entries that may be stored in local heap memory store.
322 */
323 public void setMaxEntriesLocalHeap(long maxEntries) {
324 cacheConfiguration.setMaxEntriesLocalHeap(maxEntries);
325 }
326
327 /***
328 * Maximum number of bytes that may be stored in the local disk store.
329 */
330 public long getMaxBytesLocalDisk() {
331 return cacheConfiguration.getMaxBytesLocalDisk();
332 }
333
334 /***
335 * Maximum number of bytes that may be stored in local heap memory store.
336 */
337 public long getMaxBytesLocalHeap() {
338 return cacheConfiguration.getMaxBytesLocalHeap();
339 }
340
341 /***
342 * Maximum number of bytes that may be stored in local off-heap memory store.
343 */
344 public long getMaxBytesLocalOffHeap() {
345 return cacheConfiguration.getMaxBytesLocalOffHeap();
346 }
347 }