Author: manik.surtani(a)jboss.com
Date: 2008-11-27 08:37:31 -0500 (Thu, 27 Nov 2008)
New Revision: 7213
Modified:
core/branches/flat/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
Log:
Ported from trunk
Modified:
core/branches/flat/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java 2008-11-27
12:39:44 UTC (rev 7212)
+++
core/branches/flat/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java 2008-11-27
13:37:31 UTC (rev 7213)
@@ -45,176 +45,159 @@
* is being used.
* <p/>
* It is immutable: both cache instance and MBeanServer are being passed as arguments to
the constructor.
+ * <p />
+ * <p>
+ * Note that by default object names used are prefixed with
<tt>jboss.cache:service=JBossCache</tt>. While this format
+ * works for and is consistent with JBoss AS and the JMX console, it has been known to
cause problems with other JMX
+ * servers such as Websphere. To work around this, you can provide the following VM
system property to override this
+ * prefix with a prefix of your choice:
+ * <tt><b>-Djbosscache.jmx.prefix=JBossCache</b></tt>
+ * </p>
*
* @author Mircea.Markus(a)jboss.com
* @since 3.0
*/
-public class JmxRegistrationManager
-{
- private static final Log log = LogFactory.getLog(JmxRegistrationManager.class);
+public class JmxRegistrationManager {
- /**
- * default ObjectName for clusterd caches. Cluster name should pe appended.
- */
- public static final String REPLICATED_CACHE_PREFIX =
"jboss.cache:service=JBossCache,cluster=";
+ private static final Log log = LogFactory.getLog(JmxRegistrationManager.class);
- /**
- * default ObjectName for non clustered caches. An unique identifier should be
appended.
- */
- public static final String LOCAL_CACHE_PREFIX =
"jboss.cache:service=JBossCache,uniqueId=";
+ private static final String GENERAL_PREFIX =
System.getProperty("jbosscache.jmx.prefix",
"jboss.cache:service=JBossCache");
- /**
- * Key for every Dynamic mbean added.
- */
- public static final String JMX_RESOURCE_KEY = ",jmx-resource=";
+ /**
+ * default ObjectName for clusterd caches. Cluster name should pe appended.
+ */
+ public static final String REPLICATED_CACHE_PREFIX = GENERAL_PREFIX +
",cluster=";
- private MBeanServer mBeanServer;
+ /**
+ * default ObjectName for non clustered caches. An unique identifier should be
appended.
+ */
+ public static final String LOCAL_CACHE_PREFIX = GENERAL_PREFIX +
",uniqueId=";
- private String objectNameBase;
+ /**
+ * Key for every Dynamic mbean added.
+ */
+ public static final String JMX_RESOURCE_KEY = ",jmx-resource=";
- private CacheSPI cacheSpi;
+ private MBeanServer mBeanServer;
- /**
- * C-tor.
- *
- * @param mBeanServer the server where mbeans are being registered
- * @param cache cache that needs to be monitored
- * @param objectNameBase path in the MBeanServer where to register cache MBeans
- */
- public JmxRegistrationManager(MBeanServer mBeanServer, Cache cache, ObjectName
objectNameBase)
- {
- this.mBeanServer = mBeanServer;
- this.cacheSpi = (CacheSPI) cache;
- processBaseName(objectNameBase);
- }
+ private String objectNameBase;
- public JmxRegistrationManager(MBeanServer mBeanServer, Cache_Legacy cache, String
objectNameBase)
- {
- throw new UnsupportedOperationException("Remove any code that relies on
this!");
- }
+ private CacheSPI cacheSpi;
- /**
- * @throws IllegalArgumentException if the supplied objectNameBase name isn't
valid
- * @see #JmxRegistrationManager(javax.management.MBeanServer,
org.jboss.cache.Cache_Legacy , javax.management.ObjectName)
- */
- public JmxRegistrationManager(MBeanServer mBeanServer, Cache cache, String
objectNameBase)
- {
- this.mBeanServer = mBeanServer;
- this.cacheSpi = (CacheSPI) cache;
- try
- {
- processBaseName(new ObjectName(objectNameBase));
- }
- catch (MalformedObjectNameException e)
- {
- throw new IllegalArgumentException("Invalid Object Name : " +
objectNameBase, e);
- }
- }
+ /**
+ * C-tor.
+ *
+ * @param mBeanServer the server where mbeans are being registered
+ * @param cache cache that needs to be monitored
+ * @param objectNameBase path in the MBeanServer where to register cache MBeans
+ */
+ public JmxRegistrationManager(MBeanServer mBeanServer, Cache cache, ObjectName
objectNameBase) {
+ this.mBeanServer = mBeanServer;
+ this.cacheSpi = (CacheSPI) cache;
+ processBaseName(objectNameBase);
+ }
- /**
- * Defaults to platform to platform MBeanServer.
- *
- * @see java.lang.management.ManagementFactory#getPlatformMBeanServer()
- * @see <a
href="http://java.sun.com/j2se/1.5.0/docs/guide/management/mxbeans.h...
MBeanServer</a>
- */
- public JmxRegistrationManager(Cache cache, ObjectName objectNameBase)
- {
- this(ManagementFactory.getPlatformMBeanServer(), cache, objectNameBase);
- }
+ public JmxRegistrationManager(MBeanServer mBeanServer, Cache_Legacy cache, String
objectNameBase) {
+ throw new UnsupportedOperationException("Remove any code that relies on
this!");
+ }
- public JmxRegistrationManager(Cache cache)
- {
- this(cache, null);
- }
+ /**
+ * @throws IllegalArgumentException if the supplied objectNameBase name isn't
valid
+ */
+ public JmxRegistrationManager(MBeanServer mBeanServer, Cache cache, String
objectNameBase) {
+ this.mBeanServer = mBeanServer;
+ this.cacheSpi = (CacheSPI) cache;
+ try {
+ processBaseName(new ObjectName(objectNameBase));
+ }
+ catch (MalformedObjectNameException e) {
+ throw new IllegalArgumentException("Invalid Object Name : " +
objectNameBase, e);
+ }
+ }
- /**
- * Performs the MBean registration.
- */
- public void registerAllMBeans() throws CacheException
- {
- try
- {
- List<ResourceDMBean> resourceDMBeans = getResourceDMBeans();
- for (ResourceDMBean resource : resourceDMBeans)
- {
- String resourceName = resource.getObjectName();
- ObjectName objectName = new ObjectName(getObjectName(resourceName));
- if (!mBeanServer.isRegistered(objectName))
- {
- mBeanServer.registerMBean(resource, objectName);
+ /**
+ * Defaults to platform to platform MBeanServer.
+ *
+ * @see java.lang.management.ManagementFactory#getPlatformMBeanServer()
+ * @see <a
href="http://java.sun.com/j2se/1.5.0/docs/guide/management/mxbeans.h...
MBeanServer</a>
+ */
+ public JmxRegistrationManager(Cache cache, ObjectName objectNameBase) {
+ this(ManagementFactory.getPlatformMBeanServer(), cache, objectNameBase);
+ }
+
+ public JmxRegistrationManager(Cache cache) {
+ this(cache, null);
+ }
+
+ /**
+ * Performs the MBean registration.
+ */
+ public void registerAllMBeans() throws CacheException {
+ try {
+ List<ResourceDMBean> resourceDMBeans = getResourceDMBeans();
+ for (ResourceDMBean resource : resourceDMBeans) {
+ String resourceName = resource.getObjectName();
+ ObjectName objectName = new ObjectName(getObjectName(resourceName));
+ if (!mBeanServer.isRegistered(objectName)) {
+ mBeanServer.registerMBean(resource, objectName);
+ }
}
- }
- }
- catch (Exception e)
- {
- throw new CacheException("Failure while registering mbeans", e);
- }
- }
+ }
+ catch (Exception e) {
+ throw new CacheException("Failure while registering mbeans", e);
+ }
+ }
- /**
- * Unregisters all the MBeans registered through {@link #registerAllMBeans()}.
- */
- public void unregisterAllMBeans() throws CacheException
- {
- log.trace("Unregistering jmx resources..");
- try
- {
- List<ResourceDMBean> resourceDMBeans = getResourceDMBeans();
- for (ResourceDMBean resource : resourceDMBeans)
- {
- String resourceName = resource.getObject().getClass().getSimpleName();
- ObjectName objectName = new ObjectName(getObjectName(resourceName));
- if (mBeanServer.isRegistered(objectName))
- {
- mBeanServer.unregisterMBean(objectName);
+ /**
+ * Unregisters all the MBeans registered through {@link #registerAllMBeans()}.
+ */
+ public void unregisterAllMBeans() throws CacheException {
+ log.trace("Unregistering jmx resources..");
+ try {
+ List<ResourceDMBean> resourceDMBeans = getResourceDMBeans();
+ for (ResourceDMBean resource : resourceDMBeans) {
+ String resourceName = resource.getObject().getClass().getSimpleName();
+ ObjectName objectName = new ObjectName(getObjectName(resourceName));
+ if (mBeanServer.isRegistered(objectName)) {
+ mBeanServer.unregisterMBean(objectName);
+ }
}
- }
- }
- catch (Exception e)
- {
- throw new CacheException("Failure while unregistering mbeans", e);
- }
- }
+ }
+ catch (Exception e) {
+ throw new CacheException("Failure while unregistering mbeans", e);
+ }
+ }
- private List<ResourceDMBean> getResourceDMBeans()
- {
- List<ResourceDMBean> resourceDMBeans = new
ArrayList<ResourceDMBean>();
- for (ComponentRegistry.Component component :
cacheSpi.getComponentRegistry().getRegiteredComponents())
- {
- ResourceDMBean resourceDMBean = new ResourceDMBean(component.getInstance());
- if (resourceDMBean.isManagedResource())
- {
- resourceDMBeans.add(resourceDMBean);
- }
- }
- return resourceDMBeans;
- }
+ private List<ResourceDMBean> getResourceDMBeans() {
+ List<ResourceDMBean> resourceDMBeans = new
ArrayList<ResourceDMBean>();
+ for (ComponentRegistry.Component component :
cacheSpi.getComponentRegistry().getRegiteredComponents()) {
+ ResourceDMBean resourceDMBean = new ResourceDMBean(component.getInstance());
+ if (resourceDMBean.isManagedResource()) {
+ resourceDMBeans.add(resourceDMBean);
+ }
+ }
+ return resourceDMBeans;
+ }
- private void processBaseName(ObjectName baseName)
- {
- if (baseName != null)
- {
- this.objectNameBase = baseName.getCanonicalName();
- return;
- }
- if
(cacheSpi.getConfiguration().getCacheMode().equals(Configuration.CacheMode.LOCAL))
- {
- objectNameBase = LOCAL_CACHE_PREFIX + System.currentTimeMillis();
- }
- else //the cache is clustered
- {
- objectNameBase = REPLICATED_CACHE_PREFIX +
cacheSpi.getConfiguration().getClusterName();
- }
- }
+ private void processBaseName(ObjectName baseName) {
+ if (baseName != null) {
+ this.objectNameBase = baseName.getCanonicalName();
+ return;
+ }
+ if
(cacheSpi.getConfiguration().getCacheMode().equals(Configuration.CacheMode.LOCAL)) {
+ objectNameBase = LOCAL_CACHE_PREFIX + System.currentTimeMillis();
+ } else //the cache is clustered
+ {
+ objectNameBase = REPLICATED_CACHE_PREFIX +
cacheSpi.getConfiguration().getClusterName();
+ }
+ }
- public String getObjectName(String resourceName)
- {
- return objectNameBase + JMX_RESOURCE_KEY + resourceName;
- }
+ public String getObjectName(String resourceName) {
+ return objectNameBase + JMX_RESOURCE_KEY + resourceName;
+ }
- public String getObjectNameBase()
- {
- return objectNameBase;
- }
+ public String getObjectNameBase() {
+ return objectNameBase;
+ }
}