View Javadoc

1   /**
2    *  Copyright 2003-2007 Greg Luck
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 net.sf.ehcache.CacheException;
20  
21  import javax.management.ObjectName;
22  import javax.management.MalformedObjectNameException;
23  import java.io.Serializable;
24  
25  
26  /**
27   * A JMX MBean implementation and decorator to net.sf.ehcache.CacheConfiguration
28   *
29   * @author Greg Luck
30   * @version $Id: CacheConfiguration.java 512 2007-07-10 09:18:45Z gregluck $
31   * @since 1.3
32   */
33  public class CacheConfiguration implements CacheConfigurationMBean, Serializable {
34  
35      private static final long serialVersionUID = -8944774509593267228L;
36  
37      private net.sf.ehcache.config.CacheConfiguration cacheConfiguration;
38  
39      private ObjectName objectName;
40  
41      /**
42       * Constructs using a backing CacheConfiguration
43       *
44       * @param cache
45       */
46      public CacheConfiguration(net.sf.ehcache.Ehcache cache) {
47          cacheConfiguration = cache.getCacheConfiguration();
48          objectName = createObjectName(cache.getCacheManager().toString(), cache.getName());
49      }
50  
51      /**
52       * Creates an object name using the scheme "net.sf.ehcache:type=CacheConfiguration,CacheManager=<cacheManagerName>,name=<cacheName>"
53       */
54      static ObjectName createObjectName(String cacheManagerName, String cacheName) {
55          ObjectName objectName;
56          try {
57              objectName = new ObjectName("net.sf.ehcache:type=CacheConfiguration,CacheManager="
58                      + cacheManagerName + ",name=" + cacheName);
59          } catch (MalformedObjectNameException e) {
60              throw new CacheException(e);
61          }
62          return objectName;
63      }
64  
65  
66      /**
67       * Accessor
68       */
69      public String getName() {
70          return cacheConfiguration.getName();
71      }
72  
73  
74      /**
75       * Accessor
76       */
77      public int getMaxElementsInMemory() {
78          return cacheConfiguration.getMaxElementsInMemory();
79      }
80  
81      /**
82       * Accessor
83       */
84      public int getMaxElementsOnDisk() {
85          return cacheConfiguration.getMaxElementsOnDisk();
86      }
87  
88      /**
89       * Accessor
90       * @return a String representation of the policy
91       */
92      public String getMemoryStoreEvictionPolicy() {
93          return cacheConfiguration.getMemoryStoreEvictionPolicy().toString();
94      }
95  
96      /**
97       * Accessor
98       */
99      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     /**
147      * @return the object name for this MBean
148      */
149     ObjectName getObjectName() {
150         return objectName;
151     }
152 }