[jboss-cvs] JBossAS SVN: r87015 - 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
Wed Apr 8 18:35:18 EDT 2009


Author: alesj
Date: 2009-04-08 18:35:17 -0400 (Wed, 08 Apr 2009)
New Revision: 87015

Added:
   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/SynchAdapter.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/UpdateDeleteVisitor.java
Modified:
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java
Log:
[JBAS-6722]; initial synch work.

Added: 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	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java	2009-04-08 22:35:17 UTC (rev 87015)
@@ -0,0 +1,61 @@
+/*
+ * 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 org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VisitorAttributes;
+
+/**
+ * Synch on add file visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class AddVisitor extends SynchVisitor
+{
+   private VirtualFile tempRoot;
+   private int initialPathLenght;
+
+   public AddVisitor(VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile tempRoot, int initialPathLenght)
+   {
+      super(attributes, cache, synchAdapter);
+      if (tempRoot == null)
+         throw new IllegalArgumentException("Null temp root");
+      if (initialPathLenght < 0)
+         throw new IllegalArgumentException("Initial path length is negative: " + initialPathLenght);
+
+      this.tempRoot = tempRoot;
+      this.initialPathLenght = initialPathLenght;
+   }
+
+   public void doVisit(VirtualFile file) throws Exception
+   {
+      String originalPathName = file.getPathName();
+      String pathName = originalPathName.substring(initialPathLenght);
+      VirtualFile child = tempRoot.getChild(pathName);
+      if (child == null)
+      {
+         // original was added
+         long timestamp = getSynchAdapter().add(file, tempRoot, pathName);
+         getCache().putCacheValue(originalPathName, timestamp);
+      }
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchAdapter.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchAdapter.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchAdapter.java	2009-04-08 22:35:17 UTC (rev 87015)
@@ -0,0 +1,63 @@
+/*
+ * 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.io.IOException;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Synch adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface SynchAdapter
+{
+   /**
+    * Add new file to temp.
+    *
+    * @param fileToAdd file to add
+    * @param tempRoot temp root
+    * @param pathToFile the path to file
+    * @return addition timestamp
+    * @throws IOException for any error
+    */
+   long add(VirtualFile fileToAdd, VirtualFile tempRoot, String pathToFile) throws IOException;
+
+   /**
+    * Update file.
+    *
+    * @param fileToUpdate file to update
+    * @param modifiedFile the modified file
+    * @return the update timestamp
+    * @throws IOException for any error
+    */
+   long update(VirtualFile fileToUpdate, VirtualFile modifiedFile) throws IOException;
+
+   /**
+    * Add new file to temp.
+    *
+    * @param fileToDelete file to delete
+    * @throws IOException for any error
+    */
+   void delete(VirtualFile fileToDelete) throws IOException;
+}
\ No newline at end of file

Added: 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	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java	2009-04-08 22:35:17 UTC (rev 87015)
@@ -0,0 +1,101 @@
+/*
+ * 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 org.jboss.logging.Logger;
+import org.jboss.virtual.VirtualFileVisitor;
+import org.jboss.virtual.VisitorAttributes;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Synch file visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class SynchVisitor implements VirtualFileVisitor
+{
+   protected final Logger log = Logger.getLogger(getClass());
+
+   private VisitorAttributes attributes;
+   private StructureCache<Long> cache;
+   private SynchAdapter synchAdapter;
+
+   protected SynchVisitor(VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter)
+   {
+      if (cache == null)
+         throw new IllegalArgumentException("Null cache");
+      if (synchAdapter == null)
+         throw new IllegalArgumentException("Null synch adapter");
+
+      if (attributes != null)
+         this.attributes = attributes;
+      else
+         this.attributes = VisitorAttributes.RECURSE_LEAVES_ONLY;
+      this.cache = cache;
+      this.synchAdapter = synchAdapter;
+   }
+
+   public VisitorAttributes getAttributes()
+   {
+      return attributes;
+   }
+
+   public void visit(VirtualFile file)
+   {
+      try
+      {
+         doVisit(file);
+      }
+      catch (Exception e)
+      {
+         log.warn("Exception synching file: " + file + ", cause: " + e);
+      }
+   }
+
+   /**
+    * Visit a virtual file
+    *
+    * @param file the virtual file being visited
+    * @throws Exception for any error
+    */
+   protected abstract void doVisit(VirtualFile file) throws Exception;
+
+   /**
+    * Get cache.
+    *
+    * @return the cache
+    */
+   protected StructureCache<Long> getCache()
+   {
+      return cache;
+   }
+
+   /**
+    * Get synch adapter.
+    *
+    * @return the syncj adapter
+    */
+   protected SynchAdapter getSynchAdapter()
+   {
+      return synchAdapter;
+   }
+}
\ No newline at end of file

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-04-08 22:18:24 UTC (rev 87014)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java	2009-04-08 22:35:17 UTC (rev 87015)
@@ -26,6 +26,7 @@
 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.VisitorAttributes;
 
 /**
  * Synch wrapper modification checker.
@@ -34,24 +35,32 @@
  * only then checking if we need to update some resource.
  * e.g. some .jsp or .xhtml file for JBossWeb to pick up the change
  *
- * @param <T> exact checker type
  * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  */
-public class SynchWrapperModificationChecker<T> extends AbstractStructureModificationChecker<T>
+public class SynchWrapperModificationChecker extends AbstractStructureModificationChecker<Long>
 {
    /** The true checker delegate */
-   private AbstractStructureModificationChecker<T> delegate;
+   private AbstractStructureModificationChecker<Long> delegate;
 
-   public SynchWrapperModificationChecker(AbstractStructureModificationChecker<T> delegate)
+   /** The synch adapter */
+   private SynchAdapter synchAdapter;
+
+   /** the visitor attributes */
+   private VisitorAttributes attributes;
+
+   public SynchWrapperModificationChecker(AbstractStructureModificationChecker<Long> delegate, SynchAdapter synchAdapter)
    {
       if (delegate == null)
          throw new IllegalArgumentException("Null delegate");
+      if (synchAdapter == null)
+         throw new IllegalArgumentException("Null synch adapter");
 
       this.delegate = delegate;
+      this.synchAdapter = synchAdapter;
    }
 
    @Override
-   protected StructureCache<T> getCache()
+   protected StructureCache<Long> getCache()
    {
       return delegate.getCache();
    }
@@ -68,7 +77,13 @@
       // it was not modifed & we're actually temped
       if (modified == false && root != deploymentContext.getRoot())
       {
-         // TODO - synch
+         // check for update or delete
+         UpdateDeleteVisitor udVisitor = new UpdateDeleteVisitor(attributes, getCache(), synchAdapter, root);
+         VirtualFile tempRoot = deploymentContext.getRoot();
+         tempRoot.visit(udVisitor);
+         // check for addition
+         AddVisitor addVisitor = new AddVisitor(attributes, getCache(), synchAdapter, tempRoot, root.getPathName().length());
+         root.visit(addVisitor);
       }
       return modified;
    }
@@ -82,4 +97,14 @@
    {
       delegate.removeStructureRoot(root);
    }
+
+   /**
+    * Set visitor attributes.
+    *
+    * @param attributes the attributes
+    */
+   public void setAttributes(VisitorAttributes attributes)
+   {
+      this.attributes = attributes;
+   }
 }
\ No newline at end of file

Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java (from rev 86932, 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/UpdateDeleteVisitor.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java	2009-04-08 22:35:17 UTC (rev 87015)
@@ -0,0 +1,68 @@
+/*
+ * 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 org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VisitorAttributes;
+
+/**
+ * Synch on update and delete file visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class UpdateDeleteVisitor extends SynchVisitor
+{
+   private VirtualFile originalRoot;
+   private String initialPath;
+
+   public UpdateDeleteVisitor(VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile originalRoot)
+   {
+      super(attributes, cache, synchAdapter);
+      if (originalRoot == null)
+         throw new IllegalArgumentException("Null original root");
+
+      this.originalRoot = originalRoot;
+      this.initialPath = originalRoot.getPathName();
+   }
+
+   protected void doVisit(VirtualFile file) throws Exception
+   {
+      String pathName = initialPath + file.getPathName();
+      VirtualFile child = originalRoot.getChild(pathName);
+      if (child == null)
+      {
+         // original was deleted
+         getCache().removeCache(pathName);
+         getSynchAdapter().delete(file);
+      }
+      else
+      {
+         Long previous = getCache().getCacheValue(pathName);
+         long lastModified = child.getLastModified();
+         if (previous != null && lastModified > previous)
+         {
+            lastModified = getSynchAdapter().update(file, child);
+         }
+         getCache().putCacheValue(pathName, lastModified);
+      }
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list