2
* Copyright 2003-2010 Terracotta, Inc.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
package net.sf.ehcache.management;
19
import net.sf.ehcache.CacheException;
20
import net.sf.ehcache.hibernate.management.impl.EhcacheHibernateMbeanNames;
22
import javax.management.MalformedObjectNameException;
23
import javax.management.ObjectName;
24
import java.util.ArrayList;
25
import java.util.List;
28
* An MBean implementation for those attributes and operations we wish to expose on net.sf.ehcache.CacheManager.
29
* This class is not Serializable because it is an adapter around a net.sf.ehcache.CacheManager, which is itself
32
* @version $Id: CacheManager.java 2174 2010-04-07 20:58:22Z gkeim $
35
public class CacheManager implements CacheManagerMBean {
37
private net.sf.ehcache.CacheManager cacheManager;
38
private ObjectName objectName;
41
* Create a management CacheManager
43
* @throws net.sf.ehcache.CacheException
45
public CacheManager(net.sf.ehcache.CacheManager cacheManager) throws CacheException {
46
this.cacheManager = cacheManager;
47
objectName = createObjectName(cacheManager);
51
* Creates an object name using the scheme "net.sf.ehcache:type=CacheManager,name=<cacheManagerName>"
53
static ObjectName createObjectName(net.sf.ehcache.CacheManager cacheManager) {
54
ObjectName objectName;
56
objectName = new ObjectName("net.sf.ehcache:type=CacheManager,name="
57
+ EhcacheHibernateMbeanNames.mbeanSafe(cacheManager.getName()));
58
} catch (MalformedObjectNameException e) {
59
throw new CacheException(e);
65
* Gets the status attribute of the Ehcache
67
* @return The status value, as a String from the Status enum class
69
public String getStatus() {
70
return cacheManager.getStatus().toString();
74
* Gets the name of the CacheManager
76
* @return The cache manager name, which may not be set
78
public String getName() {
79
return cacheManager.getName();
83
* Shuts down the CacheManager.
85
* If the shutdown occurs on the singleton, then the singleton is removed, so that if a singleton access method
86
* is called, a new singleton will be created.
88
public void shutdown() {
89
cacheManager.shutdown();
93
* Clears the contents of all caches in the CacheManager, but without
94
* removing any caches.
96
* This method is not synchronized. It only guarantees to clear those elements in a cache
97
* at the time that the {@link net.sf.ehcache.Ehcache#removeAll()} mehod on each cache is called.
99
public void clearAll() {
100
cacheManager.clearAll();
104
* Returns a JMX Cache bean
106
public Cache getCache(String name) {
107
return new Cache(cacheManager.getEhcache(name));
111
* Gets the cache names managed by the CacheManager
113
public String[] getCacheNames() throws IllegalStateException {
114
return cacheManager.getCacheNames();
118
* Gets a list of caches in this CacheManager
120
* @return a list of JMX Cache objects
122
public List getCaches() {
123
List cacheList = new ArrayList();
124
String[] caches = getCacheNames();
125
for (String cacheName : caches) {
126
Cache cache = getCache(cacheName);
127
cacheList.add(cache);
134
* @return the object name for this MBean
136
ObjectName getObjectName() {