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

Brian Stansberry brian.stansberry at jboss.com
Fri Jun 29 00:08:19 EDT 2007


  User: bstansberry
  Date: 07/06/29 00:08:19

  Modified:    src/org/jboss/cache/pojo/jmx   PojoCacheJmxWrapperMBean.java
                        PojoCacheJmxWrapper.java
  Log:
  [JBCACHE-1090] Emit JMX Notifications the JBAS JSR-77 layer expects
  
  Revision  Changes    Path
  1.8       +25 -4     JBossCache/src/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapperMBean.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PojoCacheJmxWrapperMBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapperMBean.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- PojoCacheJmxWrapperMBean.java	23 May 2007 20:24:16 -0000	1.7
  +++ PojoCacheJmxWrapperMBean.java	29 Jun 2007 04:08:19 -0000	1.8
  @@ -33,10 +33,29 @@
    * StandardMBean interface for {@link PojoCacheJmxWrapperMBean}.
    * 
    * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   public interface PojoCacheJmxWrapperMBean extends LegacyConfiguration
   {
  +   /** The lifecycle method stop has completed */
  +   public static final int STOPPED  = 0;
  +   /** The lifecycle method stop has been invoked */
  +   public static final int STOPPING = 1;
  +   /** The lifecycle method start has been invoked */
  +   public static final int STARTING = 2;
  +   /** The lifecycle method start has completed */
  +   public static final int STARTED  = 3;
  +   /** There has been an error during some operation */
  +   public static final int FAILED  = 4;
  +   /** The lifecycle method destroy has completed */
  +   public static final int DESTROYED = 5;
  +   /** The lifecycle method create has completed */
  +   public static final int CREATED = 6;
  +   /** The MBean has been instantiated but has not completed MBeanRegistration.postRegister */
  +   public static final int UNREGISTERED = 7;
  +   /** The MBean has been instantiated and has completed MBeanRegistration.postRegister */
  +   public static final int REGISTERED = 8;
  +   
      /**
       * Lifecycle method to start PojoCache.
       *
  @@ -74,12 +93,14 @@
      CacheStatus getCacheStatus();
      
      /**
  -    * Legacy name for {@link #getCacheStatus()}. Retained to provide
  +    * Legacy attribute to expose the {@link #getCacheStatus() cache status} 
  +    * in terms of the JBoss AS ServiceMBean values.  This interface does
  +    * not extend ServiceMBean, but this attribute is retained to provide
       * compatibility with the JBoss AS JSR-77 integration layer.
       * 
  -    * @return the current status. Will not return <code>null</code>
  +    * @return the current status, e.g. {@link #STARTED}.
       */
  -   CacheStatus getState();
  +   int getState();
      
      /**
       * Returns the PojoCache.
  
  
  
  1.16      +64 -4     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.15
  retrieving revision 1.16
  diff -u -b -r1.15 -r1.16
  --- PojoCacheJmxWrapper.java	14 Jun 2007 16:14:49 -0000	1.15
  +++ PojoCacheJmxWrapper.java	29 Jun 2007 04:08:19 -0000	1.16
  @@ -44,6 +44,7 @@
   import org.jgroups.jmx.JChannelFactoryMBean;
   import org.w3c.dom.Element;
   
  +import javax.management.AttributeChangeNotification;
   import javax.management.JMException;
   import javax.management.ListenerNotFoundException;
   import javax.management.MBeanNotificationInfo;
  @@ -72,6 +73,7 @@
      private boolean registerPlainCache = true;
      private boolean plainCacheRegistered;
      private CacheStatus cacheStatus;
  +   private boolean registered;
      private final Set<NotificationListenerArgs> pendingListeners =
            new HashSet<NotificationListenerArgs>();
   
  @@ -82,7 +84,6 @@
      private Element cacheLoaderConfig;
      private Element clusterConfig;
      private JChannelFactoryMBean multiplexerService;
  -
      /**
       * Default constructor.
       */
  @@ -182,12 +183,16 @@
   
         try
         {
  +         int oldState = getState();
            cacheStatus = CacheStatus.STARTING;
  +         int startingState = getState();
  +         sendStateChangeNotification(oldState, startingState, getClass().getSimpleName() + " starting", null);
   
            pojoCache.start();
   
            plainCacheWrapper.start();
            cacheStatus = CacheStatus.STARTED;
  +         sendStateChangeNotification(startingState, getState(), getClass().getSimpleName() + " started", null);
         }
         catch (Throwable t)
         {
  @@ -207,12 +212,18 @@
   
         try
         {
  +         int oldState = getState();
  +         cacheStatus = CacheStatus.STOPPING;
  +         int stoppingState = getState();
  +         sendStateChangeNotification(oldState, stoppingState, getClass().getSimpleName() + " stopping", null);
  +         
            cacheStatus = CacheStatus.STOPPING;
   
            pojoCache.stop();
   
            plainCacheWrapper.stop();
            cacheStatus = CacheStatus.STOPPED;
  +         sendStateChangeNotification(stoppingState, getState(), getClass().getSimpleName() + " stopped", null);
         }
         catch (Throwable t)
         {
  @@ -259,9 +270,30 @@
         return cacheStatus;
      }
   
  -   public CacheStatus getState()
  +   public int getState()
  +   {
  +      switch (cacheStatus)
      {
  -      return getCacheStatus();
  +         case INSTANTIATED:
  +         case CREATING:
  +            return registered ? REGISTERED : UNREGISTERED;
  +         case CREATED:
  +            return CREATED;
  +         case STARTING:
  +            return STARTING;
  +         case STARTED:
  +            return STARTED;
  +         case STOPPING:
  +            return STOPPING;
  +         case STOPPED:
  +         case DESTROYING:
  +            return STOPPED;
  +         case DESTROYED:
  +            return registered ? DESTROYED : UNREGISTERED;
  +         case FAILED:
  +         default:
  +            return FAILED;
  +      }
      }
   
      public boolean getRegisterPlainCache()
  @@ -662,6 +694,8 @@
                  log.error("Caught exception registering plain cache with JMX", e);
               }
            }
  +         
  +         registered = true;
         }
      }
   
  @@ -682,6 +716,8 @@
         {
            unregisterPlainCache();
         }
  +      
  +      registered = false;
      }
   
      // ----------------------------------------------------  NotificationEmitter 
  @@ -814,6 +850,9 @@
         CacheJmxWrapper plainCache = new CacheJmxWrapper();
         plainCache.setRegisterInterceptors(getRegisterInterceptors());
         plainCache.setCache(pojoCache.getCache());
  +      // It shouldn't send out lifecycle state change notifications for itself; 
  +      // we do it
  +      plainCache.setDisableStateChangeNotifications(true);
   
         if (server != null)
         {
  @@ -894,6 +933,24 @@
      }
   
      /**
  +    * Helper for sending out state change notifications
  +    */
  +   private void sendStateChangeNotification(int oldState, int newState, String msg, Throwable t)
  +   {
  +      long now = System.currentTimeMillis();
  +      
  +      AttributeChangeNotification stateChangeNotification = new AttributeChangeNotification(
  +         this,
  +         plainCacheWrapper.getNextNotificationSequenceNumber(), now, msg,
  +         "State", "java.lang.Integer",
  +         new Integer(oldState), new Integer(newState)
  +         );
  +      stateChangeNotification.setUserData(t);
  +      
  +      plainCacheWrapper.sendNotification(stateChangeNotification);      
  +   }
  +
  +   /**
       * Sets the cacheStatus to FAILED and rethrows the problem as one
       * of the declared types. Converts any non-RuntimeException Exception
       * to CacheException.
  @@ -906,7 +963,10 @@
      private void handleLifecycleTransitionFailure(Throwable t)
            throws PojoCacheException, RuntimeException, Error
      {
  +      int oldState = getState();
         cacheStatus = CacheStatus.FAILED;
  +      sendStateChangeNotification(oldState, getState(), getClass().getSimpleName() + " failed", t);
  +      
         if (t instanceof CacheException)
            throw (PojoCacheException) t;
         else if (t instanceof RuntimeException)
  
  
  



More information about the jboss-cvs-commits mailing list