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

Brian Stansberry brian.stansberry at jboss.com
Mon Nov 6 00:00:35 EST 2006


  User: bstansberry
  Date: 06/11/06 00:00:35

  Modified:    src-50/org/jboss/cache/pojo/jmx  JmxUtil.java
  Log:
  Add support for PojoCacheJmxWrapper
  Improve translation between pojo and plain cache object names
  
  Revision  Changes    Path
  1.3       +69 -6     JBossCache/src-50/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-50/org/jboss/cache/pojo/jmx/JmxUtil.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- JmxUtil.java	5 Nov 2006 05:09:40 -0000	1.2
  +++ JmxUtil.java	6 Nov 2006 05:00:35 -0000	1.3
  @@ -16,13 +16,13 @@
    * Various JMX related utilities
    *
    * @author Ben Wang
  - * @version $Id: JmxUtil.java,v 1.2 2006/11/05 05:09:40 bstansberry Exp $
  + * @version $Id: JmxUtil.java,v 1.3 2006/11/06 05:00:35 bstansberry 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 PC_SUFFIX = ",type=PojoCache";
  +   public static final String POJO_CACHE_TYPE = "cacheType=PojoCache";
   
      /*
      */
  @@ -43,6 +43,17 @@
                    tmpObj);
      }
   
  +   public static void registerPojoCache(MBeanServer server, PojoCacheJmxWrapper cache, String objectName)
  +         throws Exception
  +   {
  +      if (server == null || cache == null || objectName == null)
  +         return;
  +      ObjectName tmpObj = new ObjectName(objectName);
  +      if (!server.isRegistered(tmpObj))
  +         server.registerMBean(cache, tmpObj);
  +      
  +   }
  +
      public static String getPojoCacheObjectName(org.jboss.cache.pojo.PojoCache cache)
      {
         // get the cache's registration name
  @@ -56,14 +67,56 @@
         {
            newName = tmpName.replaceFirst(JBOSS_CACHE_DOMAIN, POJO_CACHE_DOMAIN);
         }
  +      else if (tmpName.indexOf(CACHE_TYPE_KEY) > -1)
  +      {
  +         if (tmpName.indexOf(POJO_CACHE_TYPE) > -1)
  +            throw new IllegalStateException("Plain Cache ObjectName should not include " + POJO_CACHE_TYPE);
  +         
  +         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
         {
  -         newName = tmpName + PC_SUFFIX;
  +         newName = tmpName + POJO_CACHE_TYPE;
         }
         
         return newName;
      }
   
  +   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.indexOf(CACHE_TYPE_KEY) > -1)
  +      {
  +         if (pojoCacheObjectName.indexOf(PLAIN_CACHE_TYPE) > -1)
  +            throw new IllegalStateException("PojoCache ObjectName should not include " + PLAIN_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;
  +   }
  +
      /*
      */
      public static void unregisterPojoCache(MBeanServer server, org.jboss.cache.pojo.PojoCache pcache)
  @@ -74,8 +127,18 @@
   
         // get the cache's registration name
         String tmpName = getPojoCacheObjectName(pcache);
  -      ObjectName tmpObj = new ObjectName(tmpName);
  -      if (server.isRegistered(tmpObj))
  -         server.unregisterMBean(tmpObj);
  +      unregisterPojoCache(server, tmpName);
  +   }
  +   
  +   public static void unregisterPojoCache(MBeanServer server, String objectName)
  +         throws Exception
  +   {
  +      if (server == null || objectName == null)
  +         return;
  +      
  +      ObjectName on = new ObjectName(objectName);
  +      if (server.isRegistered(on))
  +         server.unregisterMBean(on);
  +      
      }
   }
  
  
  



More information about the jboss-cvs-commits mailing list