[jbosscache-commits] JBoss Cache SVN: r6550 - in core/trunk/src: main/java/org/jboss/cache/jmx and 1 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Aug 8 15:29:53 EDT 2008


Author: mircea.markus
Date: 2008-08-08 15:29:53 -0400 (Fri, 08 Aug 2008)
New Revision: 6550

Added:
   core/trunk/src/main/java/org/jboss/cache/jmx/PlatformMBeanServerRegistration.java
   core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java
Modified:
   core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
   core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
Log:
added regitration to the platform mbean server


Modified: core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java	2008-08-08 19:04:05 UTC (rev 6549)
+++ core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java	2008-08-08 19:29:53 UTC (rev 6550)
@@ -14,6 +14,7 @@
 import org.jboss.cache.factories.ComponentFactory;
 import org.jboss.cache.factories.ComponentRegistry;
 import org.jboss.cache.invocation.CacheInvocationDelegate;
+import org.jboss.cache.jmx.PlatformMBeanServerRegistration;
 
 import java.io.InputStream;
 
@@ -123,6 +124,7 @@
       this.configuration = configuration;
 
       componentRegistry.registerComponent(spi, CacheSPI.class);
+      componentRegistry.registerComponent(new PlatformMBeanServerRegistration(), PlatformMBeanServerRegistration.class);
    }
 
    /**

Modified: core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java	2008-08-08 19:04:05 UTC (rev 6549)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java	2008-08-08 19:29:53 UTC (rev 6550)
@@ -40,7 +40,6 @@
  */
 public class JmxRegistrationManager
 {
-
    private static final Log log = LogFactory.getLog(JmxRegistrationManager.class);
 
    /**

Added: core/trunk/src/main/java/org/jboss/cache/jmx/PlatformMBeanServerRegistration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/PlatformMBeanServerRegistration.java	                        (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/PlatformMBeanServerRegistration.java	2008-08-08 19:29:53 UTC (rev 6550)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.cache.jmx;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.factories.annotations.Stop;
+import org.jboss.cache.factories.annotations.NonVolatile;
+
+/**
+ * If {@link org.jboss.cache.config.Configuration#getExposeManagementStatistics()} is true, then class will register
+ * all the MBeans from the ConfigurationRegistry to the pltform MBean server.
+ * <p/>
+ * Note: to enable platform MBeanServer the following system property should be passet to the JVM:
+ * <b>-Dcom.sun.management.jmxremote</b>.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @see java.lang.management.ManagementFactory#getPlatformMBeanServer()
+ * @since 3.0
+ */
+ at NonVolatile
+public class PlatformMBeanServerRegistration
+{
+   private static final Log log = LogFactory.getLog(PlatformMBeanServerRegistration.class);
+
+   private CacheSPI cache;
+
+   @Inject
+   public void initialize(CacheSPI cache)
+   {
+      this.cache = cache;
+   }
+
+   /**
+    * Here is where the registration is being performed.
+    */
+   @Start(priority = 14)
+   public void registerToPlatformMBeanServer()
+   {
+      if (cache == null)
+         throw new IllegalStateException("The cache should had been injected before a call to this method");
+      Configuration config = cache.getConfiguration();
+      if (config.getExposeManagementStatistics())
+      {
+         JmxRegistrationManager jmxRegistrationManager = new JmxRegistrationManager(cache);
+         jmxRegistrationManager.registerAllMBeans();
+         log.info("JBossCache MBeans were successfully registered to the platform mbean server.");
+      }
+   }
+
+   /**
+    * Unregister when the cache is being stoped.
+    */
+   @Stop
+   public void unregisterMBeans()
+   {
+      Configuration config = cache.getConfiguration();
+      if (config.getExposeManagementStatistics())
+      {
+         JmxRegistrationManager jmxRegistrationManager = new JmxRegistrationManager(cache);
+         jmxRegistrationManager.unregisterAllMBeans();
+         log.trace("JBossCache MBeans were successfully unregistered from the platform mbean server.");
+      }
+      cache = null;
+   }
+}

Added: core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java	2008-08-08 19:29:53 UTC (rev 6550)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.cache.jmx;
+
+/**
+ * @author Mircea.Markus at jboss.com
+ * @since 3.0
+ */
+public class JmxRegistrationManagerTest
+{
+}




More information about the jbosscache-commits mailing list