[jboss-cvs] JBossAS SVN: r81723 - in trunk: system/src/main/org/jboss/system/server/profileservice/repository and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 27 07:35:33 EST 2008


Author: emuckenhuber
Date: 2008-11-27 07:35:32 -0500 (Thu, 27 Nov 2008)
New Revision: 81723

Modified:
   trunk/server/src/etc/conf/default/bootstrap/profile-repository.xml
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepositoryFactory.java
Log:
JBAS-6148, JBAS-6147: add metadata awareness, ignore excluded files from the deploymentFilter

Modified: trunk/server/src/etc/conf/default/bootstrap/profile-repository.xml
===================================================================
--- trunk/server/src/etc/conf/default/bootstrap/profile-repository.xml	2008-11-27 11:18:52 UTC (rev 81722)
+++ trunk/server/src/etc/conf/default/bootstrap/profile-repository.xml	2008-11-27 12:35:32 UTC (rev 81723)
@@ -11,7 +11,8 @@
       <root>${jboss.lib.url}jboss-profileservice-spi.jar</root>
    </classloader>
     
-    <!-- The file repository profile service which provides full
+    <!-- 
+    	The file repository profile service which provides full
         support ProfileService spi.
     -->
     <bean name="ProfileService" class="org.jboss.system.server.profileservice.repository.ProfileServiceImpl">
@@ -33,6 +34,10 @@
          </array>
       </property>
       <property name="serializer"><inject bean="AttachmentsSerializer"/></property>
+      <property name="deploymentFilter"><inject bean="DeploymentFilter" /></property>
+      <property name="hotDeploymentFilter">
+        <bean class="org.jboss.system.server.profile.basic.XmlIncludeVirtualFileFilter"/>
+      </property>
       <property name="mainDeployer"><inject bean="MainDeployer"/></property>
    </bean>
    <bean name="AttachmentsSerializer" class="org.jboss.system.server.profileservice.repository.JAXBAttachmentSerializer" />
@@ -44,7 +49,7 @@
       <property name="mof"><inject bean="ManagedObjectFactory"/></property>
       <property name="mgtDeploymentCreator"><inject bean="ManagedDeploymentCreator"/></property>
    </bean>
-
+	
    <!-- A filter for excluding files from the scanner -->
    <bean name="DeploymentFilter" class="org.jboss.virtual.plugins.vfs.helpers.ExtensibleFilter">
       <!-- Files starting with theses strings are ignored -->

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java	2008-11-27 11:18:52 UTC (rev 81722)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java	2008-11-27 12:35:32 UTC (rev 81723)
@@ -47,8 +47,10 @@
 import org.jboss.deployers.spi.attachments.MutableAttachments;
 import org.jboss.deployers.spi.structure.ClassPathEntry;
 import org.jboss.deployers.spi.structure.ContextInfo;
+import org.jboss.deployers.structure.spi.DeploymentContext;
 import org.jboss.deployers.vfs.spi.client.VFSDeployment;
 import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
 import org.jboss.logging.Logger;
 import org.jboss.managed.api.ManagedCommon;
 import org.jboss.managed.api.ManagedComponent;
@@ -68,7 +70,9 @@
 import org.jboss.system.server.profileservice.attachments.RepositoryAttachmentMetaData;
 import org.jboss.util.file.Files;
 import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
 
 /**
  * An implementation of DeploymentRepository that relies on java
@@ -118,12 +122,20 @@
    private ReentrantReadWriteLock contentLock = new ReentrantReadWriteLock(true);
    /** Should an attempt to overwrite existing content fail in {@link #addDeploymentContent(String, ZipInputStream, DeploymentPhase)}*/
    private boolean failIfAlreadyExists = false;
+   
+   /** Allowed deployments filter */
+   private VirtualFileFilter deploymentFilter;
+   /** The metadata include filter */
+   private VirtualFileFilter hotDeploymentFilter;
+   /** The last modified cache */
+   private Map<String, Long> lastModifiedCache;
 
    public SerializableDeploymentRepository(File root, URI[] appURIs, ProfileKey key)
    {
       this.root = root;
       this.key = key;
       this.setApplicationURIs(appURIs);
+      this.lastModifiedCache = new ConcurrentHashMap<String, Long>();
    }
 
    public URI[] getApplicationURIs()
@@ -163,6 +175,26 @@
    {
       adminEditsRoot = new File(root);
    }
+   
+   public VirtualFileFilter getDeploymentFilter()
+   {
+      return deploymentFilter;
+   }
+   
+   public void setDeploymentFilter(VirtualFileFilter deploymentFilter)
+   {
+      this.deploymentFilter = deploymentFilter;
+   }
+   
+   public VirtualFileFilter getHotDeploymentFilter()
+   {
+      return hotDeploymentFilter;
+   }
+   
+   public void setHotDeploymentFilter(VirtualFileFilter hotDeploymentFilter)
+   {
+      this.hotDeploymentFilter = hotDeploymentFilter;
+   }
 
    public long getLastModified()
    {
@@ -527,6 +559,8 @@
                   ModificationInfo info = new ModificationInfo(ctx, rootLastModified, ModifyStatus.REMOVED);
                   modified.add(info);
                   iter.remove();
+                  // Remove last modified cache
+                  this.lastModifiedCache.remove(root.getPathName());
                   if( trace )
                      log.trace(name + " was removed");
                }
@@ -579,7 +613,7 @@
    }
    
    /**
-    * Has the root been modified.
+    * Check if the deployment has been modified.
     *
     * @param root the virtual file root
     * @return true if modifed
@@ -587,8 +621,75 @@
     */
    protected boolean hasBeenModified(VirtualFile root) throws Exception
    {
-      return root.hasBeenModified();
+      // get file:/ schema
+      URI uri = VFSUtils.getCompatibleURI(root);
+      File file = new File(uri);
+      // if root is file check its modification
+      if (file.isFile())
+         return root.hasBeenModified();
+
+      // else check metadata
+      String name = root.toURI().toString();
+      VFSDeploymentContext deploymentContext = getDeploymentContext(name);
+      if (deploymentContext != null)
+         return hasBeenModified(deploymentContext);
+
+      log.trace("Falling back to root name: " + root);
+      deploymentContext = getDeploymentContext(root.getName());
+      if (deploymentContext != null)
+         return hasBeenModified(deploymentContext);
+
+      return false;
    }
+   
+   /**
+    * Check for modifications.
+    * 
+    * @param deploymentContext
+    * @return
+    * @throws IOException
+    */
+   protected boolean hasBeenModified(VFSDeploymentContext deploymentContext) throws IOException
+   {
+      List<VirtualFile> metadataLocations = deploymentContext.getMetaDataLocations();
+      if (metadataLocations != null && metadataLocations.isEmpty() == false)
+      {
+         for(VirtualFile metadataLocation : metadataLocations)
+         {
+            List<VirtualFile> children = metadataLocation.getChildren(hotDeploymentFilter);
+            if (children != null && children.isEmpty() == false)
+            {
+               for(VirtualFile child : children)
+               {
+                  String pathName = child.getPathName();
+                  Long timestamp = lastModifiedCache.get(pathName);
+                  long lastModified = child.getLastModified();
+                  lastModifiedCache.put(pathName, lastModified);
+                  if (timestamp != null && timestamp < lastModified)
+                  {
+                     if (log.isTraceEnabled())
+                        log.trace("Metadata location modified: " + child);
+                     return true;
+                  }
+               }
+            }
+         }
+      }
+      List<DeploymentContext> childContexts = deploymentContext.getChildren();
+      if (childContexts != null && childContexts.isEmpty() == false)
+      {
+         for (DeploymentContext childContext : childContexts)
+         {
+            if (childContext instanceof VFSDeploymentContext)
+            {
+               if (hasBeenModified((VFSDeploymentContext)childContext))
+                  return true;
+            }
+         }
+      }
+      return false;
+   }
+   
 
    public Collection<VFSDeployment> getDeployments(DeploymentPhase phase)
       throws Exception
@@ -1046,6 +1147,13 @@
 
       for (VirtualFile component : components)
       {
+         // Excluding files from scanning
+         if(! this.deploymentFilter.accepts(component))
+         {
+            log.trace("ignoring "+ component);
+            continue;
+         }
+         
          String key = component.toURI().toString();
          if (applicationCtxs.containsKey(key) == true)
             continue;

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepositoryFactory.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepositoryFactory.java	2008-11-27 11:18:52 UTC (rev 81722)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepositoryFactory.java	2008-11-27 12:35:32 UTC (rev 81723)
@@ -30,6 +30,7 @@
 import org.jboss.profileservice.spi.DeploymentRepository;
 import org.jboss.profileservice.spi.DeploymentRepositoryFactory;
 import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.virtual.VirtualFileFilter;
 
 /**
  * Factory for SerializableDeploymentRepository
@@ -50,6 +51,12 @@
    private AttachmentsSerializer serializer;
    /** The main deployer structure */
    private MainDeployerStructure mainDeployer;
+   /** The deployment filter */
+   private VirtualFileFilter deploymentFilter;
+   /** The HotDeployment filter */
+   private VirtualFileFilter hotDeploymentFilter;
+   
+   /** The profile repositories */
    private HashMap<ProfileKey, DeploymentRepository> profileRepositories
       = new HashMap<ProfileKey, DeploymentRepository>();
    
@@ -98,6 +105,26 @@
       this.serializer = serializer;
    }
    
+   public VirtualFileFilter getDeploymentFilter()
+   {
+      return deploymentFilter;
+   }
+   
+   public void setDeploymentFilter(VirtualFileFilter deploymentFilter)
+   {
+      this.deploymentFilter = deploymentFilter;
+   }
+   
+   public VirtualFileFilter getHotDeploymentFilter()
+   {
+      return hotDeploymentFilter;
+   }
+   
+   public void setHotDeploymentFilter(VirtualFileFilter hotDeploymentFilter)
+   {
+      this.hotDeploymentFilter = hotDeploymentFilter;
+   }
+   
    public MainDeployerStructure getMainDeployer()
    {
       return mainDeployer;
@@ -121,6 +148,8 @@
          SerializableDeploymentRepository repo = new SerializableDeploymentRepository(root, appURIs, key);
          repo.setAttachmentsRoot(attachmentsRoot);
          repo.setSerializer(serializer);
+         repo.setDeploymentFilter(deploymentFilter);
+         repo.setHotDeploymentFilter(hotDeploymentFilter);
          repo.setMainDeployer(mainDeployer);
          profileRepositories.put(key, repo);
          dr = repo;




More information about the jboss-cvs-commits mailing list