[jboss-cvs] JBossAS SVN: r76960 - in projects/jboss-deployers/trunk/deployers-vfs/src: main/org/jboss/deployers/vfs/plugins/client and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 12 00:39:29 EDT 2008


Author: alesj
Date: 2008-08-12 00:39:29 -0400 (Tue, 12 Aug 2008)
New Revision: 76960

Added:
   projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/vfs/
   projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/vfs/VirtualFileSerializator.java
Modified:
   projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/client/AbstractVFSDeployment.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java
   projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/AbstractStructureTest.java
   projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/ear/test/InnerModificationUnitTestCase.java
   projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/explicit/test/ModificationTypeUnitTestCase.java
Log:
[JBDEPLOY-72]; minimize vfs deployment (context) serialization.

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/client/AbstractVFSDeployment.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/client/AbstractVFSDeployment.java	2008-08-12 01:10:58 UTC (rev 76959)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/client/AbstractVFSDeployment.java	2008-08-12 04:39:29 UTC (rev 76960)
@@ -22,15 +22,12 @@
 package org.jboss.deployers.vfs.plugins.client;
 
 import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamField;
-import java.net.URISyntaxException;
-import java.net.URL;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 
 import org.jboss.deployers.client.plugins.deployment.AbstractDeployment;
+import org.jboss.deployers.vfs.plugins.vfs.VirtualFileSerializator;
 import org.jboss.deployers.vfs.spi.client.VFSDeployment;
-import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -43,17 +40,8 @@
 public class AbstractVFSDeployment extends AbstractDeployment implements VFSDeployment
 {
    /** The serialVersionUID */
-   private static final long serialVersionUID = 3992263833911364088L;
+   private static final long serialVersionUID = 2L;
 
-   private static final ObjectStreamField[] serialPersistentFields =
-   {
-      new ObjectStreamField("rootUrl", URL.class),
-      new ObjectStreamField("path", String.class),
-   };
-
-   /** Minimal info to get full vfs file structure */
-   private URL rootUrl;
-   private String path;
    /** The root */
    private transient VirtualFile root;
 
@@ -97,21 +85,8 @@
       this.root = root;
    }
 
-   @SuppressWarnings("deprecation")
    public VirtualFile getRoot()
    {
-      if (root == null)
-      {
-         try
-         {
-            VirtualFile top = VFS.getRoot(rootUrl);
-            root = top.findChild(path);
-         }
-         catch (IOException e)
-         {
-            throw new IllegalArgumentException("Cannot find root: " + e);           
-         }
-      }
       return root;
    }
 
@@ -127,30 +102,16 @@
       return "AbstractVFSDeployment(" + getSimpleName() + ")";
    }
 
-   private void writeObject(ObjectOutputStream out) throws IOException, URISyntaxException
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
    {
-      URL url = rootUrl;
-      if (url == null)
-      {
-         VFS vfs = getRoot().getVFS();
-         url = vfs.getRoot().toURL();
-      }
-      String pathName = path;
-      if (pathName == null)
-         pathName = getRoot().getPathName();
-
-      out.defaultWriteObject();
-      ObjectOutputStream.PutField fields = out.putFields();
-      fields.put("rootUrl", url);
-      fields.put("path", pathName);
-      out.writeFields();
+      super.readExternal(in);
+      VirtualFileSerializator serializator = (VirtualFileSerializator)in.readObject();
+      root = serializator.getFile();
    }
 
-   private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
+   public void writeExternal(ObjectOutput out) throws IOException
    {
-      in.defaultReadObject();
-      ObjectInputStream.GetField fields = in.readFields();
-      rootUrl = (URL) fields.get("rootUrl", null);
-      path = (String) fields.get("path", null);
+      super.writeExternal(out);
+      out.writeObject(new VirtualFileSerializator(root));
    }
 }

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java	2008-08-12 01:10:58 UTC (rev 76959)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java	2008-08-12 04:39:29 UTC (rev 76960)
@@ -33,6 +33,7 @@
 import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentResourceLoader;
+import org.jboss.deployers.vfs.plugins.vfs.VirtualFileSerializator;
 import org.jboss.logging.Logger;
 import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
@@ -52,13 +53,13 @@
    private static final Logger log = Logger.getLogger(AbstractVFSDeploymentContext.class);
 
    /** The root virtual file */
-   private VirtualFile root;
+   private transient VirtualFile root;
    
    /** The meta data locations */
-   private List<VirtualFile> metaDataLocations;
+   private transient List<VirtualFile> metaDataLocations;
    
    /** The class paths */
-   private List<VirtualFile> classPath;
+   private transient List<VirtualFile> classPath;
    
    /** The loader */
    private transient VFSDeploymentResourceLoader loader;
@@ -387,11 +388,16 @@
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
    {
       super.readExternal(in);
-      root = (VirtualFile) in.readObject();
+      VirtualFileSerializator serializator = (VirtualFileSerializator) in.readObject();
+      root = serializator.getFile();
       boolean isNullOrEmpty = in.readBoolean();
       if (isNullOrEmpty == false)
-         metaDataLocations = (List<VirtualFile>) in.readObject();
-      classPath = (List) in.readObject();
+      {
+         List<VirtualFileSerializator> mdlSerializators = (List<VirtualFileSerializator>)in.readObject();
+         metaDataLocations = VirtualFileSerializator.toVirtualFiles(mdlSerializators);
+      }
+      List<VirtualFileSerializator> cpSerializators = (List<VirtualFileSerializator>)in.readObject();
+      classPath = VirtualFileSerializator.toVirtualFiles(cpSerializators);
    }
 
    /**
@@ -404,11 +410,11 @@
    public void writeExternal(ObjectOutput out) throws IOException
    {
       super.writeExternal(out);
-      out.writeObject(root);
+      out.writeObject(new VirtualFileSerializator(root));
       boolean isNullOrEmpty = metaDataLocations == null || metaDataLocations.isEmpty();
       out.writeBoolean(isNullOrEmpty);
       if (isNullOrEmpty == false)
-         out.writeObject(metaDataLocations);
-      out.writeObject(classPath);
+         out.writeObject(VirtualFileSerializator.toVirtualFileSerializators(metaDataLocations));
+      out.writeObject(VirtualFileSerializator.toVirtualFileSerializators(classPath));
    }
 }

Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/vfs/VirtualFileSerializator.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/vfs/VirtualFileSerializator.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/vfs/VirtualFileSerializator.java	2008-08-12 04:39:29 UTC (rev 76960)
@@ -0,0 +1,153 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss 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.deployers.vfs.plugins.vfs;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * A minimal way of serializing VirtualFiles.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class VirtualFileSerializator implements Serializable
+{
+   private static final long serialVersionUID = 1L;
+
+   private static final ObjectStreamField[] serialPersistentFields =
+   {
+      new ObjectStreamField("rootUrl", URL.class),
+      new ObjectStreamField("path", String.class),
+   };
+
+   /** Minimal info to get full vfs file structure */
+   private URL rootUrl;
+   private String path;
+   /** The root */
+   private transient VirtualFile file;
+
+   public VirtualFileSerializator()
+   {
+   }
+
+   public VirtualFileSerializator(VirtualFile file)
+   {
+      this.file = file;
+   }
+
+   /**
+    * Transform VirtualFileSerializators to VirtualFiles.
+    *
+    * @param serializators the serializators
+    * @return virtual files
+    * @throws IOException for any error
+    */
+   public static List<VirtualFile> toVirtualFiles(List<VirtualFileSerializator> serializators) throws IOException
+   {
+      if (serializators == null)
+         return null;
+      if (serializators.isEmpty())
+         return Collections.emptyList();
+
+      List<VirtualFile> files = new ArrayList<VirtualFile>(serializators.size());
+      for (VirtualFileSerializator serializator : serializators)
+         files.add(serializator.getFile());
+
+      return files;
+   }
+
+   /**
+    * Transform VirtualFiles to VirtualFileSerializators.
+    *
+    * @param files the virtual files
+    * @return serializators
+    * @throws IOException for any error
+    */
+   public static List<VirtualFileSerializator> toVirtualFileSerializators(List<VirtualFile> files) throws IOException
+   {
+      if (files == null)
+         return null;
+      if (files.isEmpty())
+         return Collections.emptyList();
+
+      List<VirtualFileSerializator> serializators = new ArrayList<VirtualFileSerializator>(files.size());
+      for (VirtualFile file : files)
+         serializators.add(new VirtualFileSerializator(file));
+
+      return serializators;
+   }
+
+   /**
+    * Get the virtual file.
+    *
+    * @return virtual file instance
+    * @throws IOException for any error
+    */
+   @SuppressWarnings("deprecation")
+   public VirtualFile getFile() throws IOException
+   {
+      if (file == null)
+      {
+         VirtualFile root = VFS.getRoot(rootUrl);
+         file = root.findChild(path);
+      }
+      return file;
+   }
+
+   // write just url and path
+   private void writeObject(ObjectOutputStream out) throws IOException, URISyntaxException
+   {
+      URL url = rootUrl;
+      if (url == null)
+      {
+         VFS vfs = getFile().getVFS();
+         url = vfs.getRoot().toURL();
+      }
+      String pathName = path;
+      if (pathName == null)
+         pathName = getFile().getPathName();
+
+      ObjectOutputStream.PutField fields = out.putFields();
+      fields.put("rootUrl", url);
+      fields.put("path", pathName);
+      out.writeFields();
+   }
+
+   // read url and path
+   private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
+   {
+      ObjectInputStream.GetField fields = in.readFields();
+      rootUrl = (URL) fields.get("rootUrl", null);
+      path = (String) fields.get("path", null);
+   }
+}

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/AbstractStructureTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/AbstractStructureTest.java	2008-08-12 01:10:58 UTC (rev 76959)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/AbstractStructureTest.java	2008-08-12 04:39:29 UTC (rev 76960)
@@ -196,13 +196,7 @@
    
    protected VFSDeploymentContext determineStructureWithStructureDeployer(VFSDeployment deployment, StructureDeployer structureDeployer) throws Exception
    {
-      VFSStructuralDeployersImpl structuralDeployers = new VFSStructuralDeployersImpl();
-      VFSStructureBuilder builder = new VFSStructureBuilder();
-      structuralDeployers.setStructureBuilder(builder);
-      
-      structuralDeployers.addDeployer(structureDeployer);
-      
-      return (VFSDeploymentContext) structuralDeployers.determineStructure(deployment);
+      return determineStructureWithStructureDeployers(deployment, structureDeployer);
    }
    
    protected VFSDeploymentContext determineStructureWithAllStructureDeployers(VFSDeployment deployment) throws Exception
@@ -212,14 +206,23 @@
    
    protected VFSDeploymentContext determineStructureWithStructureDeployers(VFSDeployment deployment, StructureDeployer... deployers) throws Exception
    {
+      return determineStructureWithStructureDeployers(deployment, true, deployers);
+   }
+
+   protected VFSDeploymentContext determineStructureWithStructureDeployers(VFSDeployment deployment, boolean serialize, StructureDeployer... deployers) throws Exception
+   {
       VFSStructuralDeployersImpl structuralDeployers = new VFSStructuralDeployersImpl();
       VFSStructureBuilder builder = new VFSStructureBuilder();
       structuralDeployers.setStructureBuilder(builder);
       
       for (StructureDeployer deployer : deployers)
          structuralDeployers.addDeployer(deployer);
-      
-      return (VFSDeploymentContext) structuralDeployers.determineStructure(deployment);
+
+      VFSDeploymentContext context = (VFSDeploymentContext)structuralDeployers.determineStructure(deployment);
+      if (serialize)
+         return serializeDeserialize(context, VFSDeploymentContext.class);
+      else
+         return context;
    }
    
    protected VFSDeploymentContext deploy(String context, String path) throws Throwable
@@ -262,7 +265,8 @@
    protected VFSDeployment createDeployment(String context, String path) throws Exception
    {
       VirtualFile root = getVirtualFile(context, path);
-      return VFSDeploymentFactory.getInstance().createVFSDeployment(root);
+      VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(root);
+      return serializeDeserialize(deployment, VFSDeployment.class);
    }
 
    protected VirtualFile getVirtualFile(String root, String path) throws Exception

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/ear/test/InnerModificationUnitTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/ear/test/InnerModificationUnitTestCase.java	2008-08-12 01:10:58 UTC (rev 76959)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/ear/test/InnerModificationUnitTestCase.java	2008-08-12 04:39:29 UTC (rev 76960)
@@ -57,7 +57,8 @@
 
    protected VFSDeploymentContext determineStructure(VFSDeployment deployment) throws Exception
    {
-      return determineStructureWithStructureDeployers(deployment, new JARStructure(), new WarUnpackStructure(), new FileStructure());
+      // TODO - check serialization of modifed roots
+      return determineStructureWithStructureDeployers(deployment, false, new JARStructure(), new WarUnpackStructure(), new FileStructure());
    }
 
    public void testExplicitInnerUnpack() throws Throwable

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/explicit/test/ModificationTypeUnitTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/explicit/test/ModificationTypeUnitTestCase.java	2008-08-12 01:10:58 UTC (rev 76959)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/explicit/test/ModificationTypeUnitTestCase.java	2008-08-12 04:39:29 UTC (rev 76960)
@@ -57,7 +57,8 @@
 
    protected VFSDeploymentContext determineStructure(VFSDeployment deployment) throws Exception
    {
-      return determineStructureWithStructureDeployers(deployment, new DeclaredStructure(), new JARStructure(), new WARStructure(), new FileStructure());
+      // TODO - check serialization of modifed roots
+      return determineStructureWithStructureDeployers(deployment, false, new DeclaredStructure(), new JARStructure(), new WARStructure(), new FileStructure());
    }
 
    public void testExplicitInnerUnpack() throws Throwable




More information about the jboss-cvs-commits mailing list