001: /**
002: * Copyright 2003-2007 Luck Consulting Pty Ltd
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */package net.sf.ehcache.management;
016:
017: import net.sf.ehcache.CacheException;
018:
019: import javax.management.ObjectName;
020: import javax.management.MalformedObjectNameException;
021: import java.io.Serializable;
022:
023: /**
024: * A JMX MBean implementation and decorator to net.sf.ehcache.CacheConfiguration
025: *
026: * @author Greg Luck
027: * @version $Id: CacheConfiguration.java 519 2007-07-27 07:11:45Z gregluck $
028: * @since 1.3
029: */
030: public class CacheConfiguration implements CacheConfigurationMBean,
031: Serializable {
032:
033: private static final long serialVersionUID = -8944774509593267228L;
034:
035: private net.sf.ehcache.config.CacheConfiguration cacheConfiguration;
036:
037: private ObjectName objectName;
038:
039: /**
040: * Constructs using a backing CacheConfiguration
041: *
042: * @param cache
043: */
044: public CacheConfiguration(net.sf.ehcache.Ehcache cache) {
045: cacheConfiguration = cache.getCacheConfiguration();
046: objectName = createObjectName(cache.getCacheManager()
047: .toString(), cache.getName());
048: }
049:
050: /**
051: * Creates an object name using the scheme "net.sf.ehcache:type=CacheConfiguration,CacheManager=<cacheManagerName>,name=<cacheName>"
052: */
053: static ObjectName createObjectName(String cacheManagerName,
054: String cacheName) {
055: ObjectName objectName;
056: try {
057: objectName = new ObjectName(
058: "net.sf.ehcache:type=CacheConfiguration,CacheManager="
059: + cacheManagerName + ",name=" + cacheName);
060: } catch (MalformedObjectNameException e) {
061: throw new CacheException(e);
062: }
063: return objectName;
064: }
065:
066: /**
067: * Accessor
068: */
069: public String getName() {
070: return cacheConfiguration.getName();
071: }
072:
073: /**
074: * Accessor
075: */
076: public int getMaxElementsInMemory() {
077: return cacheConfiguration.getMaxElementsInMemory();
078: }
079:
080: /**
081: * Accessor
082: */
083: public int getMaxElementsOnDisk() {
084: return cacheConfiguration.getMaxElementsOnDisk();
085: }
086:
087: /**
088: * Accessor
089: * @return a String representation of the policy
090: */
091: public String getMemoryStoreEvictionPolicy() {
092: return cacheConfiguration.getMemoryStoreEvictionPolicy()
093: .toString();
094: }
095:
096: /**
097: * Accessor
098: */
099: public boolean isEternal() {
100: return cacheConfiguration.isEternal();
101: }
102:
103: /**
104: * Accessor
105: */
106: public long getTimeToIdleSeconds() {
107: return cacheConfiguration.getTimeToIdleSeconds();
108: }
109:
110: /**
111: * Accessor
112: */
113: public long getTimeToLiveSeconds() {
114: return cacheConfiguration.getTimeToLiveSeconds();
115: }
116:
117: /**
118: * Accessor
119: */
120: public boolean isOverflowToDisk() {
121: return cacheConfiguration.isOverflowToDisk();
122: }
123:
124: /**
125: * Accessor
126: */
127: public boolean isDiskPersistent() {
128: return cacheConfiguration.isDiskPersistent();
129: }
130:
131: /**
132: * Accessor
133: */
134: public int getDiskSpoolBufferSizeMB() {
135: return cacheConfiguration.getDiskSpoolBufferSizeMB();
136: }
137:
138: /**
139: * Accessor
140: */
141: public long getDiskExpiryThreadIntervalSeconds() {
142: return cacheConfiguration.getDiskExpiryThreadIntervalSeconds();
143: }
144:
145: /**
146: * @return the object name for this MBean
147: */
148: ObjectName getObjectName() {
149: return objectName;
150: }
151: }
|