[Jboss-cvs] JBossAS SVN: r56086 - trunk/cluster/src/main/org/jboss/ha/framework/server

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 18 19:02:10 EDT 2006


Author: bstansberry at jboss.com
Date: 2006-08-18 19:02:09 -0400 (Fri, 18 Aug 2006)
New Revision: 56086

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java
Log:
[JBAS-3470] Inject TreeCache into DS
Don't let notification failures affect others

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java	2006-08-18 23:01:38 UTC (rev 56085)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java	2006-08-18 23:02:09 UTC (rev 56086)
@@ -30,19 +30,17 @@
 import java.util.Iterator;
 import java.util.Set;
 import java.util.HashSet;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
 
 import org.jboss.ha.framework.interfaces.HAPartition;
 import org.jboss.logging.Logger;
-import org.jboss.system.Registry;
+import org.jboss.system.ServiceMBeanSupport;
 import org.jboss.cache.TreeCache;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.TreeCacheListener;
 import org.jboss.cache.CacheException;
 import org.jboss.cache.Node;
-import org.jboss.cache.PropertyConfigurator;
 import org.jboss.cache.ExtendedTreeCacheListener;
+import org.jboss.cache.TreeCacheMBean;
 import org.jgroups.View;
 
 /**
@@ -54,6 +52,7 @@
  * @version $Revision$
  */
 public class DistributedStateImpl
+   extends ServiceMBeanSupport
    implements DistributedStateImplMBean, TreeCacheListener, ExtendedTreeCacheListener
 {
    // Constants -----------------------------------------------------
@@ -68,9 +67,9 @@
    protected HashMap keyListeners = new HashMap ();
    protected HAPartition partition;
    protected Logger log;
-   protected MBeanServer mbeanServer = null;
+//   protected MBeanServer mbeanServer = null;
    protected String name = null;
-   TreeCache cache;
+   protected TreeCacheMBean cache;
 
    public static final String ROOT = "__DISTRIBUTED_STATE__";
 
@@ -82,66 +81,73 @@
 
    // Constructors --------------------------------------------------
 
-   public DistributedStateImpl () {} // for JMX checks
-
-   public DistributedStateImpl (HAPartition partition, MBeanServer server)
+   public DistributedStateImpl () 
    {
-      this.partition = partition;
-      this.mbeanServer = server;
+      super();
       this.log = Logger.getLogger (this.getClass ());
    }
 
    // Public --------------------------------------------------------
 
-   public void init () throws Exception
+   
+//   public void init () throws Exception
+//   {
+//      ObjectName name = new ObjectName("jboss.cache:service=ClusterTreeCache");
+//      cache = null;
+//      if (name == null) {
+//         log.debug("DistributedState - failed to get name for ClusterTreeCache MBean");
+//      }
+//      else {
+//         String method = "getInstance";
+//         Object o = mbeanServer.invoke(name, method, null, null);
+//         if (o == null) {
+//            log.debug("DistributedState - ClusterTreeCache instance is null");
+//         }
+//         else {
+//            log.debug("DistributedState - ClusterTreeCache instance is "+o.getClass().getName());
+//            cache = (TreeCache)o;
+//         }
+//      }
+//      cache.addTreeCacheListener(this);
+//
+//      // subscribed this "sub-service" of HAPartition with JMX
+//      // TODO: In the future (when state transfer issues will be completed),
+//      // we will need to redesign the way HAPartitions and its sub-protocols are
+//      // registered with JMX. They will most probably be independant JMX services.
+//      //
+//      this.name = "jboss:service=" + SERVICE_NAME +
+//                    ",partitionName=" + this.partition.getPartitionName();
+//      ObjectName jmxName = new ObjectName(this.name);
+//      mbeanServer.registerMBean(this, jmxName);
+//      Registry.bind (this.name, this);
+//   }
+
+   protected void createService() throws Exception
    {
-      ObjectName name = new ObjectName("jboss.cache:service=ClusterTreeCache");
-      cache = null;
-      if (name == null) {
-         log.debug("DistributedState - failed to get name for ClusterTreeCache MBean");
-      }
-      else {
-         String method = "getInstance";
-         Object o = mbeanServer.invoke(name, method, null, null);
-         if (o == null) {
-            log.debug("DistributedState - ClusterTreeCache instance is null");
-         }
-         else {
-            log.debug("DistributedState - ClusterTreeCache instance is "+o.getClass().getName());
-            cache = (TreeCache)o;
-         }
-      }
+      super.createService();
       cache.addTreeCacheListener(this);
-
-      // subscribed this "sub-service" of HAPartition with JMX
-      // TODO: In the future (when state transfer issues will be completed),
-      // we will need to redesign the way HAPartitions and its sub-protocols are
-      // registered with JMX. They will most probably be independant JMX services.
-      //
-      this.name = "jboss:service=" + SERVICE_NAME +
-                    ",partitionName=" + this.partition.getPartitionName();
-      ObjectName jmxName = new ObjectName(this.name);
-      mbeanServer.registerMBean(this, jmxName);
-      Registry.bind (this.name, this);
    }
 
-   public void start () throws Exception
+   public void startService() throws Exception
    {
+      super.startService();
    }
 
-   public void stop () throws Exception
+   public void stopService() throws Exception
    {
+      super.stopService();
       // JBCLUSTER-38 move to destroy
 //      Registry.unbind (this.name);
 //      ObjectName jmxName = new ObjectName(this.name);
 //      mbeanServer.unregisterMBean (jmxName);
    }
    
-   public void destroy() throws Exception
+   public void destroyService() throws Exception
    {
-      Registry.unbind (this.name);
-      ObjectName jmxName = new ObjectName(this.name);
-      mbeanServer.unregisterMBean (jmxName);
+      super.destroyService();
+//      Registry.unbind (this.name);
+//      ObjectName jmxName = new ObjectName(this.name);
+//      mbeanServer.unregisterMBean (jmxName);
       
    }
 
@@ -205,33 +211,43 @@
       return result.toString ();
    }
 
+   public TreeCacheMBean getTreeCache()
+   {
+      return cache;
+   }
+
+   public void setTreeCache(TreeCacheMBean cache)
+   {
+      this.cache = cache;      
+   }
+
    // DistributedState implementation ----------------------------------------------
 
-/*
-	 * (non-Javadoc)
-	 *
-	 * @see org.jboss.ha.framework.interfaces.DistributedState#set(java.lang.String,
-	 *      java.io.Serializable, java.io.Serializable)
-	 */
-public void set(String category, Serializable key, Serializable value)
-      throws Exception {
-   cache.put(buildFqn(category), key, value);
-   notifyKeyListeners (category, key, value, true);
-}
+   /*
+	* (non-Javadoc)
+	*
+	* @see org.jboss.ha.framework.interfaces.DistributedState#set(java.lang.String,
+	*      java.io.Serializable, java.io.Serializable)
+	*/
+   public void set(String category, Serializable key, Serializable value)
+         throws Exception {
+      cache.put(buildFqn(category), key, value);
+      notifyKeyListeners (category, key, value, true);
+   }
 
-/*
- * (non-Javadoc)
- *
- * @see org.jboss.ha.framework.interfaces.DistributedState#set(java.lang.String,
- *      java.io.Serializable, java.io.Serializable, boolean) @param
- *      asynchronousCall is not supported yet. TreeCache cannot switch this
- *      on the fly. Will take value from TreeCache-config instead.
- */
-public void set(String category, Serializable key, Serializable value,
-      boolean asynchronousCall) throws Exception {
-   // TODO does not support asynchronousCall yet. TreeCache cannot switch this on the fly
-   set(category, key, value);
-}
+   /*
+    * (non-Javadoc)
+    *
+    * @see org.jboss.ha.framework.interfaces.DistributedState#set(java.lang.String,
+    *      java.io.Serializable, java.io.Serializable, boolean) @param
+    *      asynchronousCall is not supported yet. TreeCache cannot switch this
+    *      on the fly. Will take value from TreeCache-config instead.
+    */
+   public void set(String category, Serializable key, Serializable value,
+         boolean asynchronousCall) throws Exception {
+      // TODO does not support asynchronousCall yet. TreeCache cannot switch this on the fly
+      set(category, key, value);
+   }
 
    /*
      * (non-Javadoc)
@@ -475,15 +491,24 @@
     * @param pre
     * @param isLocal
     * @see TreeCacheListener#nodeRemoved(Fqn)
+    * 
+    * FIXME JBAS-3473
     */
    public void nodeRemove(Fqn fqn, boolean pre, boolean isLocal) {
       if (pre  && fqn.isChildOf(ROOTFQN) && fqn.size() == ROOTFQNSIZE + 2) {
          String category = (String) fqn.get(ROOTFQNSIZE);
          Serializable key = (Serializable) fqn.get(ROOTFQNSIZE + 1);
-         Serializable value = (Serializable) cache.peek(fqn);
-         // show value about to be deleted
-         notifyKeyListenersOfRemove(category, key, value, isLocal);
-
+         try
+         {
+            Serializable value = (Serializable) cache.get(fqn);
+            // show value about to be deleted
+            notifyKeyListenersOfRemove(category, key, value, isLocal);
+         }
+         catch (CacheException e)
+         {
+            log.error("Caught exception getting value for category " + category +
+                      ", key " + key);
+         }
       }
    }
 
@@ -501,10 +526,19 @@
       if (!pre  && fqn.isChildOf(ROOTFQN) && fqn.size() == ROOTFQNSIZE + 2) {
          String category = (String) fqn.get(ROOTFQNSIZE);
          Serializable key = (Serializable)fqn.get(ROOTFQNSIZE + 1);
-         Serializable value = (Serializable) cache.peek(fqn);
-         if (value != null) {  // show new value
-            notifyKeyListeners(category, key, value, isLocal);
+         try
+         {
+            Serializable value = (Serializable) cache.get(fqn);
+            
+            if (value != null) {  // show new value
+               notifyKeyListeners(category, key, value, isLocal);
+            }
          }
+         catch (CacheException e)
+         {
+            log.error("Caught exception getting value for category " + category +
+                      ", key " + key);
+         }
       }
    }
 




More information about the jboss-cvs-commits mailing list