[jboss-cvs] JBossAS SVN: r99395 - in branches/vfs3-int: system and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 14 04:38:49 EST 2010


Author: emuckenhuber
Date: 2010-01-14 04:38:49 -0500 (Thu, 14 Jan 2010)
New Revision: 99395

Added:
   branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AutoUnmounter.java
Modified:
   branches/vfs3-int/profileservice/src/main/java/org/jboss/profileservice/management/upload/remoting/AbstractDeployHandler.java
   branches/vfs3-int/profileservice/src/main/java/org/jboss/profileservice/management/upload/remoting/DeployHandler.java
   branches/vfs3-int/system/pom.xml
   branches/vfs3-int/system/src/main/java/org/jboss/system/server/profile/repository/AbstractImmutableProfile.java
   branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/attachments/AttachmentStore.java
   branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java
   branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java
   branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java
   branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractVFSProfileSource.java
   branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
   branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/DefaultProfileDeploymentFactory.java
   branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/FilteredProfileFactory.java
   branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/HotDeploymentRepository.java
   branches/vfs3-int/system/src/main/java/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java
Log:
[JBAS-7348] some hot-deployment fixes, use backup location for VirtualFiles and update the deployment names 

Modified: branches/vfs3-int/profileservice/src/main/java/org/jboss/profileservice/management/upload/remoting/AbstractDeployHandler.java
===================================================================
--- branches/vfs3-int/profileservice/src/main/java/org/jboss/profileservice/management/upload/remoting/AbstractDeployHandler.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/profileservice/src/main/java/org/jboss/profileservice/management/upload/remoting/AbstractDeployHandler.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -21,7 +21,9 @@
  */ 
 package org.jboss.profileservice.management.upload.remoting;
 
+import java.io.IOException;
 import java.io.InputStream;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -29,12 +31,11 @@
 
 import javax.management.MBeanServer;
 
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.InvocationResponse;
 import org.jboss.aspects.remoting.AOPRemotingInvocationHandler;
 import org.jboss.deployers.spi.management.deploy.DeploymentID;
 import org.jboss.deployers.spi.management.deploy.DeploymentManager;
 import org.jboss.logging.Logger;
+import org.jboss.mx.server.Invocation;
 import org.jboss.profileservice.management.client.upload.SerializableDeploymentID;
 import org.jboss.profileservice.remoting.SecurityContainer;
 import org.jboss.profileservice.spi.DeploymentRepository;
@@ -43,6 +44,7 @@
 import org.jboss.profileservice.spi.ProfileKey;
 import org.jboss.profileservice.spi.ProfileRepository;
 import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvocationResponse;
 import org.jboss.remoting.ServerInvoker;
 import org.jboss.remoting.callback.InvokerCallbackHandler;
 import org.jboss.remoting.stream.StreamInvocationHandler;
@@ -290,7 +292,13 @@
       
       // FIXME make deployment visible to management view
       VirtualFile vf = deploymentRepository.getDeploymentContent(repositoryName);
-      ProfileDeployment deployment = createDeployment(vf);
+      
+      // FIXME 
+      ProfileKey key = deploymentTarget.getProfile();
+      String profileName = key.getName();
+      String deploymentName = createDeploymentName(vf);
+      ProfileDeployment deployment = createDeployment(profileName, deploymentName, vf);
+      // Add deployment
       deploymentRepository.addDeployment(deployment.getName(), deployment);
       deploymentRepository.lockDeploymentContent(deployment.getName());
       
@@ -417,14 +425,20 @@
     * @param file the root file
     * @return the deployment
     */
-   protected ProfileDeployment createDeployment(VirtualFile file)
+   protected ProfileDeployment createDeployment(String profileName, String deploymentName, VirtualFile file) throws IOException
    {
       if (file == null)
          throw new IllegalArgumentException("Null file");
       
-      return deploymentFactory.createProfileDeployment(file);
+      return deploymentFactory.createProfileDeployment(profileName, deploymentName, file);
    }
    
+   @SuppressWarnings("static-access")
+   protected String createDeploymentName(VirtualFile vf) throws URISyntaxException
+   {
+      return deploymentFactory.createDeploymentName(vf);
+   }
+   
    private void establishSecurityContext(InvocationRequest invocation) throws Exception
    { 
       SecurityContext newSC = SecurityActions.createAndSetSecurityContext(securityDomain);  

Modified: branches/vfs3-int/profileservice/src/main/java/org/jboss/profileservice/management/upload/remoting/DeployHandler.java
===================================================================
--- branches/vfs3-int/profileservice/src/main/java/org/jboss/profileservice/management/upload/remoting/DeployHandler.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/profileservice/src/main/java/org/jboss/profileservice/management/upload/remoting/DeployHandler.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -108,7 +108,8 @@
       VirtualFile vf = VFS.getChild(contentURL);
      
       // FIXME make deployment visible to management view
-      ProfileDeployment deployment = createDeployment(vf);
+      String deploymentName = createDeploymentName(vf);
+      ProfileDeployment deployment = createDeployment(AbstractTransientProfileManager.TRANSIENT_PROFILE_NAME, deploymentName, vf);
       this.transientProfile.addDeployment(deployment);
 
       String name = deployment.getName();

Modified: branches/vfs3-int/system/pom.xml
===================================================================
--- branches/vfs3-int/system/pom.xml	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/pom.xml	2010-01-14 09:38:49 UTC (rev 99395)
@@ -56,10 +56,6 @@
       </exclusions>
     </dependency>
     <dependency>
-      <groupId>org.jboss.aop</groupId>
-      <artifactId>jboss-aop</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.jboss</groupId>
       <artifactId>jbossxb</artifactId>
     </dependency>
@@ -68,10 +64,6 @@
       <artifactId>jboss-logging-spi</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.jboss.integration</groupId>
-      <artifactId>jboss-profileservice-spi</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.jboss.man</groupId>
       <artifactId>jboss-managed</artifactId>
     </dependency>
@@ -84,6 +76,10 @@
       <artifactId>jboss-dependency</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.jboss.integration</groupId>
+      <artifactId>jboss-profileservice-spi</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.jboss.deployers</groupId>
       <artifactId>jboss-deployers-client-spi</artifactId>
     </dependency>
@@ -104,14 +100,14 @@
       <artifactId>jboss-kernel</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.jboss.deployers</groupId>
-      <artifactId>jboss-deployers-impl</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.jboss.kernel</groupId>
       <artifactId>jboss-aop-mc-int</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.jboss.deployers</groupId>
+      <artifactId>jboss-deployers-impl</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.jboss.bootstrap</groupId>
       <artifactId>jboss-bootstrap-spi-as</artifactId>
     </dependency>

Modified: branches/vfs3-int/system/src/main/java/org/jboss/system/server/profile/repository/AbstractImmutableProfile.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/server/profile/repository/AbstractImmutableProfile.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/server/profile/repository/AbstractImmutableProfile.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -73,6 +73,11 @@
       updateLastModfied();
    }
    
+   public void destroy()
+   {
+      super.destroy();
+   }
+   
    public ProfileKey getKey()
    {
       return this.key;
@@ -156,4 +161,12 @@
       //
    }
 
+   @Override
+   protected ProfileDeployment createDeployment(VirtualFile vf) throws Exception
+   {
+      String profileName = getKey().getName();
+      String deploymentName = createDeploymentName(vf);
+      return super.createDeployment(profileName, deploymentName, vf);
+   }
+   
 }

Modified: branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/attachments/AttachmentStore.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/attachments/AttachmentStore.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/attachments/AttachmentStore.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -27,7 +27,6 @@
 import org.jboss.managed.api.ManagedComponent;
 import org.jboss.profileservice.spi.ProfileDeployment;
 import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
-import org.jboss.vfs.VirtualFile;
 
 /**
  * The AttachmentStore.
@@ -48,21 +47,23 @@
    /**
     * Load the repository attachment meta data
     * 
-    * @param deploymentCtx the deployment root
+    * @param deploymentName the deployment name
+    * @param simpleName the simple name
     * @return the persisted meta data or null if it does not exist
     * @throws Exception
     */
-   RepositoryAttachmentMetaData loadMetaData(VirtualFile deploymentCtx) throws Exception;
+   RepositoryAttachmentMetaData loadMetaData(String deploymentName, String simpleName) throws Exception;
 
    /**
     * Load a attachment.
     * 
-    * @param deploymentCtx
+    * @param deploymentName
+    * @param simpleName
     * @param attachment
     * @return
     * @throws Exception
     */
-   PersistenceRoot loadAttachment(VirtualFile deploymentCtx, AttachmentMetaData attachment) throws Exception;
+   PersistenceRoot loadAttachment(String deploymentName, String simpleName, AttachmentMetaData attachment) throws Exception;
 
    /**
     * Persist the managed component.

Modified: branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -32,7 +32,6 @@
 import org.jboss.system.server.profileservice.attachments.RepositoryAttachmentMetaData;
 import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
 import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
-import org.jboss.vfs.VirtualFile;
 
 /**
  * The ProfileService Persistence Deployer. This deployer applies the
@@ -100,8 +99,9 @@
    
    protected void applyPersistentChanges(VFSDeploymentUnit unit) throws Throwable
    {
-      VirtualFile vf = unit.getRoot();
-      RepositoryAttachmentMetaData metaData = store.loadMetaData(vf);
+      String deploymentName = unit.getName();
+      String simpleName = unit.getSimpleName();
+      RepositoryAttachmentMetaData metaData = store.loadMetaData(deploymentName, simpleName);
       if(metaData == null)
          return;      
       
@@ -119,10 +119,10 @@
             Object instance = unit.getAttachment(attachment.getName());
             if(instance != null)
             {
-               PersistenceRoot root = this.store.loadAttachment(vf, attachment);
+               PersistenceRoot root = this.store.loadAttachment(deploymentName, simpleName, attachment);
                if(root == null)
                {
-                  log.warn("Null persisted information for deployment: " + vf);
+                  log.warn("Null persisted information for deployment: " + deploymentName);
                }
                // update ...
                getPersistenceFactory().restorePersistenceRoot(root, instance, unit.getClassLoader());

Modified: branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -34,14 +34,12 @@
 
 import org.jboss.deployers.client.plugins.deployment.AbstractDeployment;
 import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.plugins.main.MainDeployerImpl;
 import org.jboss.deployers.spi.attachments.AttachmentsFactory;
 import org.jboss.deployers.spi.attachments.MutableAttachments;
 import org.jboss.deployers.structure.spi.DeploymentContext;
 import org.jboss.deployers.structure.spi.main.MainDeployerInternals;
 import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.logging.Logger;
 import org.jboss.managed.api.ManagedCommon;
 import org.jboss.managed.api.ManagedComponent;
@@ -53,6 +51,7 @@
 import org.jboss.system.server.profileservice.attachments.RepositoryAttachmentMetaDataFactory;
 import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
 import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
+import org.jboss.vfs.VFS;
 import org.jboss.vfs.VirtualFile;
 
 /**
@@ -146,9 +145,20 @@
    {
       Deployment mcDeployment = null;
       if(deployment.getRoot() == null)
+      {
          mcDeployment = new AbstractDeployment(deployment.getName());
+      }
       else
-         mcDeployment = deploymentFactory.createVFSDeployment(deployment.getRoot());
+      {
+         // Get the actual virtual file for the deployment
+         // NOTE the profileDeployment root points to a copy
+         URI deploymentURI = new URI(deployment.getName());
+         VirtualFile vf = VFS.getChild(deploymentURI);
+         
+         // we need to create a VFSDeployment with specifying the name
+         // otherwise we loose track of the deployments
+         mcDeployment = deploymentFactory.createVFSDeployment(deployment.getName(), vf);
+      }
 
       // Add the deployment attachments as PredeterminedManagedObjects
       Map<String, Object> attachments = deployment.getAttachments();
@@ -184,12 +194,14 @@
       return null;
    }
 
-   public RepositoryAttachmentMetaData loadMetaData(VirtualFile deploymentRoot) throws Exception
+   public RepositoryAttachmentMetaData loadMetaData(String deploymentName, String simpleName) throws Exception
    {
-      if(deploymentRoot == null)
-         throw new IllegalArgumentException("Null deployment root.");
+      if(deploymentName == null)
+         throw new IllegalArgumentException("Null deployment name.");
+      if(simpleName == null)
+         throw new IllegalArgumentException("null simple name");
 
-      String deploymentPath = createRelativeDeploymentPath(deploymentRoot);
+      String deploymentPath = createRelativeDeploymentPath(deploymentName, simpleName);
       return loadAttachmentMetaData(deploymentPath);
    }
 
@@ -219,16 +231,15 @@
       if(ctx == null)
          throw new IllegalStateException("Cannot persist attachment, failed to find deployment: " + deploymentName);
 
-      // Get the root
-      VirtualFile root = ctx.getRoot();
-      String deploymentPath = createRelativeDeploymentPath(root);
+      // Create the path
+      String deploymentPath = createRelativeDeploymentPath(ctx.getName(), ctx.getSimpleName());
 
       // Load previous saved information
       RepositoryAttachmentMetaData repositoryMetaData = loadAttachmentMetaData(deploymentPath);
       if(repositoryMetaData == null)
       {
          repositoryMetaData = RepositoryAttachmentMetaDataFactory.createInstance();
-         repositoryMetaData.setDeploymentName(root.getName());
+         repositoryMetaData.setDeploymentName(ctx.getSimpleName());
       }
 
       // Get the parent MO
@@ -319,14 +330,14 @@
 
 
 
-   public PersistenceRoot loadAttachment(VirtualFile deploymentCtx, AttachmentMetaData attachment) throws Exception
+   public PersistenceRoot loadAttachment(String deploymentName, String simpleName, AttachmentMetaData attachment) throws Exception
    {
-      if(deploymentCtx == null)
+      if(deploymentName == null)
          throw new IllegalArgumentException("Null deployment root.");
       if(attachment == null)
          throw new IllegalArgumentException("Null attachment");
 
-      String deploymentPath = createRelativeDeploymentPath(deploymentCtx);
+      String deploymentPath = createRelativeDeploymentPath(deploymentName, simpleName);
 
       // Load
       String attachmentPath = deploymentPath + attachment.getName();
@@ -352,18 +363,12 @@
     * @return the relative name
     * @throws Exception
     */
-   protected String createRelativeDeploymentPath(VirtualFile vf) throws Exception
+   protected String createRelativeDeploymentPath(String deploymentName, String simpleName) throws Exception
    {
-      if(vf == null)
-         throw new IllegalStateException("Null deployment.");
-
-      // deployment URI
-      String pathName = vf.toURI().toString();
-      String fileName = vf.getName();
       // Generate hash
-      String hash = HashGenerator.createHash(pathName);
+      String hash = HashGenerator.createHash(deploymentName);
       // simple name + "-" + hash
-      return fileName + "-" + hash + File.separator;
+      return simpleName + "-" + hash + File.separator;
 
    }
 
@@ -373,7 +378,6 @@
     * @param name the deployment context name
     * @return vfs deployment context or null if doesn't exist or not vfs based
     */
-   @SuppressWarnings("deprecation")
    protected VFSDeploymentContext getDeploymentContext(String name)
    {
       if (mainDeployer == null)

Modified: branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -25,7 +25,6 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.jboss.deployers.vfs.spi.client.VFSDeployment;
 import org.jboss.profileservice.spi.ProfileDeployment;
 import org.jboss.vfs.VirtualFile;
 
@@ -53,28 +52,6 @@
    /** The serialVersionUID. */
    private static final long serialVersionUID = -2208890215429044674L;
    
-   /**
-    * Get the vfs file name safely.
-    * @see VFSDeployment
-    * 
-    * @param root the virtual file
-    * @return the name
-    */
-   static final String safeVirtualFileName(VirtualFile root)
-   {
-      if (root == null)
-         throw new IllegalArgumentException("Null root");
-
-      try
-      {
-         return root.toURI().toString();
-      }
-      catch (Exception e)
-      {
-         return root.getName();
-      }
-   }
-   
    public AbstractProfileDeployment(String name)
    {
       if(name == null)
@@ -82,9 +59,11 @@
       this.name = name;
    }
    
-   public AbstractProfileDeployment(VirtualFile root)
+   public AbstractProfileDeployment(String name, VirtualFile root)
    {
-      this(safeVirtualFileName(root));
+      if(name == null)
+         throw new IllegalArgumentException("Null name.");
+      this.name = name;
       this.root = root;
    }
 
@@ -101,6 +80,10 @@
    /**
     * Get the root of the deployment.
     * 
+    * NOTE the {@link VirtualFile} will point to the original file
+    * in the filesystem, although URL will most probably not match
+    * since it gets mounted to a backup location {@see AutoUnmounter}.
+    * 
     * @return the root, or null if it's not a VFS deployment.
     */
    public VirtualFile getRoot()

Modified: branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractVFSProfileSource.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractVFSProfileSource.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AbstractVFSProfileSource.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -50,6 +50,9 @@
 public abstract class AbstractVFSProfileSource
 {
    
+   /** The deployment factory. */
+   private static final DefaultProfileDeploymentFactory deploymentFactory = DefaultProfileDeploymentFactory.getInstance();
+   
    /** The repository uris. */
    protected final Collection<URI> uris;
 
@@ -71,6 +74,32 @@
    /** The logger. */
    protected final Logger log = Logger.getLogger(getClass());
    
+   /**
+    * Create the deployment name based on the {@link VirtualFile}.
+    * 
+    * @param root the virtual file
+    * @return the deployment name
+    * @throws URISyntaxException 
+    */
+   protected static String createDeploymentName(VirtualFile root) throws URISyntaxException
+   {
+      if (root == null)
+         throw new IllegalArgumentException("Null root");
+
+      return DefaultProfileDeploymentFactory.createDeploymentName(root);
+   }
+   
+   /**
+    * Create the deployment name based on a {@link URI}.
+    * 
+    * @param uri the deployment uri
+    * @return the deployment name
+    */
+   protected static String createDeploymentName(URI uri)
+   {
+      return DefaultProfileDeploymentFactory.createDeploymentName(uri);
+   }
+   
    public AbstractVFSProfileSource(URI[] uris)
    {
       if(uris == null)
@@ -123,8 +152,23 @@
       return this.lastModified;
    }
    
-   public void destroy()
+   public void destroy() 
    {
+      boolean trace = log.isTraceEnabled();
+      for(ProfileDeployment deployment : getDeployments())
+      {
+         try
+         {
+            deploymentFactory.cleanup(deployment.getName());
+         }
+         catch(IOException ignore)
+         {
+            if(trace)
+            {
+               log.trace("error while cleaning up the the deployment backup", ignore);
+            }
+         }
+      }
       // Unload
       this.applicationCtxs.clear();
       this.applicationVFCache.clear();
@@ -178,9 +222,12 @@
       
       // Get the deployment
       ProfileDeployment deployment = getDeployment(vfsPath);
+      String deploymentName = deployment.getName();
       // Remove the entries
-      this.applicationCtxs.remove(deployment.getName());
-      this.applicationVFCache.remove(deployment.getName());
+      this.applicationCtxs.remove(deploymentName);
+      this.applicationVFCache.remove(deploymentName);
+      // Cleanup the backup
+      deploymentFactory.cleanup(deploymentName);
       // Update last modified
       updateLastModfied();
       // Return
@@ -247,7 +294,7 @@
       }
       
       // Check if we accept this deployment
-      String key = component.toURI().toString();
+      String key = createDeploymentName(component);
       if(acceptsDeployment(key) == false)
          return;
 
@@ -319,9 +366,10 @@
     * @throws MalformedURLException
     * @throws URISyntaxException
     */
+   @Deprecated
    protected String addVirtualFileCache(VirtualFile vf) throws MalformedURLException, URISyntaxException
    {
-      String uri = vf.toURI().toString();
+      String uri = createDeploymentName(vf);
       this.applicationVFCache.put(uri, vf);
       return uri;
    }
@@ -332,6 +380,7 @@
     * @param name the name
     * @return the virtual file or null, if it does not exist
     */
+   @Deprecated
    protected VirtualFile getCachedVirtualFile(String name)
    {
       return this.applicationVFCache.get(name);
@@ -343,29 +392,42 @@
     * 
     * @param uri the uri
     * @return the virtual file
-    * @throws IOException
+    * @throws Exception
     */
+   @Deprecated
    protected VirtualFile getCachedVirtualFile(URI uri) throws IOException 
    {
       VirtualFile vf = getCachedVirtualFile(uri.toString());
       if(vf == null)
       {
          vf = VFS.getChild(uri);
-         this.applicationVFCache.put(uri.toString(), vf);
+         String name = createDeploymentName(uri);
+         this.applicationVFCache.put(name, vf);
       }
       return vf;
    }
    
    /**
-    * Create a ProfileDeployment, based on the virtual file.
+    * Create a profile deployment.
     * 
+    * @param vf the original virtual file
+    * @return the profile deployment
+    * @throws Exception
+    */
+   protected abstract ProfileDeployment createDeployment(VirtualFile vf) throws Exception;
+   
+   /**
+    * Create a ProfileDeployment, based on avirtual file.
+    * 
+    * @param profileName the profile name
+    * @param name the deployment name
     * @param vf the deployment root
     * @return the profile deployment
     * @throws Exception
     */
-   protected static ProfileDeployment createDeployment(VirtualFile vf) throws Exception
-   {
-      return new AbstractProfileDeployment(vf);
+   protected static ProfileDeployment createDeployment(String profileName, String name, VirtualFile original) throws Exception
+   {           
+      return deploymentFactory.createProfileDeployment(profileName, name, original);
    }
    
    /**

Added: branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AutoUnmounter.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AutoUnmounter.java	                        (rev 0)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/AutoUnmounter.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -0,0 +1,85 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.system.server.profileservice.repository;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.util.automount.Automounter;
+
+/**
+ * The counterpart to {@link Automounter}, preserving a mount to the original
+ * {@link VirtualFile} used by profileservice.
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+class AutoUnmounter
+{
+
+   /** The closeables. */
+   private Map<String, Closeable> mounts = new ConcurrentHashMap<String, Closeable>(); 
+
+   /** The originals root. */
+   // TODO better name: ${server.temp.dir}... 
+   private VirtualFile originals = VFS.getChild("/profileservice/originals/"); 
+   
+   /**
+    * Backup a virtual file to preserve the original location.
+    * 
+    * @param profileName the profile name
+    * @param name the deployment name
+    * @param original the original file
+    * @return the backup
+    * @throws IOException
+    */
+   VirtualFile backup(String profileName, String name, VirtualFile original) throws IOException
+   {
+      File realFile = original.getPhysicalFile();
+      VirtualFile backup = originals.getChild(profileName).getChild(realFile.getName());
+      Closeable closeable = VFS.mountReal(realFile, backup);
+      mounts.put(name, closeable);
+      return backup;
+   }
+   
+   /**
+    * Cleanup
+    * 
+    * @param name
+    * @throws IOException
+    */
+   void cleanup(String name) throws IOException
+   {
+      Closeable closeable = mounts.remove(name);
+      if(closeable != null)
+      {
+         closeable.close();
+      }
+   }
+  
+}
+

Modified: branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -312,6 +312,16 @@
       // FIXME remove
    }
    
+   @Override
+   protected ProfileDeployment createDeployment(VirtualFile vf) throws Exception
+   {
+      // Create a profile deployment
+      // NOTE the vfs root of profile deployment points to a backup location
+      String profileName = getProfileKey().getName();
+      String deploymentName = createDeploymentName(vf);
+      return super.createDeployment(profileName, deploymentName, vf);
+   }
+   
    /**
     * Lock for read
     */

Modified: branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/DefaultProfileDeploymentFactory.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/DefaultProfileDeploymentFactory.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/DefaultProfileDeploymentFactory.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -21,6 +21,10 @@
  */ 
 package org.jboss.system.server.profileservice.repository;
 
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
 import org.jboss.profileservice.spi.ProfileDeployment;
 import org.jboss.vfs.VirtualFile;
 
@@ -30,12 +34,26 @@
  * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
  * @version $Revision$
  */
-public class DefaultProfileDeploymentFactory
+public class DefaultProfileDeploymentFactory extends AutoUnmounter
 {
 
    /** The instance. */
    private static final DefaultProfileDeploymentFactory INSTANCE = new DefaultProfileDeploymentFactory();
+
+   public static String createDeploymentName(VirtualFile original) throws URISyntaxException
+   {
+      return createDeploymentName(original.toURI());
+   }
    
+   public static String createDeploymentName(URI uri)
+   {
+      // Always use the name without the "/"
+      String name = uri.toString();
+      if(name.endsWith("/"))
+         return name.substring(0, name.length() -1);
+      return name;
+   }
+   
    protected DefaultProfileDeploymentFactory()
    {
       //
@@ -51,10 +69,26 @@
       return new AbstractProfileDeployment(name);
    }
    
-   public ProfileDeployment createProfileDeployment(VirtualFile vf)
+   @Deprecated
+   public ProfileDeployment createProfileDeployment(VirtualFile vf) throws URISyntaxException 
    {
-      return new AbstractProfileDeployment(vf);
+      String name = createDeploymentName(vf);
+      return new AbstractProfileDeployment(name, vf);
    }
    
+   public ProfileDeployment createProfileDeployment(String profileName, String name, VirtualFile original) throws IOException
+   {
+      VirtualFile copy = backup(profileName, name, original);
+      return new AbstractProfileDeployment(name, copy);
+   }
+
+   /**
+    * Cleanup the deployment
+    */
+   public void cleanup(String deploymentName) throws IOException
+   {
+      super.cleanup(deploymentName);
+   }
+   
 }
 

Modified: branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/FilteredProfileFactory.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/FilteredProfileFactory.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/FilteredProfileFactory.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -22,7 +22,6 @@
 package org.jboss.system.server.profileservice.repository;
 
 import java.io.FileNotFoundException;
-import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -144,7 +143,7 @@
          updateLastModfied();
       }
 
-      protected VirtualFile resolveDeploymentName(String deploymentName) throws IOException
+      protected VirtualFile resolveDeploymentName(String deploymentName) throws Exception
       {
          List<VirtualFile> list = new ArrayList<VirtualFile>();
          for(URI uri : getRepositoryURIs())

Modified: branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/HotDeploymentRepository.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/HotDeploymentRepository.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/server/profileservice/repository/HotDeploymentRepository.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -118,7 +118,7 @@
                }
                // Check for modification
                else if (hasDeploymentContentFlags(pathName, DeploymentContentFlags.MODIFIED)
-                     || getChecker().hasStructureBeenModified(root))
+                     || getChecker().hasStructureBeenModified(pathName, root))
                {
                   long rootLastModified = root.getLastModified();
                   if (trace)

Modified: branches/vfs3-int/system/src/main/java/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java
===================================================================
--- branches/vfs3-int/system/src/main/java/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java	2010-01-14 09:37:45 UTC (rev 99394)
+++ branches/vfs3-int/system/src/main/java/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java	2010-01-14 09:38:49 UTC (rev 99395)
@@ -21,7 +21,6 @@
  */
 package org.jboss.system.tools;
 
-import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -44,7 +43,6 @@
 import org.jboss.system.server.profileservice.hotdeploy.Scanner;
 import org.jboss.system.server.profileservice.repository.HotDeploymentRepository;
 import org.jboss.system.server.profileservice.repository.TypedProfileRepository;
-import org.jboss.vfs.VFS;
 import org.jboss.vfs.VirtualFile;
 
 /**
@@ -219,17 +217,10 @@
             {
                for (ProfileDeployment pd : deployments)
                {
-                  VirtualFile root = pd.getRoot();
-                  if (root != null)
+                  // Only include VFS based deployments
+                  if(pd.getRoot() != null)
                   {
-                     try
-                     {
-                        urls.add(root.toURL().toExternalForm());
-                     }
-                     catch (Exception e)
-                     {
-                        log.warn("Exception while reading root's URL: " + root);
-                     }
+                     urls.add(pd.getName());
                   }
                }
             }
@@ -294,7 +285,7 @@
             for (VirtualFile file : files)
             {
                // the key is URI
-               String name = file.toURI().toString();
+               String name = createDeploymentName(file.toURI());
                // it still exists - remove it
                if (acceptsDeployment(name) == false)
                {




More information about the jboss-cvs-commits mailing list