[jboss-cvs] JBossAS SVN: r99082 - in projects/vfs/branches/dml-zip-rework/src: main/java/org/jboss/vfs/util/automount and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jan 6 18:42:11 EST 2010
Author: johnbailey
Date: 2010-01-06 18:42:11 -0500 (Wed, 06 Jan 2010)
New Revision: 99082
Added:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/AbstractMountOwner.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/Automounter.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/MountOwner.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/SimpleMountOwner.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/VirtualFileOwner.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/util/
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/util/automount/
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/util/automount/AutomounterTestCase.java
Removed:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/Automounter.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTestCase.java
Log:
Updated the Automounter to use MountOwner objects as the owner instead of only VirtualFile
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/Automounter.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/Automounter.java 2010-01-06 23:38:55 UTC (rev 99081)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/Automounter.java 2010-01-06 23:42:11 UTC (rev 99082)
@@ -1,329 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.vfs.util;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.jboss.util.id.GUID;
-import org.jboss.vfs.TempFileProvider;
-import org.jboss.vfs.VFS;
-import org.jboss.vfs.VFSUtils;
-import org.jboss.vfs.VirtualFile;
-import org.jboss.vfs.util.PathTokenizer;
-
-/**
- * Utility used to manage mounting Virtual FileSystems.
- *
- * TODO - Make this thread safe.............
- *
- * @author <a href="jbailey at redhat.com">John Bailey</a>
- */
-public class Automounter
-{
- /* Root entry in the tree. */
- private static final RegistryEntry rootEntry = new RegistryEntry();
-
- /* VirutalFile used as a base mount for 'hidden' original copies of mounted files */
- private static final VirtualFile originalsRoot = VFS.getChild("/.vfs/backups");
-
- /* VirutalFile used as a base for all temporary filesytems created */
- private static final VirtualFile tempRoot = VFS.getChild("/.vfs/tmp");
-
- /* Possible mount types */
- private static enum MountType {
- ZIP, EXPANDED
- };
-
- /**
- * Private constructor
- */
- private Automounter()
- {
- }
-
- /**
- * Mount provided {@link VirtualFile} (if not mounted) and set the owner to be the provided target. (Self owned mount)
- *
- * @param target VirtualFile to mount
- * @throws IOException when the target can not be mounted.
- */
- public static void mount(VirtualFile target) throws IOException
- {
- mount(target, target);
- }
-
- /**
- * Mount provided {@link VirtualFile} (if not mounted) and add an owner entry. Also creates a back-reference to from the owner to the target.
- *
- * @param owner Virtual file that owns the reference to the mount
- * @param target VirtualFile to mount
- * @throws IOException when the target can not be mounted
- */
- public static void mount(VirtualFile owner, VirtualFile target) throws IOException
- {
- RegistryEntry targetEntry = getEntry(target);
- RegistryEntry ownerEntry = getEntry(owner);
- targetEntry.mount(ownerEntry, target, MountType.ZIP);
- }
-
- /**
- * Mount provided {@link VirtualFile} (if not mounted) as an expanded Zip mount and add an owner entry.
- * Also creates a back-reference to from the owner to the target. (Self owned mount)
- *
- * @param owner Virtual file that owns the reference to the mount
- * @param target VirtualFile to mount
- * @throws IOException when the target can not be mounted
- */
- public static void mountExpanded(VirtualFile target) throws IOException
- {
- mountExpanded(target, target);
- }
-
- /**
- * Mount provided {@link VirtualFile} (if not mounted) as an expanded Zip mount and add an owner entry.
- * Also creates a back-reference to from the owner to the target.
- *
- * @param owner Virtual file that owns the reference to the mount
- * @param target VirtualFile to mount
- * @throws IOException when the target can not be mounted
- */
- public static void mountExpanded(VirtualFile owner, VirtualFile target) throws IOException
- {
- RegistryEntry targetEntry = getEntry(target);
- RegistryEntry ownerEntry = getEntry(owner);
- targetEntry.mount(ownerEntry, target, MountType.EXPANDED);
- }
-
- /**
- * Recursively cleanup all mounted handles starting at the provided {@link VirtualFile} location
- * and remove all references to other mounts.
- *
- * @param owner VirtualFile to cleanup
- */
- public static void cleanup(VirtualFile owner)
- {
- getEntry(owner).cleanup();
- }
-
- /**
- * Determines whether a target {@link VirtualFile} is mounted.
- *
- * @param target
- * @return
- */
- public static boolean isMounted(VirtualFile target)
- {
- return getEntry(target).isMounted();
- }
-
- /**
- * Create a backup of the provided root. Only one backup is allowed for a location.
- *
- * @param original the original VirtualFile to backup
- * @return a reference to the backup location
- * @throws IOException if any problems occur during the backup process
- */
- public static VirtualFile backup(VirtualFile original) throws IOException
- {
- RegistryEntry entry = getEntry(original);
- entry.backup(original);
- return entry.backupFile;
- }
-
- /**
- * Get the backup for the provided target
- *
- * @param target the location to get the backup for
- * @return the backup
- */
- public static VirtualFile getBackup(VirtualFile target)
- {
- RegistryEntry entry = getEntry(target);
- return entry.backupFile != null ? entry.backupFile : null;
- }
-
- /**
- * Check to see if a backup exists for the provided location.
- *
- * @param target the location to check for a backup.
- * @return true if the backup exists.
- */
- public static boolean hasBackup(VirtualFile target)
- {
- return getEntry(target).backupFile != null;
- }
-
-
- /**
- * Get the entry from the tree creating the entry if not present.
- *
- * @param virtualFile
- * @return
- */
- private static RegistryEntry getEntry(VirtualFile virtualFile)
- {
- if (virtualFile == null)
- {
- throw new IllegalArgumentException("A valid VirtualFile is required.");
- }
- return rootEntry.find(virtualFile);
- }
-
- private static TempFileProvider getTempFileProvider(String name) throws IOException
- {
- return TempFileProvider.create(name, Executors.newSingleThreadScheduledExecutor());
- }
-
- private static class RegistryEntry
- {
- private final ConcurrentMap<String, RegistryEntry> children = new ConcurrentHashMap<String, RegistryEntry>();
-
- private final Set<RegistryEntry> inboundReferences = new HashSet<RegistryEntry>();
-
- private final Set<RegistryEntry> outboundReferences = new HashSet<RegistryEntry>();
-
- private final List<Closeable> handles = new LinkedList<Closeable>();
-
- private final AtomicBoolean mounted = new AtomicBoolean();
-
- private VirtualFile backupFile;
-
- private void mount(RegistryEntry owner, VirtualFile target, MountType mountType) throws IOException
- {
- if (mounted.compareAndSet(false, true))
- {
- if(target.isFile())
- {
- final TempFileProvider provider = getTempFileProvider(target.getName());
- // Make sure we can get to the original
- backup(target);
- // Copy archive to temporary location to avoid file locking issues
- File copy = copyArchiveFile(target, provider);
-
- if (MountType.ZIP.equals(mountType))
- handles.add(VFS.mountZip(copy, target, provider));
- else
- handles.add(VFS.mountZipExpanded(copy, target, provider));
- }
- }
- if (owner.equals(this) == false)
- {
- inboundReferences.add(owner);
- owner.outboundReferences.add(this);
- }
- }
-
-
- private File copyArchiveFile(VirtualFile target, final TempFileProvider provider) throws IOException,
- FileNotFoundException
- {
- VirtualFile tempLocation = tempRoot.getChild(GUID.asString());
- handles.add(VFS.mountTemp(tempLocation, provider));
- File copy = tempLocation.getChild(target.getName()).getPhysicalFile();
- VFSUtils.copyStreamAndClose(target.openStream(), new FileOutputStream(copy));
- return copy;
- }
-
- private void removeInboundReference(RegistryEntry owner)
- {
- inboundReferences.remove(owner);
- if (inboundReferences.isEmpty())
- {
- cleanup();
- }
- }
-
- private void cleanup()
- {
- VFSUtils.safeClose(handles);
- handles.clear();
-
- Collection<RegistryEntry> entries = getEntriesRecursive();
- for (RegistryEntry entry : entries)
- {
- entry.cleanup();
- }
- for (RegistryEntry entry : outboundReferences)
- {
- entry.removeInboundReference(this);
- }
- mounted.set(false);
- }
-
- private boolean isMounted()
- {
- return !handles.isEmpty();
- }
-
- private RegistryEntry find(VirtualFile file)
- {
- return find(PathTokenizer.getTokens(file.getPathName()));
- }
-
- private RegistryEntry find(List<String> path)
- {
- if (path.isEmpty())
- {
- return this;
- }
- String current = path.remove(0);
- children.putIfAbsent(current, new RegistryEntry());
- RegistryEntry childEntry = children.get(current);
- return childEntry.find(path);
- }
-
- private Collection<RegistryEntry> getEntriesRecursive()
- {
- List<RegistryEntry> allHandles = new LinkedList<RegistryEntry>();
- collectEntries(this, allHandles);
- return allHandles;
- }
-
- private void collectEntries(RegistryEntry registryEntry, List<RegistryEntry> entries)
- {
- for (RegistryEntry childEntry : registryEntry.children.values())
- {
- collectEntries(childEntry, entries);
- entries.add(childEntry);
- }
- }
-
- private void backup(VirtualFile target) throws IOException
- {
- backupFile = originalsRoot.getChild(GUID.asString() + target.getName());
- handles.add(VFS.mountReal(target.getPhysicalFile(), backupFile));
- }
- }
-}
Added: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/AbstractMountOwner.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/AbstractMountOwner.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/AbstractMountOwner.java 2010-01-06 23:42:11 UTC (rev 99082)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.vfs.util.automount;
+
+/**
+ * Abstract MountOwner used to wrap a real object as an owner.
+ *
+ * @author <a href="jbailey at redhat.com">John Bailey</a>
+ *
+ * @param <T> the type of the actual owner
+ */
+public abstract class AbstractMountOwner<T> implements MountOwner
+{
+ private final T owner;
+
+ /**
+ * Construct with an object.
+ *
+ * @param owner the actual owner
+ */
+ protected AbstractMountOwner(T owner)
+ {
+ this.owner = owner;
+ }
+
+ /**
+ * Get the owner object
+ *
+ * @return the actual owner
+ */
+ protected T getOwner() {
+ return owner;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean equals(Object other)
+ {
+ if(!(other instanceof AbstractMountOwner))
+ return false;
+ return getOwner().equals(AbstractMountOwner.class.cast(other).getOwner());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return getOwner().hashCode();
+ }
+}
Copied: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/Automounter.java (from rev 98954, projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/Automounter.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/Automounter.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/Automounter.java 2010-01-06 23:42:11 UTC (rev 99082)
@@ -0,0 +1,278 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.vfs.util.automount;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.jboss.util.id.GUID;
+import org.jboss.vfs.TempFileProvider;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VFSUtils;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.util.PathTokenizer;
+
+/**
+ * Utility used to manage mounting Virtual FileSystems.
+ *
+ * TODO - Make this thread safe.............
+ *
+ * @author <a href="jbailey at redhat.com">John Bailey</a>
+ */
+public class Automounter
+{
+ /* Root entry in the tree. */
+ private static final RegistryEntry rootEntry = new RegistryEntry();
+
+ /* Map of owners and their references */
+ private static final ConcurrentMap<MountOwner, Set<RegistryEntry>> ownerReferences = new ConcurrentHashMap<MountOwner, Set<RegistryEntry>>();
+
+ /* VirutalFile used as a base mount for 'hidden' original copies of mounted files */
+ private static final VirtualFile originalsRoot = VFS.getChild("/.vfs/backups");
+
+ /**
+ * Private constructor
+ */
+ private Automounter()
+ {
+ }
+
+ /**
+ * Mount provided {@link VirtualFile} (if not mounted) and set the owner to be the provided target. (Self owned mount)
+ *
+ * @param target VirtualFile to mount
+ * @throws IOException when the target can not be mounted.
+ */
+ public static void mount(VirtualFile target) throws IOException
+ {
+ mount(new VirtualFileOwner(target), target);
+ }
+
+ /**
+ * Mount provided {@link VirtualFile} (if not mounted) and add an owner entry. Also creates a back-reference to from the owner to the target.
+ *
+ * @param owner MountOwner that owns the reference to the mount
+ * @param target VirtualFile to mount
+ * @throws IOException when the target can not be mounted
+ */
+ public static void mount(MountOwner owner, VirtualFile target) throws IOException
+ {
+ RegistryEntry targetEntry = getEntry(target);
+ targetEntry.mount(target);
+ targetEntry.inboundReferences.add(owner);
+ ownerReferences.putIfAbsent(owner, new HashSet<RegistryEntry>());
+ ownerReferences.get(owner).add(targetEntry);
+ }
+
+ /**
+ * Cleanup all references from the {@link MountOwner}. Cleanup any mounted entries that become un-referenced in the process.
+ *
+ * @param owner {@link MountOwner} to cleanup references for
+ */
+ public static void cleanup(MountOwner owner)
+ {
+ final Set<RegistryEntry> references = ownerReferences.remove(owner);
+ if(references != null)
+ {
+ for (RegistryEntry entry : references)
+ {
+ entry.removeInboundReference(owner);
+ }
+ }
+ owner.onCleanup();
+ }
+
+ /**
+ * Determines whether a target {@link VirtualFile} is mounted.
+ *
+ * @param target
+ * @return
+ */
+ public static boolean isMounted(VirtualFile target)
+ {
+ return getEntry(target).isMounted();
+ }
+
+ /**
+ * Create a backup of the provided root. Only one backup is allowed for a location.
+ * TODO: Find a way to remove the need for this.
+ *
+ * @param original the original VirtualFile to backup
+ * @return a reference to the backup location
+ * @throws IOException if any problems occur during the backup process
+ */
+ public static VirtualFile backup(VirtualFile original) throws IOException
+ {
+ RegistryEntry entry = getEntry(original);
+ entry.backup(original);
+ return entry.backupFile;
+ }
+
+ /**
+ * Get the backup for the provided target
+ * TODO: Find a way to remove the need for this.
+ *
+ * @param target the location to get the backup for
+ * @return the backup
+ */
+ public static VirtualFile getBackup(VirtualFile target)
+ {
+ RegistryEntry entry = getEntry(target);
+ return entry.backupFile != null ? entry.backupFile : null;
+ }
+
+ /**
+ * Check to see if a backup exists for the provided location.
+ * TODO: Find a way to remove the need for this.
+ *
+ * @param target the location to check for a backup.
+ * @return true if the backup exists.
+ */
+ public static boolean hasBackup(VirtualFile target)
+ {
+ return getEntry(target).backupFile != null;
+ }
+
+
+ /**
+ * Get the entry from the tree creating the entry if not present.
+ *
+ * @param virtualFile
+ * @return
+ */
+ static RegistryEntry getEntry(VirtualFile virtualFile)
+ {
+ if (virtualFile == null)
+ {
+ throw new IllegalArgumentException("A valid VirtualFile is required.");
+ }
+ return rootEntry.find(virtualFile);
+ }
+
+ private static TempFileProvider getTempFileProvider(String name) throws IOException
+ {
+ return TempFileProvider.create(name, Executors.newSingleThreadScheduledExecutor());
+ }
+
+ static class RegistryEntry
+ {
+ private final ConcurrentMap<String, RegistryEntry> children = new ConcurrentHashMap<String, RegistryEntry>();
+
+ private final Set<MountOwner> inboundReferences = new HashSet<MountOwner>();
+
+ private final List<Closeable> handles = new LinkedList<Closeable>();
+
+ private final AtomicBoolean mounted = new AtomicBoolean();
+
+ private VirtualFile backupFile;
+
+ private void mount(VirtualFile target) throws IOException
+ {
+ if (mounted.compareAndSet(false, true))
+ {
+ if(target.isFile())
+ {
+ final TempFileProvider provider = getTempFileProvider(target.getName());
+ // Make sure we can get to the original
+ backup(target);
+ handles.add(VFS.mountZip(target, target, provider));
+ }
+ }
+ }
+
+ private void removeInboundReference(MountOwner owner)
+ {
+ inboundReferences.remove(owner);
+ if (inboundReferences.isEmpty())
+ {
+ cleanup();
+ }
+ }
+
+ void cleanup()
+ {
+ VFSUtils.safeClose(handles);
+ handles.clear();
+
+ Collection<RegistryEntry> entries = getEntriesRecursive();
+ for (RegistryEntry entry : entries)
+ {
+ entry.cleanup();
+ }
+
+ mounted.set(false);
+ }
+
+ private boolean isMounted()
+ {
+ return !handles.isEmpty();
+ }
+
+ private RegistryEntry find(VirtualFile file)
+ {
+ return find(PathTokenizer.getTokens(file.getPathName()));
+ }
+
+ private RegistryEntry find(List<String> path)
+ {
+ if (path.isEmpty())
+ {
+ return this;
+ }
+ String current = path.remove(0);
+ children.putIfAbsent(current, new RegistryEntry());
+ RegistryEntry childEntry = children.get(current);
+ return childEntry.find(path);
+ }
+
+ private Collection<RegistryEntry> getEntriesRecursive()
+ {
+ List<RegistryEntry> allHandles = new LinkedList<RegistryEntry>();
+ collectEntries(this, allHandles);
+ return allHandles;
+ }
+
+ private void collectEntries(RegistryEntry registryEntry, List<RegistryEntry> entries)
+ {
+ for (RegistryEntry childEntry : registryEntry.children.values())
+ {
+ collectEntries(childEntry, entries);
+ entries.add(childEntry);
+ }
+ }
+
+ private void backup(VirtualFile target) throws IOException
+ {
+ backupFile = originalsRoot.getChild(GUID.asString() + target.getName());
+ handles.add(VFS.mountReal(target.getPhysicalFile(), backupFile));
+ }
+ }
+}
Added: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/MountOwner.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/MountOwner.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/MountOwner.java 2010-01-06 23:42:11 UTC (rev 99082)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.vfs.util.automount;
+
+/**
+ * An owner of a reference to an automounted resource.
+ *
+ * @author <a href="jbailey at redhat.com">John Bailey</a>
+ *
+ */
+public interface MountOwner
+{
+ /**
+ * A callback method allowing the mount owner to perform any addition cleanup
+ * specific to the owner type.
+ */
+ void onCleanup();
+}
Added: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/SimpleMountOwner.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/SimpleMountOwner.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/SimpleMountOwner.java 2010-01-06 23:42:11 UTC (rev 99082)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.vfs.util.automount;
+
+/**
+ * Simple mount owner wrapper relying on any object type as the owner.
+ *
+ * @author <a href="jbailey at redhat.com">John Bailey</a>
+ *
+ */
+public class SimpleMountOwner extends AbstractMountOwner<Object>
+{
+ /**
+ * Construct with a new object as the owner
+ */
+ public SimpleMountOwner() {
+ this(new Object());
+ }
+
+ /**
+ * Construct with the provided object as the owner
+ *
+ * @param object the actual owner
+ */
+ public SimpleMountOwner(Object owner)
+ {
+ super(owner);
+ }
+
+ /**
+ * No-op cleanup method
+ */
+ @Override
+ public void onCleanup()
+ {
+ }
+}
Added: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/VirtualFileOwner.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/VirtualFileOwner.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/util/automount/VirtualFileOwner.java 2010-01-06 23:42:11 UTC (rev 99082)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.vfs.util.automount;
+
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * Mount owner using a {@link VirtualFile} as the actual owner.
+ *
+ * @author <a href="jbailey at redhat.com">John Bailey</a>
+ *
+ */
+public class VirtualFileOwner extends AbstractMountOwner<VirtualFile>
+{
+ /**
+ * Constructed with a {@link VirtualFile} owner
+ *
+ * @param file the {@link VirtualFile} owning mount references
+ */
+ public VirtualFileOwner(VirtualFile file)
+ {
+ super(file);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Execute a forced recursive deep clean on the {@link VirtualFile} owner.
+ */
+ @Override
+ public void onCleanup()
+ {
+ Automounter.getEntry(getOwner()).cleanup();
+ }
+}
Deleted: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTestCase.java 2010-01-06 23:38:55 UTC (rev 99081)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTestCase.java 2010-01-06 23:42:11 UTC (rev 99082)
@@ -1,123 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.test.vfs;
-
-import org.jboss.vfs.VirtualFile;
-import org.jboss.vfs.util.Automounter;
-
-/**
- * Test for {@link Automounter}
- *
- * @author <a href="jbailey at redhat.com">John Bailey</a>
- */
-public class AutomounterTestCase extends AbstractVFSTest
-{
-
- public AutomounterTestCase(String name)
- {
- super(name);
- }
-
- public void testMountAndCleanup() throws Exception
- {
- VirtualFile virtualFile = getVirtualFile("/vfs/test/simple.ear");
- Automounter.mount(virtualFile, virtualFile);
- assertTrue(Automounter.isMounted(virtualFile));
- Automounter.cleanup(virtualFile);
- assertFalse(Automounter.isMounted(virtualFile));
- }
-
- public void testCleanupWithOwner() throws Exception
- {
- VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
- Automounter.mount(earVirtualFile);
-
- VirtualFile jarVirtualFile = earVirtualFile.getChild("archive.jar");
- Automounter.mount(earVirtualFile, jarVirtualFile);
-
- VirtualFile warVirtualFile = earVirtualFile.getChild("simple.war");
- Automounter.mount(earVirtualFile, warVirtualFile);
-
- assertTrue(Automounter.isMounted(earVirtualFile));
- assertTrue(Automounter.isMounted(warVirtualFile));
- assertTrue(Automounter.isMounted(jarVirtualFile));
-
- Automounter.cleanup(earVirtualFile);
-
- assertFalse(Automounter.isMounted(earVirtualFile));
- assertFalse(Automounter.isMounted(warVirtualFile));
- assertFalse(Automounter.isMounted(jarVirtualFile));
- }
-
- public void testCleanupRecursive() throws Exception
- {
- VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
- Automounter.mount(earVirtualFile);
-
- VirtualFile jarVirtualFile = earVirtualFile.getChild("archive.jar");
- Automounter.mount(jarVirtualFile);
-
- VirtualFile warVirtualFile = earVirtualFile.getChild("simple.war");
- Automounter.mount(warVirtualFile);
-
- assertTrue(Automounter.isMounted(earVirtualFile));
- assertTrue(Automounter.isMounted(warVirtualFile));
- assertTrue(Automounter.isMounted(jarVirtualFile));
-
- Automounter.cleanup(earVirtualFile);
-
- assertFalse(Automounter.isMounted(earVirtualFile));
- assertFalse(Automounter.isMounted(warVirtualFile));
- assertFalse(Automounter.isMounted(jarVirtualFile));
- }
-
- public void testCleanupRefereces() throws Exception
- {
- VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
- Automounter.mount(earVirtualFile);
-
- VirtualFile jarVirtualFile = getVirtualFile("/vfs/test/jar1.jar");
- Automounter.mount(earVirtualFile, jarVirtualFile);
-
- VirtualFile warVirtualFile = getVirtualFile("/vfs/test/filesonly.war");
- Automounter.mount(earVirtualFile, warVirtualFile);
-
- assertTrue(Automounter.isMounted(earVirtualFile));
- assertTrue(Automounter.isMounted(warVirtualFile));
- assertTrue(Automounter.isMounted(jarVirtualFile));
-
- VirtualFile otherEarVirtualFile = getVirtualFile("/vfs/test/spring-ear.ear");
- Automounter.mount(otherEarVirtualFile, jarVirtualFile);
-
- Automounter.cleanup(earVirtualFile);
-
- assertFalse(Automounter.isMounted(earVirtualFile));
- assertFalse(Automounter.isMounted(warVirtualFile));
- assertTrue("Should not have unmounted the reference from two locations", Automounter.isMounted(jarVirtualFile));
-
- Automounter.cleanup(otherEarVirtualFile);
- assertFalse(Automounter.isMounted(jarVirtualFile));
- }
-
-
-
-}
Copied: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/util/automount/AutomounterTestCase.java (from rev 98948, projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/AutomounterTestCase.java)
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/util/automount/AutomounterTestCase.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/vfs/util/automount/AutomounterTestCase.java 2010-01-06 23:42:11 UTC (rev 99082)
@@ -0,0 +1,183 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.test.vfs.util.automount;
+
+import org.jboss.test.vfs.AbstractVFSTest;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.util.automount.Automounter;
+import org.jboss.vfs.util.automount.MountOwner;
+import org.jboss.vfs.util.automount.SimpleMountOwner;
+import org.jboss.vfs.util.automount.VirtualFileOwner;
+
+/**
+ * Test for {@link Automounter}
+ *
+ * @author <a href="jbailey at redhat.com">John Bailey</a>
+ */
+public class AutomounterTestCase extends AbstractVFSTest
+{
+
+ public AutomounterTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testMountAndCleanup() throws Exception
+ {
+ VirtualFile virtualFile = getVirtualFile("/vfs/test/simple.ear");
+ MountOwner owner = new VirtualFileOwner(virtualFile);
+ Automounter.mount(owner, virtualFile);
+ assertTrue(Automounter.isMounted(virtualFile));
+ Automounter.cleanup(owner);
+ assertFalse(Automounter.isMounted(virtualFile));
+ }
+
+ public void testCleanupWithOwner() throws Exception
+ {
+ VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
+ Automounter.mount(earVirtualFile);
+
+ VirtualFileOwner owner = new VirtualFileOwner(earVirtualFile);
+
+ VirtualFile jarVirtualFile = earVirtualFile.getChild("archive.jar");
+ Automounter.mount(owner, jarVirtualFile);
+
+ VirtualFile warVirtualFile = earVirtualFile.getChild("simple.war");
+ Automounter.mount(owner, warVirtualFile);
+
+ assertTrue(Automounter.isMounted(earVirtualFile));
+ assertTrue(Automounter.isMounted(warVirtualFile));
+ assertTrue(Automounter.isMounted(jarVirtualFile));
+
+ Automounter.cleanup(owner);
+
+ assertFalse(Automounter.isMounted(earVirtualFile));
+ assertFalse(Automounter.isMounted(warVirtualFile));
+ assertFalse(Automounter.isMounted(jarVirtualFile));
+ }
+
+ public void testCleanupRecursive() throws Exception
+ {
+ VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
+ Automounter.mount(earVirtualFile);
+
+ VirtualFile jarVirtualFile = earVirtualFile.getChild("archive.jar");
+ Automounter.mount(jarVirtualFile);
+
+ VirtualFile warVirtualFile = earVirtualFile.getChild("simple.war");
+ Automounter.mount(warVirtualFile);
+
+ assertTrue(Automounter.isMounted(earVirtualFile));
+ assertTrue(Automounter.isMounted(warVirtualFile));
+ assertTrue(Automounter.isMounted(jarVirtualFile));
+
+ Automounter.cleanup(new VirtualFileOwner(earVirtualFile));
+
+ assertFalse(Automounter.isMounted(earVirtualFile));
+ assertFalse(Automounter.isMounted(warVirtualFile));
+ assertFalse(Automounter.isMounted(jarVirtualFile));
+ }
+
+ public void testCleanupRefereces() throws Exception
+ {
+ VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
+ Automounter.mount(earVirtualFile);
+
+ VirtualFileOwner owner = new VirtualFileOwner(earVirtualFile);
+
+ VirtualFile jarVirtualFile = getVirtualFile("/vfs/test/jar1.jar");
+ Automounter.mount(owner, jarVirtualFile);
+
+ VirtualFile warVirtualFile = getVirtualFile("/vfs/test/filesonly.war");
+ Automounter.mount(owner, warVirtualFile);
+
+ assertTrue(Automounter.isMounted(earVirtualFile));
+ assertTrue(Automounter.isMounted(warVirtualFile));
+ assertTrue(Automounter.isMounted(jarVirtualFile));
+
+ VirtualFile otherEarVirtualFile = getVirtualFile("/vfs/test/spring-ear.ear");
+ VirtualFileOwner otherOwner = new VirtualFileOwner(otherEarVirtualFile);
+ Automounter.mount(otherOwner, jarVirtualFile);
+
+ Automounter.cleanup(owner);
+
+ assertFalse(Automounter.isMounted(earVirtualFile));
+ assertFalse(Automounter.isMounted(warVirtualFile));
+ assertTrue("Should not have unmounted the reference from two locations", Automounter.isMounted(jarVirtualFile));
+
+ Automounter.cleanup(otherOwner);
+ assertFalse(Automounter.isMounted(jarVirtualFile));
+ }
+
+ public void testCleanupReferecesSameVF() throws Exception
+ {
+ VirtualFile earVirtualFile = getVirtualFile("/vfs/test/simple.ear");
+ Automounter.mount(earVirtualFile);
+
+ VirtualFileOwner owner = new VirtualFileOwner(earVirtualFile);
+
+ VirtualFile jarVirtualFile = getVirtualFile("/vfs/test/jar1.jar");
+ Automounter.mount(owner, jarVirtualFile);
+
+ VirtualFileOwner otherOwner = new VirtualFileOwner(earVirtualFile);
+ Automounter.mount(otherOwner, jarVirtualFile);
+
+ Automounter.cleanup(owner);
+
+ assertFalse("Should have been unmounted since the VirtualFile is the same", Automounter.isMounted(jarVirtualFile));
+ }
+
+ public void testCleanupReferecesSimpleOwner() throws Exception
+ {
+ MountOwner owner = new SimpleMountOwner(new Object());
+
+ VirtualFile jarVirtualFile = getVirtualFile("/vfs/test/jar1.jar");
+ Automounter.mount(owner, jarVirtualFile);
+
+ MountOwner otherOwner = new SimpleMountOwner(new Object());
+ Automounter.mount(otherOwner, jarVirtualFile);
+
+ Automounter.cleanup(owner);
+
+ assertTrue("Should not have unmounted the reference from two locations", Automounter.isMounted(jarVirtualFile));
+
+ Automounter.cleanup(otherOwner);
+ assertFalse(Automounter.isMounted(jarVirtualFile));
+ }
+
+ public void testCleanupReferecesSimpleOwnerSameObj() throws Exception
+ {
+ Object ownerObject = new Object();
+ MountOwner owner = new SimpleMountOwner(ownerObject);
+
+ VirtualFile jarVirtualFile = getVirtualFile("/vfs/test/jar1.jar");
+ Automounter.mount(owner, jarVirtualFile);
+
+ MountOwner otherOwner = new SimpleMountOwner(ownerObject);
+ Automounter.mount(otherOwner, jarVirtualFile);
+
+ Automounter.cleanup(owner);
+
+ assertFalse("Should have been unmounted since the owner object is the same", Automounter.isMounted(jarVirtualFile));
+ }
+
+}
More information about the jboss-cvs-commits
mailing list