[jboss-cvs] JBossCache/src/org/jboss/cache/jmx ...

Manik Surtani msurtani at jboss.com
Thu Jan 4 11:17:38 EST 2007


  User: msurtani
  Date: 07/01/04 11:17:38

  Modified:    src/org/jboss/cache/jmx      CacheJmxWrapper.java
                        JmxUtil.java CacheJmxWrapperMBean.java
  Removed:     src/org/jboss/cache/jmx      Cache.java CacheMBean.java
  Log:
  Updated JMX interfaces
  
  Revision  Changes    Path
  1.12      +148 -52   JBossCache/src/org/jboss/cache/jmx/CacheJmxWrapper.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheJmxWrapper.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/jmx/CacheJmxWrapper.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -b -r1.11 -r1.12
  --- CacheJmxWrapper.java	4 Jan 2007 15:39:38 -0000	1.11
  +++ CacheJmxWrapper.java	4 Jan 2007 16:17:38 -0000	1.12
  @@ -28,49 +28,138 @@
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.config.ConfigurationException;
   import org.jboss.cache.factories.DefaultCacheFactory;
  +import org.jboss.cache.interceptors.CacheMgmtInterceptor;
  +import org.jboss.cache.interceptors.Interceptor;
   
  +import javax.management.ListenerNotFoundException;
  +import javax.management.MBeanNotificationInfo;
   import javax.management.MBeanRegistration;
   import javax.management.MBeanServer;
   import javax.management.MalformedObjectNameException;
  +import javax.management.NotificationFilter;
  +import javax.management.NotificationListener;
   import javax.management.ObjectName;
   
  -public abstract class CacheJmxWrapper extends org.jboss.cache.jmx.Cache implements CacheJmxWrapperMBean, MBeanRegistration
  +public class CacheJmxWrapper implements CacheJmxWrapperMBean, MBeanRegistration
   {
      private Log log = LogFactory.getLog(getClass().getName());
   
  -   private boolean registerInterceptors = true;
  -   private Configuration config;
      private MBeanServer server;
      private String cacheObjectName;
  -   private boolean selfConstructed = false;
      private boolean registeredInterceptorsInCreate;
      private boolean interceptorsRegistered;
  +   private CacheImpl cache;
  +   private boolean selfConstructed = false;
  +   private Configuration config;
      private boolean created;
  +   private boolean registerInterceptors = true;
   
  -   // --------------------------------------------------------  CacheJMXWrapperMBean
  -
  -   public boolean getRegisterInterceptors()
  +   public CacheJmxWrapper()
      {
  -      return registerInterceptors;
      }
   
  -   public void setRegisterInterceptors(boolean register)
  +   public CacheJmxWrapper(Cache cache)
      {
  -      this.registerInterceptors = register;
  +      setCache(cache);
      }
   
  -   public Cache getCache()
  +   public org.jboss.cache.Cache getCache()
      {
         return cache;
      }
   
  +   public Configuration getConfiguration()
  +   {
  +      return cache == null ? null : cache.getConfiguration();
  +   }
  +
  +   public String getConfigurationAsString()
  +   {
  +      return cache == null ? "Cache is null" : cache.getConfiguration().toString();
  +   }
  +
  +   public String getConfigurationAsHtmlString()
  +   {
  +      return cache == null ? "Cache is null" : formatHtml(cache.getConfiguration().toString());
  +   }
  +
  +   public String getCacheDetails()
  +   {
  +      return cache == null ? "Cache is null" : cache.printDetails();
  +   }
  +
  +   public String getCacheDetailsAsHtml()
  +   {
  +      return cache == null ? "Cache is null" : formatHtml(cache.printDetails());
  +   }
  +
  +   public int getNumberOfNodes()
  +   {
  +      return cache == null ? -1 : cache.getNumberOfNodes();
  +   }
  +
  +   public int getNumberOfAttributes()
  +   {
  +      return cache == null ? -1 : cache.getNumberOfAttributes();
  +   }
  +
  +   public String getLockInfo()
  +   {
  +      return cache == null ? "Cache is null" : cache.printLockInfo();
  +   }
  +
  +   public String getLockInfoAsHtml()
  +   {
  +      return cache == null ? "Cache is null" : formatHtml(cache.printLockInfo());
  +   }
  +
  +   public void addNotificationListener(NotificationListener notificationListener, NotificationFilter notificationFilter, Object object) throws IllegalArgumentException
  +   {
  +      getCacheMgmtInterceptor().addNotificationListener(notificationListener, notificationFilter, object);
  +   }
  +
  +   public void removeNotificationListener(NotificationListener notificationListener) throws ListenerNotFoundException
  +   {
  +      getCacheMgmtInterceptor().removeNotificationListener(notificationListener);
  +   }
  +
  +   public MBeanNotificationInfo[] getNotificationInfo()
  +   {
  +      return getCacheMgmtInterceptor().getNotificationInfo();
  +   }
  +
  +   private CacheMgmtInterceptor getCacheMgmtInterceptor()
  +   {
  +      for (Interceptor i : cache.getInterceptors())
  +      {
  +         if (i instanceof CacheMgmtInterceptor) return (CacheMgmtInterceptor) i;
  +      }
  +      throw new RuntimeException("Cache management interceptor not found");
  +   }
  +
  +   /**
  +    * Formats a given String for display as an HTML snippet.
  +    *
  +    * @param s string to format
  +    * @return formatted string
  +    */
  +   protected String formatHtml(String s)
  +   {
  +      s = s.replaceAll("\r\n", "<br />");
  +      s = s.replaceAll("\r", "<br />");
  +      s = s.replaceAll("\n", "<br />");
  +      s = s.replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
  +      s = s.replaceAll(" ", "&nbsp;");
  +      return s;
  +   }
  +
      public void create() throws Exception
      {
         if (cache == null)
         {
            if (config == null)
            {
  -            throw new ConfigurationException("Must call setConfiguration() or setCache()before call to create()");
  +            throw new ConfigurationException("Must call setConfiguration() or setCache() before call to create()");
            }
   
            constructCache();
  @@ -117,6 +206,53 @@
         created = false;
      }
   
  +   public boolean getRegisterInterceptors()
  +   {
  +      return registerInterceptors;
  +   }
  +
  +   public void setRegisterInterceptors(boolean register)
  +   {
  +      this.registerInterceptors = register;
  +   }
  +
  +   protected void constructCache() throws Exception
  +   {
  +      log.debug("Constructing Cache");
  +      setCache(DefaultCacheFactory.getInstance().createCache(config, false));
  +      selfConstructed = true;
  +   }
  +
  +   protected boolean registerInterceptors() throws Exception
  +   {
  +      if (registerInterceptors && !interceptorsRegistered && server != null)
  +      {
  +         log.debug("Registering interceptors");
  +         JmxUtil.registerInterceptors(server, cache.getInterceptorChain(), cacheObjectName);
  +         interceptorsRegistered = true;
  +         return true;
  +      }
  +      return false;
  +   }
  +
  +   protected void unregisterInterceptors()
  +   {
  +      if (registerInterceptors && interceptorsRegistered && server != null)
  +      {
  +         try
  +         {
  +            log.debug("Unreqistering interceptors");
  +            JmxUtil.unregisterInterceptors(server, cache.getInterceptorChain(), getCacheObjectName());
  +            interceptorsRegistered = false;
  +         }
  +         catch (Exception e)
  +         {
  +            log.error("Exception unregistering interceptors from JMX", e);
  +         }
  +      }
  +   }
  +
  +
      // --------------------------------------------------------------  MBeanRegistration
   
      /**
  @@ -187,11 +323,6 @@
   
      // ---------------------------------------------------------------  Public methods
   
  -   public Configuration getConfiguration()
  -   {
  -      return config;
  -   }
  -
      /**
       * Sets the configuration that the underlying cache should use.
       *
  @@ -248,39 +379,4 @@
   
      // --------------------------------------------------------  Private methods
   
  -   private void constructCache() throws Exception
  -   {
  -      log.debug("Constructing Cache");
  -      setCache(DefaultCacheFactory.getInstance().createCache(config, false));
  -      selfConstructed = true;
  -   }
  -
  -   private boolean registerInterceptors() throws Exception
  -   {
  -      if (registerInterceptors && !interceptorsRegistered && server != null)
  -      {
  -         log.debug("Registering interceptors");
  -         JmxUtil.registerInterceptors(server, cache.getInterceptorChain(), cacheObjectName);
  -         interceptorsRegistered = true;
  -         return true;
  -      }
  -      return false;
  -   }
  -
  -   private void unregisterInterceptors()
  -   {
  -      if (registerInterceptors && interceptorsRegistered && server != null)
  -      {
  -         try
  -         {
  -            log.debug("Unreqistering interceptors");
  -            JmxUtil.unregisterInterceptors(server, cache.getInterceptorChain(), getCacheObjectName());
  -            interceptorsRegistered = false;
  -         }
  -         catch (Exception e)
  -         {
  -            log.error("Exception unregistering interceptors from JMX", e);
  -         }
  -      }
  -   }
   }
  
  
  
  1.8       +2 -2      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.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- JmxUtil.java	4 Jan 2007 05:35:40 -0000	1.7
  +++ JmxUtil.java	4 Jan 2007 16:17:38 -0000	1.8
  @@ -35,7 +35,7 @@
    *
    * @author Jerry Gauthier
    * @author Manik Surtani
  - * @version $Id: JmxUtil.java,v 1.7 2007/01/04 05:35:40 msurtani Exp $
  + * @version $Id: JmxUtil.java,v 1.8 2007/01/04 16:17:38 msurtani Exp $
    */
   public class JmxUtil
   {
  @@ -47,7 +47,7 @@
      public static final String CACHE_TYPE_KEY = "cacheType=";
      public static final String PLAIN_CACHE_TYPE = "cacheType=Cache";
   
  -   public static void registerCacheMBean(MBeanServer server, CacheMBean cache, String cacheObjectName)
  +   public static void registerCacheMBean(MBeanServer server, CacheJmxWrapperMBean cache, String cacheObjectName)
              throws Exception
      {
         ObjectName on = new ObjectName(cacheObjectName);
  
  
  
  1.3       +66 -26    JBossCache/src/org/jboss/cache/jmx/CacheJmxWrapperMBean.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheJmxWrapperMBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/jmx/CacheJmxWrapperMBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- CacheJmxWrapperMBean.java	10 Nov 2006 02:23:34 -0000	1.2
  +++ CacheJmxWrapperMBean.java	4 Jan 2007 16:17:38 -0000	1.3
  @@ -1,36 +1,77 @@
   /*
  - * JBoss, Home of Professional Open Source.
  - * Copyright 2006, Red Hat Middleware LLC, and individual contributors
  - * as indicated by the @author tags. See the copyright.txt file in the
  - * distribution for a full listing of individual contributors.
  + * JBoss, Home of Professional Open Source
    *
  - * 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.
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
    */
   package org.jboss.cache.jmx;
   
  -
  +import org.jboss.cache.Cache;
  +import org.jboss.cache.config.Configuration;
   
   /**
  - * StandardMBean interface for {@link CacheJmxWrapper}.
  + * JMX interface to the {@link org.jboss.cache.Cache}.  Full access to the cache is not supported, only a certain
  + * set of operations are exposed via JMX:
  + * <p/>
  + * <ol>
  + * <li> Lifecycle methods - create, start, stop, destroy</li>
  + * <li> Configuration (read-only) getter - which retrieves a String (or formatted HTML for web based JMX consoles) representation of the configuration</li>
  + * <li> Setters for a specific subset of config elements which may be changed at runtime</li>
  + * <li> Cache information methods (numNodes, numAttributes, lockInfo, printDetails) which print as Strings or as formatted HTML (for web based JMX consoles)</li>
    * 
  - * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  - * @version $Revision: 1.2 $
  + * @since 2.0.0
    */
  -public interface CacheJmxWrapperMBean extends CacheMBean
  +public interface CacheJmxWrapperMBean extends LifeCycle
   {
  +   /**
  +    * Retrieves a reference to the underlying {@link Cache}
  +    */
  +   Cache getCache();
  +
  +   /**
  +    * @return an immutable configuration
  +    */
  +   Configuration getConfiguration();
  +
  +   /**
  +    * @return a string based representation of the configuration
  +    */
  +   String getConfigurationAsString();
  +
  +   /**
  +    * @return an HTML formatted string based representation of the configuration
  +    */
  +   String getConfigurationAsHtmlString();
  +
  +   /**
  +    * @return details of nodes in the cache
  +    */
  +   String getCacheDetails();
  +
  +   /**
  +    * @return details of nodes in the cache, formatted as HTML
  +    */
  +   String getCacheDetailsAsHtml();
  +
  +   /**
  +    * @return number of nodes in the cache
  +    */
  +   int getNumberOfNodes();
  +
  +   /**
  +    * @return number of attributes in the cache
  +    */
  +   int getNumberOfAttributes();
  +
  +   /**
  +    * @return information on the state of node locks
  +    */
  +   String getLockInfo();
  +
  +   /**
  +    * @return information on the state of node locks, formatted as HTML
  +    */
  +   String getLockInfoAsHtml();
      
      /**
       * Gets whether this object should register the cache's interceptors
  @@ -47,5 +88,4 @@
       * Default is <code>true</code>.
       */
      void setRegisterInterceptors(boolean register);
  -   
   }
  
  
  



More information about the jboss-cvs-commits mailing list