[jboss-cvs] JBossCache/src/org/jboss/cache/jmx ...
Brian Stansberry
brian.stansberry at jboss.com
Sun Nov 5 15:19:43 EST 2006
User: bstansberry
Date: 06/11/05 15:19:43
Modified: src/org/jboss/cache/jmx JmxUtil.java
Log:
Refactor JMX registration to decouple from TreeCache class
Revision Changes Path
1.4 +45 -50 JBossCache/src/org/jboss/cache/jmx/JmxUtil.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JmxUtil.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/jmx/JmxUtil.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- JmxUtil.java 5 Nov 2006 05:08:49 -0000 1.3
+++ JmxUtil.java 5 Nov 2006 20:19:43 -0000 1.4
@@ -21,21 +21,22 @@
*/
package org.jboss.cache.jmx;
-import org.jboss.cache.TreeCache;
-import org.jboss.cache.interceptors.Interceptor;
+import java.util.ArrayList;
+import java.util.List;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
-import java.util.ArrayList;
-import java.util.List;
+
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.interceptors.Interceptor;
/**
* Various JMX related utilities
*
* @author Jerry Gauthier
* @author Manik Surtani
- * @version $Id: JmxUtil.java,v 1.3 2006/11/05 05:08:49 bstansberry Exp $
+ * @version $Id: JmxUtil.java,v 1.4 2006/11/05 20:19:43 bstansberry Exp $
*/
public class JmxUtil
{
@@ -45,6 +46,14 @@
public static final String PREFIX = JBOSS_CACHE_DOMAIN + ":service=Cache,clusterName=";
private static final String JBOSS_SERVER_DOMAIN = "jboss";
+ public static void registerCacheMBean(MBeanServer server, CacheMBean cache, String cacheObjectName)
+ throws Exception
+ {
+ ObjectName on = new ObjectName(cacheObjectName);
+ if (!server.isRegistered(on))
+ server.registerMBean(cache, on);
+ }
+
/*
* Register the associated mbeans for cache interceptors
*
@@ -52,28 +61,14 @@
* @param cache the cache having the set of interceptors to be registered
* @param registerCache whether the cache itself should be registered
*/
- public static void registerInterceptors(MBeanServer server, TreeCache cache, boolean registerCache)
+ public static void registerInterceptors(MBeanServer server, List<Interceptor> interceptors, String cacheObjectName)
throws Exception
{
- if (server == null || cache == null)
+ if (server == null || interceptors == null || cacheObjectName == null)
return;
- List interceptors = cache.getInterceptors();
Interceptor interceptor = null;
- String tmpName = getCacheObjectName(cache.getCacheSPI());
-
- // register the cache
- // TODO (BES 2006-11-04) I don't think there is any use case for not registering.
- // This check is legacy stuff from 1.4, when the AS JMX microkernel may have
- // already registered the old monolithic cache.
- if (registerCache)
- {
- ObjectName tmpObj = new ObjectName(tmpName);
- if (!server.isRegistered(tmpObj))
- server.registerMBean(cache.getCacheMBeanInterface(), tmpObj);
- }
-
for (int i = 0; i < interceptors.size(); i++)
{
interceptor = (Interceptor) interceptors.get(i);
@@ -92,7 +87,7 @@
// for JDK 1.4, must parse name and remove package prefix
// for JDK 1.5, can use getSimpleName() to establish class name without package prefix
String className = interceptor.getClass().getName();
- String serviceName = tmpName + MBEAN_KEY + className.substring(className.lastIndexOf('.') + 1);
+ String serviceName = cacheObjectName + MBEAN_KEY + className.substring(className.lastIndexOf('.') + 1);
ObjectName objName = new ObjectName(serviceName);
if (!server.isRegistered(objName))
@@ -110,17 +105,30 @@
public static String getCacheObjectName(org.jboss.cache.CacheSPI cache)
{
// get the cache's registration name
- String tmpName = cache.getConfiguration().getServiceName();
+ return getCacheObjectName(cache.getConfiguration(), cache.getClass().getName());
+ }
+
+ public static String getCacheObjectName(Configuration config, String cacheSPIClass)
+ {
+ // get the cache's registration name
+ String tmpName = config.getServiceName();
if (tmpName == null)
{
- tmpName = PREFIX + cache.getConfiguration().getClusterName();
- if (cache.getConfiguration().getClusterName() == null)
- tmpName = PREFIX + cache.getClass().getName() + System.currentTimeMillis();
+ if (config.getClusterName() == null)
+ tmpName = PREFIX + cacheSPIClass + System.currentTimeMillis();
+ else
+ tmpName = PREFIX + config.getClusterName();
}
return tmpName;
}
+ public static void unregisterCacheMBean(MBeanServer server, String cacheObjectName)
+ throws Exception
+ {
+ server.unregisterMBean(new ObjectName(cacheObjectName));
+ }
+
/*
* Unregister the associated mbeans for cache interceptors
*
@@ -128,17 +136,14 @@
* @param cache the cache having the set of interceptors to be unregistered
* @param unregisterCache whether the cache itself should be unregistered
*/
- public static void unregisterInterceptors(MBeanServer server, TreeCache cache, boolean unregisterCache)
+ public static void unregisterInterceptors(MBeanServer server, List<Interceptor> interceptors, String cacheObjectName)
throws Exception
{
- if (server == null || cache == null)
+ if (server == null || interceptors == null || cacheObjectName == null)
return;
- List interceptors = cache.getInterceptors();
Interceptor interceptor = null;
- String tmpName = getCacheObjectName(cache.getCacheSPI());
-
for (int i = 0; i < interceptors.size(); i++)
{
interceptor = (Interceptor) interceptors.get(i);
@@ -146,22 +151,12 @@
// for JDK 1.4, must parse name and remove package prefix
// for JDK 1.5, can use getSimpleName() to establish class name without package prefix
String className = interceptor.getClass().getName();
- String serviceName = tmpName + MBEAN_KEY + className.substring(className.lastIndexOf('.') + 1);
+ String serviceName = cacheObjectName + MBEAN_KEY + className.substring(className.lastIndexOf('.') + 1);
ObjectName objName = new ObjectName(serviceName);
if (server.isRegistered(objName))
server.unregisterMBean(objName);
}
-
- // unregister the cache itself
- // TODO (BES 2006-11-04) I don't think there is any use case for not unregistering.
- // See comment in registerInterceptors
- if (unregisterCache)
- {
- ObjectName tmpObj = new ObjectName(tmpName);
- if (server.isRegistered(tmpObj))
- server.unregisterMBean(tmpObj);
- }
}
public static MBeanServer getMBeanServer()
More information about the jboss-cvs-commits
mailing list