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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 16 14:23:48 EST 2007


Author: jerrygauth
Date: 2007-01-16 14:23:47 -0500 (Tue, 16 Jan 2007)
New Revision: 59679

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java
Log:
JBAS-3473

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java	2007-01-16 19:17:59 UTC (rev 59678)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedStateImpl.java	2007-01-16 19:23:47 UTC (rev 59679)
@@ -113,7 +113,7 @@
 //      // 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.
+//      // registered with JMX. They will most probably be independent JMX services.
 //      //
 //      this.name = "jboss:service=" + SERVICE_NAME +
 //                    ",partitionName=" + this.partition.getPartitionName();
@@ -231,9 +231,9 @@
 	*      java.io.Serializable, java.io.Serializable)
 	*/
    public void set(String category, Serializable key, Serializable value)
-         throws Exception {
+         throws Exception
+   {
       cache.put(buildFqn(category), key, value);
-      notifyKeyListeners (category, key, value, true);
    }
 
    /*
@@ -245,7 +245,8 @@
     *      on the fly. Will take value from TreeCache-config instead.
     */
    public void set(String category, Serializable key, Serializable value,
-         boolean asynchronousCall) throws Exception {
+         boolean asynchronousCall) throws Exception
+   {
       // TODO does not support asynchronousCall yet. TreeCache cannot switch this on the fly
       set(category, key, value);
    }
@@ -258,7 +259,8 @@
      *      CacheException
      */
    public Serializable remove(String category, Serializable key)
-         throws Exception {
+         throws Exception
+   {
       return remove(category, key, true);
    }
 
@@ -272,14 +274,14 @@
     *      CacheException!
     */
    public Serializable remove(String category, Serializable key,
-         boolean asynchronousCall) throws Exception {
+         boolean asynchronousCall) throws Exception
+   {
       Serializable retVal = get(category, key);
-      if(retVal != null){
+      if(retVal != null)
+      {
          cache.remove(buildFqn(category), key);
-         notifyKeyListenersOfRemove(category, key, retVal, true);
       }
-
-		return retVal;
+	  return retVal;
 	}
 
    /*
@@ -288,26 +290,31 @@
      * @see org.jboss.ha.framework.interfaces.DistributedState#get(java.lang.String,
      *      java.io.Serializable)
      */
-   public Serializable get(String category, Serializable key) {
-      try {
+   public Serializable get(String category, Serializable key)
+   {
+      try
+      {
          return (Serializable) cache.get(buildFqn(category), key);
-      } catch (CacheException ce) {
+      } catch (CacheException ce)
+      {
          return null;
-		}
+	  }
+   }
 
-	}
-
    public Collection getAllCategories ()
    {
-      try {
+      try
+      {
          Node base = cache.getRoot().getChild(ROOTFQN);
          Collection keys = (base == null ? null : base.getChildrenNames());
-         if(keys != null && keys.size() > 0) {
+         if(keys != null && keys.size() > 0)
+         {
             keys = Collections.unmodifiableCollection(keys);
          }
          return keys;
       }
-      catch(CacheException ce) {
+      catch(CacheException ce)
+      {
          return null;
       }
    }
@@ -318,16 +325,19 @@
      * @see org.jboss.ha.framework.interfaces.DistributedState#getAllKeys(java.lang.String)
      *      @return - returns null in case of CacheException
      */
-   public Collection getAllKeys(String category) {
-      try {
+   public Collection getAllKeys(String category)
+   {
+      try
+      {
          Node node = getNode(category);
          if (node==null)
             return null;
          return node.getKeys();
-      } catch (CacheException ce) {
+      } catch (CacheException ce)
+      {
          return null;
-		}
-	}
+      }
+   }
 
    /*
      * (non-Javadoc)
@@ -335,14 +345,17 @@
      * @see org.jboss.ha.framework.interfaces.DistributedState#getAllValues(java.lang.String)
      *      @return - returns null in case of CacheException
      */
-   public Collection getAllValues(String category) {
-      try {
+   public Collection getAllValues(String category)
+   {
+      try
+      {
          Node categoryNode = getNode(category);
          if (categoryNode == null) {
             return null;
          }
          Set childNodes = categoryNode.getKeys();
-         if (childNodes == null) {
+         if (childNodes == null)
+         {
             return null;
          }
          Map entries = categoryNode.getData();
@@ -350,10 +363,11 @@
             return null;
          Collection retVal = new HashSet(entries.values());
          return Collections.unmodifiableCollection(retVal);
-      } catch (CacheException ce) {
+      } catch (CacheException ce)
+      {
          return null;
-		}
-	}
+      }
+   }
 
 
    public void registerDSListenerEx (String category, DSListenerEx subscriber)
@@ -469,19 +483,23 @@
 
 
    // Private -------------------------------------------------------
-   protected Fqn buildFqn(String category) {
+   protected Fqn buildFqn(String category)
+   {
       return new Fqn(ROOTFQN, category);
    }
 
-   protected Fqn buildFqn(String category, Serializable key) {
+   protected Fqn buildFqn(String category, Serializable key)
+   {
       return new Fqn(new Object[] { ROOT, category, key });
    }
 
-   protected Fqn buildFqn(String category, Serializable key, Serializable value) {
+   protected Fqn buildFqn(String category, Serializable key, Serializable value)
+   {
       return new Fqn(new Object[] { ROOT, category, key, value });
    }
 
-   protected Node getNode(String category) throws CacheException {
+   protected Node getNode(String category) throws CacheException
+   {
       return cache.getRoot().getChild(buildFqn(category));
    }
 
@@ -489,56 +507,30 @@
    
    private class DSCacheListener extends AbstractCacheListener
    {
-
-      /**
-       * 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);
-      }
-
       public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data) {
          
+         // we don't want pre-notifications or changes for other roots in a shared cache
          if (pre || !fqn.isChildOf(ROOTFQN))
             return;
          
-         //System.out.println("*** DistributedStateImpl.nodeModified; fqn="+fqn+"; pre="+pre+"; isLocal="+isLocal);
-         // for now, just return category name
-         DistributedStateImpl.this.notifyKeyListeners((String)fqn.get(ROOTFQNSIZE), "", "", isLocal);
+         // we're only interested in put and remove data operations
+         if (!modType.equals(ModificationType.PUT_DATA) && !modType.equals(ModificationType.REMOVE_DATA))
+            return;
+         
+         Serializable key = null;
+         Serializable value = null;
+         
+         // there should be exactly one key/value pair in the map
+         if (data != null && !data.isEmpty())
+         {
+            key = (Serializable)data.keySet().iterator().next();
+            value = (Serializable)data.get(key);
+         }        
+         
+         if (modType.equals(ModificationType.PUT_DATA))
+               DistributedStateImpl.this.notifyKeyListeners((String)fqn.get(ROOTFQNSIZE), key, value, isLocal);
+         else
+            DistributedStateImpl.this.notifyKeyListenersOfRemove((String)fqn.get(ROOTFQNSIZE), key, value, isLocal);
       }
    }
 




More information about the jboss-cvs-commits mailing list