[jboss-cvs] JBossAS SVN: r90101 - projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 11 12:36:50 EDT 2009


Author: alesj
Date: 2009-06-11 12:36:50 -0400 (Thu, 11 Jun 2009)
New Revision: 90101

Added:
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java
Modified:
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java
Log:
[JBDEPLOY-192]; fix interaction between metadata and synch checker.
TODO - on tests.

Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java (from rev 89985, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java	2009-06-11 16:36:50 UTC (rev 90101)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.deployers.vfs.spi.structure.modified;
+
+import java.util.Set;
+
+/**
+ * Abstract structure cache.
+ * Used as a bridge between possible changes/updates.
+ *
+ * @param <T> exact cache value type
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractStructureCache<T> implements StructureCache<T>
+{
+   public Set<String> getLeaves(String pathName)
+   {
+      return getLeaves(pathName, null);
+   }
+}
\ No newline at end of file

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java	2009-06-11 16:12:38 UTC (rev 90100)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java	2009-06-11 16:36:50 UTC (rev 90101)
@@ -22,6 +22,7 @@
 package org.jboss.deployers.vfs.spi.structure.modified;
 
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
 import org.jboss.virtual.VisitorAttributes;
 
 /**
@@ -36,7 +37,12 @@
 
    public AddVisitor(VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile tempRoot, int initialPathLenght)
    {
-      super(attributes, cache, synchAdapter);
+      this(null, attributes, cache, synchAdapter, tempRoot, initialPathLenght);
+   }
+
+   public AddVisitor(VirtualFileFilter filter, VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile tempRoot, int initialPathLenght)
+   {
+      super(filter, attributes, cache, synchAdapter);
       if (tempRoot == null)
          throw new IllegalArgumentException("Null temp root");
       if (initialPathLenght < 0)

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java	2009-06-11 16:12:38 UTC (rev 90100)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java	2009-06-11 16:36:50 UTC (rev 90101)
@@ -35,7 +35,7 @@
  * @param <T> exact cache value type
  * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  */
-public class DefaultStructureCache<T> implements StructureCache<T>
+public class DefaultStructureCache<T> extends AbstractStructureCache<T>
 {
    private Map<String, T> map = new ConcurrentHashMap<String, T>();
 
@@ -53,13 +53,14 @@
       return map.get(pathName);
    }
 
-   public Set<String> getLeaves(String pathName)
+   public Set<String> getLeaves(String pathName, StructureCacheFilter filter)
    {
       Set<String> result = null;
       Pattern pattern = Pattern.compile(pathName + "/[^/]+");
       for (String key : map.keySet())
       {
-         if (pattern.matcher(key).matches())
+         // first the pattern should match, only then we check the filter
+         if (pattern.matcher(key).matches() && (filter == null || filter.accepts(key)))
          {
             if (result == null)
                result = new HashSet<String>();

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java	2009-06-11 16:12:38 UTC (rev 90100)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java	2009-06-11 16:36:50 UTC (rev 90101)
@@ -46,6 +46,9 @@
    /** The metadata filter */
    private VirtualFileFilter filter;
 
+   /** The structure cache filter */
+   private StructureCacheFilter cacheFilter;
+
    public MetaDataStructureModificationChecker(MainDeployerStructure mainDeployer)
    {
       super(mainDeployer);
@@ -61,6 +64,27 @@
       this.filter = filter;
    }
 
+   /**
+    * Set the structure cache filter.
+    *
+    * @param cacheFilter the cache filter
+    */
+   public void setCacheFilter(StructureCacheFilter cacheFilter)
+   {
+      this.cacheFilter = cacheFilter;
+   }
+
+   /**
+    * Check filters.
+    */
+   public void start()
+   {
+      if (cacheFilter == null && filter instanceof StructureCacheFilter)
+      {
+         cacheFilter = (StructureCacheFilter) filter;
+      }
+   }
+
    @Override
    protected boolean hasRootBeenModified(VirtualFile root) throws IOException
    {
@@ -143,7 +167,7 @@
                {
                   List<VirtualFile> children = mdpVF.getChildren(filter);
                   String mdpPathName = mdpVF.getPathName();
-                  Set<String> leaves = getCache().getLeaves(mdpPathName);
+                  Set<String> leaves = getCache().getLeaves(mdpPathName, cacheFilter);
                   // do we have some new files or some were deleted
                   if (leaves != null && children != null && leaves.size() != children.size())
                   {

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java	2009-06-11 16:12:38 UTC (rev 90100)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java	2009-06-11 16:36:50 UTC (rev 90101)
@@ -68,6 +68,19 @@
    Set<String> getLeaves(String pathName);
 
    /**
+    * Get filtered leaves for this path name parameter.
+    * Only exact sub path nodes count in.
+    *
+    * This method should return a mutable Set copy
+    * as we intend to modify it in checker processing.
+    *
+    * @param pathName the path name
+    * @param filter the leaves path filter
+    * @return sub-paths nodes or null if no such match yet
+    */
+   Set<String> getLeaves(String pathName, StructureCacheFilter filter);
+
+   /**
     * Invalidate cache for path name.
     *
     * @param pathName the path name

Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java (from rev 89985, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java	2009-06-11 16:36:50 UTC (rev 90101)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.deployers.vfs.spi.structure.modified;
+
+/**
+ * Simple structure cache filter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface StructureCacheFilter
+{
+   /**
+    * Do we accept the path.
+    *
+    * @param path the full path
+    * @return true if the path is accepted, false otherwise
+    */
+   boolean accepts(String path);
+}
\ No newline at end of file

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java	2009-06-11 16:12:38 UTC (rev 90100)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java	2009-06-11 16:36:50 UTC (rev 90101)
@@ -22,9 +22,10 @@
 package org.jboss.deployers.vfs.spi.structure.modified;
 
 import org.jboss.logging.Logger;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VisitorAttributes;
 import org.jboss.virtual.VirtualFileVisitor;
-import org.jboss.virtual.VisitorAttributes;
-import org.jboss.virtual.VirtualFile;
 
 /**
  * Synch file visitor.
@@ -35,17 +36,24 @@
 {
    protected final Logger log = Logger.getLogger(getClass());
 
+   private VirtualFileFilter filter;
    private VisitorAttributes attributes;
    private StructureCache<Long> cache;
    private SynchAdapter synchAdapter;
 
    protected SynchVisitor(VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter)
    {
+      this(null, attributes, cache, synchAdapter);
+   }
+
+   protected SynchVisitor(VirtualFileFilter filter, VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter)
+   {
       if (cache == null)
          throw new IllegalArgumentException("Null cache");
       if (synchAdapter == null)
          throw new IllegalArgumentException("Null synch adapter");
 
+      this.filter = filter;
       if (attributes != null)
          this.attributes = attributes;
       else
@@ -63,7 +71,10 @@
    {
       try
       {
-         doVisit(file);
+         if (filter == null || filter.accepts(file))
+         {
+            doVisit(file);
+         }
       }
       catch (Exception e)
       {

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java	2009-06-11 16:12:38 UTC (rev 90100)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java	2009-06-11 16:36:50 UTC (rev 90101)
@@ -23,9 +23,10 @@
 
 import java.io.IOException;
 
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
-import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
 import org.jboss.virtual.VisitorAttributes;
 
 /**
@@ -42,6 +43,9 @@
    /** The true checker delegate */
    private AbstractStructureModificationChecker<Long> delegate;
 
+   /** The filter */
+   private VirtualFileFilter filter;
+
    /** The synch adapter */
    private SynchAdapter synchAdapter;
 
@@ -85,11 +89,11 @@
       if (modified == false && root != deploymentContext.getRoot())
       {
          // check for update or delete
-         UpdateDeleteVisitor udVisitor = new UpdateDeleteVisitor(tempAttributes, getCache(), synchAdapter, root);
+         UpdateDeleteVisitor udVisitor = new UpdateDeleteVisitor(filter, tempAttributes, getCache(), synchAdapter, root);
          VirtualFile tempRoot = deploymentContext.getRoot();
          tempRoot.visit(udVisitor);
          // check for addition
-         AddVisitor addVisitor = new AddVisitor(originalAttributes, getCache(), synchAdapter, tempRoot, root.getPathName().length());
+         AddVisitor addVisitor = new AddVisitor(filter, originalAttributes, getCache(), synchAdapter, tempRoot, root.getPathName().length());
          root.visit(addVisitor);
       }
       return modified;
@@ -106,6 +110,16 @@
    }
 
    /**
+    * Set the filter.
+    *
+    * @param filter the filter
+    */
+   public void setFilter(VirtualFileFilter filter)
+   {
+      this.filter = filter;
+   }
+
+   /**
     * Set original visitor attributes.
     *
     * @param attributes the attributes

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java	2009-06-11 16:12:38 UTC (rev 90100)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java	2009-06-11 16:36:50 UTC (rev 90101)
@@ -39,7 +39,7 @@
  * @param <T> exact value type
  * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  */
-public class TreeStructureCache<T> implements StructureCache<T>
+public class TreeStructureCache<T> extends AbstractStructureCache<T>
 {
    /** The tree root */
    private final Node<T> root = createRoot();
@@ -84,10 +84,33 @@
       return (node != null ? node.getValue() : null);
    }
 
-   public Set<String> getLeaves(String pathName)
+   public Set<String> getLeaves(String pathName, StructureCacheFilter filter)
    {
       Node<T> node = getNode(pathName);
-      return (node != null) ? node.getChildrenNames() : null;
+      if (node != null)
+      {
+         Set<String> children = node.getChildrenNames();
+         if (filter != null && children != null && children.isEmpty() == false)
+         {
+            Set<String> result = new HashSet<String>();
+            for (String child : children)
+            {
+               if (filter.accepts(child))
+               {
+                  result.add(child);
+               }
+            }
+            return result;
+         }
+         else
+         {
+            return children;
+         }
+      }
+      else
+      {
+         return null;
+      }
    }
 
    public void invalidateCache(String pathName)

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java	2009-06-11 16:12:38 UTC (rev 90100)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java	2009-06-11 16:36:50 UTC (rev 90101)
@@ -22,6 +22,7 @@
 package org.jboss.deployers.vfs.spi.structure.modified;
 
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
 import org.jboss.virtual.VisitorAttributes;
 
 /**
@@ -36,7 +37,12 @@
 
    public UpdateDeleteVisitor(VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile originalRoot)
    {
-      super(attributes, cache, synchAdapter);
+      this(null, attributes, cache, synchAdapter, originalRoot);
+   }
+
+   public UpdateDeleteVisitor(VirtualFileFilter filter, VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile originalRoot)
+   {
+      super(filter, attributes, cache, synchAdapter);
       if (originalRoot == null)
          throw new IllegalArgumentException("Null original root");
 




More information about the jboss-cvs-commits mailing list