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

Jason Thomas Greene jgreene at jboss.com
Thu Apr 5 21:23:16 EDT 2007


  User: jgreene 
  Date: 07/04/05 21:23:16

  Modified:    src/org/jboss/cache/pojo/jmx   JmxUtil.java
                        PojoCacheJmxWrapper.java
  Log:
  Fix JMX
  
  Revision  Changes    Path
  1.2       +39 -57    JBossCache/src/org/jboss/cache/pojo/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/pojo/jmx/JmxUtil.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- JmxUtil.java	13 Jan 2007 15:55:11 -0000	1.1
  +++ JmxUtil.java	6 Apr 2007 01:23:16 -0000	1.2
  @@ -7,23 +7,30 @@
   
   package org.jboss.cache.pojo.jmx;
   
  -import org.jboss.cache.CacheSPI;
  +import java.util.Hashtable;
  +import java.util.Map;
  +import java.util.Set;
   
   import javax.management.MBeanServer;
  +import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
   
  +import org.jboss.cache.CacheSPI;
  +
   /**
    * Various JMX related utilities
    *
    * @author Ben Wang
  - * @version $Id: JmxUtil.java,v 1.1 2007/01/13 15:55:11 bwang Exp $
  + * @version $Id: JmxUtil.java,v 1.2 2007/04/06 01:23:16 jgreene Exp $
    */
   public class JmxUtil extends org.jboss.cache.jmx.JmxUtil
   {
      public static final String POJO_CACHE_DOMAIN = "jboss.pojocache";
      public static final String PC_PREFIX = POJO_CACHE_DOMAIN + ":service=PojoCache,clusterName=";
  -   public static final String POJO_CACHE_TYPE = "cacheType=PojoCache";
  -
  +   public static final String POJO_CACHE_TYPE = "PojoCache";
  +   public static final String POJO_SERVICE_PREFIX = "Pojo";
  +   public static final String SERVICE_KEY_NAME = "service";
  +   public static final String CACHE_TYPE_KEY_NAME = "cacheType";
   
      public static void registerPojoCache(MBeanServer server, PojoCacheJmxWrapper cache, String objectName)
              throws Exception
  @@ -36,67 +43,42 @@
   
      }
   
  -   public static String getPojoCacheObjectName(org.jboss.cache.pojo.PojoCache cache)
  +   private static ObjectName toObjectName(String name)
      {
  -      // get the cache's registration name
  -      String tmpName = getCacheObjectName((CacheSPI) cache.getCache());
  -      String newName = null;
  -      if (tmpName.startsWith(PREFIX))
  +      try
         {
  -         newName = tmpName.replaceFirst(PREFIX, PC_PREFIX);
  +         return new ObjectName(name);
         }
  -      else if (tmpName.startsWith(JBOSS_CACHE_DOMAIN))
  +      catch (MalformedObjectNameException e)
         {
  -         newName = tmpName.replaceFirst(JBOSS_CACHE_DOMAIN, POJO_CACHE_DOMAIN);
  +         throw new IllegalArgumentException(e);
  +      }
         }
  -      else if (tmpName.contains(CACHE_TYPE_KEY))
  +
  +   public static String getPojoCacheObjectName(org.jboss.cache.pojo.PojoCache cache)
         {
  -         if (tmpName.contains(POJO_CACHE_TYPE))
  -            throw new IllegalStateException("Plain Cache ObjectName should not include " + POJO_CACHE_TYPE);
  +      // get the cache's registration name
  +      String tmpName = getCacheObjectName((CacheSPI) cache.getCache());
  +      ObjectName cacheName = toObjectName(tmpName);
   
  -         int start = tmpName.indexOf(POJO_CACHE_TYPE);
  -         int end = tmpName.indexOf(",", start);
  -         if (end < 0)
  -            end = tmpName.length();
  -         String oldType = tmpName.substring(start, end);
  -         newName = tmpName.replaceFirst(oldType, POJO_CACHE_TYPE);
  -      }
  -      else
  +      String newName = POJO_CACHE_DOMAIN + ":";
  +      Hashtable<String, String> keyPropertyList = cacheName.getKeyPropertyList();
  +      for (Map.Entry<String, String> entry : keyPropertyList.entrySet())
         {
  -         newName = tmpName + "," + POJO_CACHE_TYPE;
  -      }
  +         String key = entry.getKey();
  +         String value = entry.getValue();
   
  -      return newName;
  +         if (SERVICE_KEY_NAME.equals(key) || CACHE_TYPE_KEY_NAME.equals(key))
  +            continue;
  +         newName += key + "=" + value + ",";
      }
   
  -   public static String getPlainCacheObjectName(String pojoCacheObjectName)
  -   {
  -      String plainName = null;
  -      if (pojoCacheObjectName.startsWith(PC_PREFIX))
  -      {
  -         plainName = pojoCacheObjectName.replaceFirst(PC_PREFIX, PREFIX);
  -      }
  -      else if (pojoCacheObjectName.startsWith(POJO_CACHE_DOMAIN))
  -      {
  -         plainName = pojoCacheObjectName.replaceFirst(POJO_CACHE_DOMAIN, JBOSS_CACHE_DOMAIN);
  -      }
  -      else if (pojoCacheObjectName.contains(CACHE_TYPE_KEY))
  -      {
  -         if (pojoCacheObjectName.contains(PLAIN_CACHE_TYPE))
  -            throw new IllegalStateException("PojoCache ObjectName should not include " + PLAIN_CACHE_TYPE);
  +      String serviceName = keyPropertyList.get(SERVICE_KEY_NAME);
  +      serviceName = serviceName != null ? POJO_SERVICE_PREFIX + serviceName : POJO_CACHE_TYPE;
   
  -         int start = pojoCacheObjectName.indexOf(PLAIN_CACHE_TYPE);
  -         int end = pojoCacheObjectName.indexOf(",", start);
  -         if (end < 0)
  -            end = pojoCacheObjectName.length();
  -         String oldType = pojoCacheObjectName.substring(start, end);
  -         plainName = pojoCacheObjectName.replaceFirst(oldType, PLAIN_CACHE_TYPE);
  -      }
  -      else
  -      {
  -         plainName = pojoCacheObjectName + "," + PLAIN_CACHE_TYPE;
  -      }
  -      return plainName;
  +      newName += SERVICE_KEY_NAME + "=" + serviceName + "," + CACHE_TYPE_KEY_NAME + "=" + POJO_CACHE_TYPE;
  +
  +      return toObjectName(newName).getCanonicalName();
      }
   
      public static void unregisterPojoCache(MBeanServer server, String objectName)
  
  
  
  1.3       +2 -9      JBossCache/src/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PojoCacheJmxWrapper.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- PojoCacheJmxWrapper.java	19 Jan 2007 02:04:32 -0000	1.2
  +++ PojoCacheJmxWrapper.java	6 Apr 2007 01:23:16 -0000	1.3
  @@ -47,7 +47,7 @@
      private boolean selfConstructed;
      private PojoCache pojoCache;
      private CacheJmxWrapper plainCacheWrapper;
  -   private boolean registerPlainCache;
  +   private boolean registerPlainCache = true;
      private boolean registeredPlainCacheInCreate;
      private boolean plainCacheRegistered;   
      private boolean created;
  @@ -178,7 +178,7 @@
         
         if (cacheObjectName == null)
         {
  -         cacheObjectName = objName.getCanonicalName();
  +         cacheObjectName = objName.toString();
         }
         
         return new ObjectName(cacheObjectName);
  @@ -281,13 +281,6 @@
      {
         if (registerPlainCache && !plainCacheRegistered && server != null)
         {
  -         if (config.getServiceName() == null || config.getServiceName().length() == 0)
  -         {
  -            // We need to inject the object name into the plain cache
  -            String plainName = JmxUtil.getPlainCacheObjectName(cacheObjectName);
  -            plainCacheWrapper.setCacheObjectName(plainName);
  -         }
  -         
            log.debug("Registering plain cache under name " + plainCacheWrapper.getCacheObjectName());
            org.jboss.cache.jmx.JmxUtil.registerCacheMBean(server, plainCacheWrapper, plainCacheWrapper.getCacheObjectName());
            plainCacheRegistered = true;
  
  
  



More information about the jboss-cvs-commits mailing list