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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Nov 18 06:29:35 EST 2006


Author: bstansberry at jboss.com
Date: 2006-11-18 06:29:33 -0500 (Sat, 18 Nov 2006)
New Revision: 58569

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java
   trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImplMBean.java
Log:
Use JBC 2.0 API

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java	2006-11-18 11:28:53 UTC (rev 58568)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java	2006-11-18 11:29:33 UTC (rev 58569)
@@ -27,21 +27,19 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Set;
-import java.util.HashSet;
 
+import org.jboss.cache.AbstractCacheListener;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
 import org.jboss.ha.framework.interfaces.HAPartition;
 import org.jboss.logging.Logger;
 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.ExtendedTreeCacheListener;
-import org.jboss.cache.TreeCacheMBean;
-import org.jgroups.View;
 
 /**
  *   This class manages distributed state across the cluster.
@@ -53,7 +51,7 @@
  */
 public class DistributedStateImpl
    extends ServiceMBeanSupport
-   implements DistributedStateImplMBean, TreeCacheListener, ExtendedTreeCacheListener
+   implements DistributedStateImplMBean
 {
    // Constants -----------------------------------------------------
 
@@ -69,7 +67,8 @@
    protected Logger log;
 //   protected MBeanServer mbeanServer = null;
    protected String name = null;
-   protected TreeCacheMBean cache;
+   protected Cache cache;
+   private DSCacheListener cacheListener;
 
    public static final String ROOT = "__DISTRIBUTED_STATE__";
 
@@ -85,6 +84,7 @@
    {
       super();
       this.log = Logger.getLogger (this.getClass ());
+      this.cacheListener = new DSCacheListener();
    }
 
    // Public --------------------------------------------------------
@@ -145,6 +145,7 @@
    public void destroyService() throws Exception
    {
       super.destroyService();
+      cache.removeCacheListener(cacheListener);
 //      Registry.unbind (this.name);
 //      ObjectName jmxName = new ObjectName(this.name);
 //      mbeanServer.unregisterMBean (jmxName);
@@ -211,15 +212,15 @@
       return result.toString ();
    }
 
-   public TreeCacheMBean getTreeCache()
+   public Cache getClusteredCache()
    {
       return cache;
    }
 
-   public void setTreeCache(TreeCacheMBean cache)
+   public void setClusteredCache(Cache cache)
    {
       this.cache = cache;
-      this.cache.addTreeCacheListener(this);
+      this.cache.addCacheListener(cacheListener);
    }
 
    // DistributedState implementation ----------------------------------------------
@@ -300,7 +301,8 @@
    public Collection getAllCategories ()
    {
       try {
-         Collection keys=cache.getChildrenNames(ROOTFQN);
+         Node base = cache.getChild(ROOTFQN);
+         Collection keys = (base == null ? null : base.getChildrenNames());
          if(keys != null && keys.size() > 0) {
             keys = Collections.unmodifiableCollection(keys);
          }
@@ -320,9 +322,9 @@
    public Collection getAllKeys(String category) {
       try {
          Node nodeLogger = getLogger(category);
-         if (nodeLogger==null || nodeLogger.getDataKeys() == null)
+         if (nodeLogger==null)
             return null;
-         return Collections.unmodifiableCollection(nodeLogger.getDataKeys());
+         return nodeLogger.getKeys();
       } catch (CacheException ce) {
          return null;
 		}
@@ -340,17 +342,14 @@
          if (categoryNode == null) {
             return null;
          }
-         Set childNodes = categoryNode.getDataKeys();
+         Set childNodes = categoryNode.getKeys();
          if (childNodes == null) {
             return null;
          }
-         Collection retVal = new HashSet();
-         Iterator it = childNodes.iterator();
-         while (it.hasNext()) {
-            Object value = categoryNode.get(it.next());
-            if (value != null)
-               retVal.add(value);
-         }
+         Map entries = categoryNode.getData();
+         if (entries == null)
+            return null;
+         Collection retVal = new HashSet(entries.values());
          return Collections.unmodifiableCollection(retVal);
       } catch (CacheException ce) {
          return null;
@@ -470,172 +469,6 @@
    /** ExtendedTreeCacheListener methods */
 
 
-   /**
-    * Called when a node is about to be evicted or has been evicted from the
-    * in-memory cache.
-    * Note: Currently TreeCacheListener has {@link TreeCacheListener#nodeEvicted(Fqn)}
-    * which will be merged with method in release 1.3.
-    *
-    * @param fqn
-    * @param pre
-    * @see TreeCacheListener#nodeEvicted(Fqn)
-    */
-   public void nodeEvict(Fqn fqn, boolean pre) {}
-
-   /**
-    * Called when a node is about to be removed or has been removed from the
-    * in-memory cache.
-    * Note: Currently TreeCacheListener has {@link TreeCacheListener#nodeRemoved(Fqn)}
-    * which will be merged with this method in release 1.3.
-    *
-    * @param fqn
-    * @param pre
-    * @param isLocal
-    * @see TreeCacheListener#nodeRemoved(Fqn)
-    * 
-    * FIXME JBAS-3473
-    */
-   public void nodeRemove(Fqn fqn, boolean pre, boolean isLocal) {
-      // we're not interested in pre events or changes to another root in a shared cache instance
-      // we're also not interested in local changes as we issue our own notification
-      if (isLocal || pre || !fqn.isChildOf(ROOTFQN))
-         return;
-      
-      // this logic currently doesn't work because key isn't stored as a node
-      /*
-      if (fqn.size() == ROOTFQNSIZE + 2) {
-         String category = (String) fqn.get(ROOTFQNSIZE);
-         Serializable key = (Serializable) fqn.get(ROOTFQNSIZE + 1);
-         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);
-         }
-      }
-      */
-      // for now, just return category name
-      notifyKeyListenersOfRemove((String)fqn.get(ROOTFQNSIZE), "", "", isLocal);
-   }
-
-   /**
-    * Called when a node is about to be modified or has been modified.
-    * Note: Currently TreeCacheListener has {@link TreeCacheListener#nodeModified(Fqn)}
-    * which will be merged with this method in release 1.3.
-    *
-    * @param fqn
-    * @param pre
-    * @param isLocal
-    * @see TreeCacheListener#nodeModified(Fqn)
-    */
-   public void nodeModify(Fqn fqn, boolean pre, boolean isLocal) {
-      // we're not interested in pre events or changes to another root in a shared cache instance
-      // we're also not interested in local changes as we issue our own notification
-      if (isLocal || pre || !fqn.isChildOf(ROOTFQN))
-         return;
-      
-      // this logic currently doesn't work because key isn't stored as a node
-      /*
-      if (fqn.size() == ROOTFQNSIZE + 2) {
-         String category = (String) fqn.get(ROOTFQNSIZE);
-         Serializable key = (Serializable)fqn.get(ROOTFQNSIZE + 1);
-         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);
-         }     
-      }
-      */
-      // for now, just return category name
-      notifyKeyListeners((String)fqn.get(ROOTFQNSIZE), "", "", isLocal);
-   }
-
-   /** TreeCacheListener methods */
-
-     /**
-    * Called when a node is created
-    * @param fqn
-    */
-   public void nodeCreated(Fqn fqn) {}
-
-   /**
-    * Called when a node is removed.
-    * @param fqn
-    */
-   public void nodeRemoved(Fqn fqn) {}
-
-   /**
-    * Called when a node is loaded into memory via the CacheLoader. This is not the same
-    * as {@link #nodeCreated(Fqn)}.
-    */
-   public void nodeLoaded(Fqn fqn) {}
-
-   /**
-    * Called when a node is evicted (not the same as remove()).
-    * @param fqn
-    */
-   public void nodeEvicted(Fqn fqn) {}
-
-   /**
-    * Called when a node is modified, e.g., one (key, value) pair
-    * in the internal map storage has been modified.
-    * @param fqn
-    */
-   public void nodeModified(Fqn fqn) {}
-
-   /**
-    * Called when a node is visisted, i.e., get().
-    * @param fqn
-    */
-   public void nodeVisited(Fqn fqn) {}
-
-   /**
-    * Called when the cache is started.
-    * @param cache
-    */
-   public void cacheStarted(TreeCache cache) {}
-
-   /**
-    * Called when the cache is stopped.
-    * @param cache
-    */
-   public void cacheStopped(TreeCache cache) {}
-
-   public void viewChange(View new_view) {} // might be MergeView after merging
-
-   /**
-    * Called when a node is to be or has been activated into memory via the
-    * CacheLoader that was evicted earlier.
-    *
-    * @param fqn
-    * @param pre
-    */
-   public void nodeActivate(Fqn fqn, boolean pre) {}
-
-   /**
-    * Called when a node is to be or has been written to the backend store via the
-    * cache loader due to a node eviction by the eviction policy provider
-    *
-    * @param fqn
-    * @param pre
-    */
-   public void nodePassivate(Fqn fqn, boolean pre) {}
-
-
-
    // Private -------------------------------------------------------
    protected Fqn buildFqn(String category) {
       return new Fqn(ROOTFQN, category);
@@ -649,10 +482,107 @@
       return new Fqn(new Object[] { ROOT, category, key, value });
    }
 
+   // FIXME Why is this method named "getLogger"???  Suspect a bug here!
    protected Node getLogger(String category) throws CacheException {
-      return cache.get(buildFqn(category));
+      return cache.getChild(buildFqn(category));
    }
 
    // Inner classes -------------------------------------------------
+   
+   private class DSCacheListener extends AbstractCacheListener
+   {
+      /**
+       * Called when a node is about to be evicted or has been evicted from the
+       * in-memory cache.
+       * Note: Currently TreeCacheListener has {@link TreeCacheListener#nodeEvicted(Fqn)}
+       * which will be merged with method in release 1.3.
+       *
+       * @param fqn
+       * @param pre
+       * @see TreeCacheListener#nodeEvicted(Fqn)
+       */
+      public void nodeEvict(Fqn fqn, boolean pre) {}
 
+      /**
+       * Called when a node is about to be removed or has been removed from the
+       * in-memory cache.
+       * Note: Currently TreeCacheListener has {@link TreeCacheListener#nodeRemoved(Fqn)}
+       * which will be merged with this method in release 1.3.
+       *
+       * @param fqn
+       * @param pre
+       * @param isLocal
+       * @see TreeCacheListener#nodeRemoved(Fqn)
+       * 
+       * FIXME JBAS-3473
+       */
+      public void nodeRemove(Fqn fqn, boolean pre, boolean isLocal) {
+         // we're not interested in pre events or changes to another root in a shared cache instance
+         // we're also not interested in local changes as we issue our own notification
+         if (isLocal || pre || !fqn.isChildOf(ROOTFQN))
+            return;
+         
+         // this logic currently doesn't work because key isn't stored as a node
+         /*
+         if (fqn.size() == ROOTFQNSIZE + 2) {
+            String category = (String) fqn.get(ROOTFQNSIZE);
+            Serializable key = (Serializable) fqn.get(ROOTFQNSIZE + 1);
+            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);
+            }
+         }
+         */
+         // for now, just return category name
+         DistributedStateImpl.this.notifyKeyListenersOfRemove((String)fqn.get(ROOTFQNSIZE), "", "", isLocal);
+      }
+
+      /**
+       * Called when a node is about to be modified or has been modified.
+       * Note: Currently TreeCacheListener has {@link TreeCacheListener#nodeModified(Fqn)}
+       * which will be merged with this method in release 1.3.
+       *
+       * @param fqn
+       * @param pre
+       * @param isLocal
+       * @see TreeCacheListener#nodeModified(Fqn)
+       */
+      public void nodeModify(Fqn fqn, boolean pre, boolean isLocal) {
+         // we're not interested in pre events or changes to another root in a shared cache instance
+         // we're also not interested in local changes as we issue our own notification
+         if (isLocal || pre || !fqn.isChildOf(ROOTFQN))
+            return;
+         
+         // this logic currently doesn't work because key isn't stored as a node
+         /*
+         if (fqn.size() == ROOTFQNSIZE + 2) {
+            String category = (String) fqn.get(ROOTFQNSIZE);
+            Serializable key = (Serializable)fqn.get(ROOTFQNSIZE + 1);
+            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);
+            }     
+         }
+         */
+         // for now, just return category name
+         DistributedStateImpl.this.notifyKeyListeners((String)fqn.get(ROOTFQNSIZE), "", "", isLocal);
+      }      
+   }
+
 }

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImplMBean.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImplMBean.java	2006-11-18 11:28:53 UTC (rev 58568)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImplMBean.java	2006-11-18 11:29:33 UTC (rev 58569)
@@ -21,7 +21,7 @@
   */
 package org.jboss.ha.framework.server;
 
-import org.jboss.cache.TreeCacheMBean;
+import org.jboss.cache.Cache;
 
 /**
  * @author  <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
@@ -40,6 +40,6 @@
    String listContent () throws Exception;
    String listXmlContent () throws Exception;
    
-   TreeCacheMBean getTreeCache();
-   void setTreeCache(TreeCacheMBean cache);
+   Cache getClusteredCache();
+   void setClusteredCache(Cache cache);
 }




More information about the jboss-cvs-commits mailing list