You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ec...@apache.org on 2014/11/19 04:56:29 UTC
svn commit: r1640477 - in /commons/proper/vfs/trunk:
core/src/main/java/org/apache/commons/vfs2/impl/ src/changes/
Author: ecki
Date: Wed Nov 19 03:56:29 2014
New Revision: 1640477
URL: http://svn.apache.org/r1640477
Log:
[VFS-544] Allow virtual file system to be closed. Renamed map to typeMap. Javadoc fixes.
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VirtualFileProvider.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VirtualFileSystem.java
commons/proper/vfs/trunk/src/changes/changes.xml
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java?rev=1640477&r1=1640476&r2=1640477&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java Wed Nov 19 03:56:29 2014
@@ -86,12 +86,7 @@ public class DefaultFileSystemManager im
/**
* Mappings of file types.
*/
- private final FileTypeMap map = new FileTypeMap();
-
- /**
- * The virtual file provider.
- */
- private final VirtualFileProvider vfsProvider = new VirtualFileProvider();
+ private final FileTypeMap typeMap = new FileTypeMap();
/**
@@ -149,6 +144,11 @@ public class DefaultFileSystemManager im
private TemporaryFileStore tempFileStore;
/**
+ * The virtual file provider.
+ */
+ private VirtualFileProvider vfsProvider;
+
+ /**
* Flag, if manager is initialized (after init() and before close()).
*/
private boolean init;
@@ -245,7 +245,7 @@ public class DefaultFileSystemManager im
*/
public void addExtensionMap(final String extension, final String scheme)
{
- map.addExtension(extension, scheme);
+ typeMap.addExtension(extension, scheme);
}
/**
@@ -256,7 +256,7 @@ public class DefaultFileSystemManager im
*/
public void addMimeTypeMap(final String mimeType, final String scheme)
{
- map.addMimeType(mimeType, scheme);
+ typeMap.addMimeType(mimeType, scheme);
}
/**
@@ -536,28 +536,36 @@ public class DefaultFileSystemManager im
/**
* Initializes this manager.
+ * <p>
+ * If no value for the following properties was specified, it will
+ * use the following defaults:
+ * <ul>
+ * <li>fileContentInfoFactory = new FileContentInfoFilenameFactory()</li>
+ * <li>filesCache = new SoftRefFilesCache()</li>
+ * <li>fileCacheStrategy = CacheStrategy.ON_RESOLVE</li>
+ * </ul>
*
* @throws FileSystemException if an error occurs during initialization.
*/
public void init() throws FileSystemException
{
- if (filesCache == null)
- {
- // filesCache = new DefaultFilesCache();
- filesCache = new SoftRefFilesCache();
- }
-
if (fileContentInfoFactory == null)
{
fileContentInfoFactory = new FileContentInfoFilenameFactory();
}
+ if (filesCache == null)
+ {
+ // filesCache = new DefaultFilesCache();
+ filesCache = new SoftRefFilesCache();
+ }
if (fileCacheStrategy == null)
{
fileCacheStrategy = CacheStrategy.ON_RESOLVE;
}
-
setupComponent(filesCache);
+
+ vfsProvider = new VirtualFileProvider();
setupComponent(vfsProvider);
init = true;
@@ -567,7 +575,7 @@ public class DefaultFileSystemManager im
* Closes the manager.
* <p>
* This will close all providers (all files), it will also close
- * all maanged componnets including temporary files, replicators
+ * all managed components including temporary files, replicators
* and cache.
* <p>
* The manager is in uninitialized state after this method.
@@ -588,31 +596,36 @@ public class DefaultFileSystemManager im
providers.clear();
// Close the other components
- closeComponent(filesCache);
-
- // managed lifecycle
- closeComponent(defaultProvider);
+ closeComponent(vfsProvider);
closeComponent(fileReplicator);
closeComponent(tempFileStore);
+ closeComponent(filesCache);
+ closeComponent(defaultProvider);
- components.clear();
+ // collections with add()
+ typeMap.clear();
+ operationProviders.clear();
- defaultProvider = null;
- fileReplicator = null;
- tempFileStore = null;
- filesCache = null;
+ // should not happen, but make debugging easier:
+ if (!components.isEmpty())
+ {
+ log.warn("DefaultFilesystemManager.close: not all components are closed: " + components.toString());
+ }
+ components.clear();
- // reset manager state
+ // managed components
+ vfsProvider = null;
- // collections with add()
- map.clear();
- operationProviders.clear();
// setters and derived state
+ defaultProvider = null;
baseFile = null;
fileObjectDecorator = null;
fileObjectDecoratorConst = null;
localFileProvider = null;
+ fileReplicator = null;
+ tempFileStore = null;
// setters with init() defaults
+ filesCache = null;
fileCacheStrategy = null;
fileContentInfoFactory = null;
@@ -635,6 +648,7 @@ public class DefaultFileSystemManager im
final AbstractFileProvider provider = (AbstractFileProvider) fileProvider;
provider.freeUnusedResources();
}
+ // vfsProvider does not need to free resources
}
/**
@@ -1007,7 +1021,7 @@ public class DefaultFileSystemManager im
public FileObject createFileSystem(final FileObject file)
throws FileSystemException
{
- final String scheme = map.getScheme(file);
+ final String scheme = typeMap.getScheme(file);
if (scheme == null)
{
throw new FileSystemException(
@@ -1028,7 +1042,7 @@ public class DefaultFileSystemManager im
public boolean canCreateFileSystem(final FileObject file)
throws FileSystemException
{
- return map.getScheme(file) != null;
+ return typeMap.getScheme(file) != null;
}
/**
@@ -1119,6 +1133,11 @@ public class DefaultFileSystemManager im
{
((AbstractFileProvider) provider).closeFileSystem(filesystem);
}
+ else if (filesystem instanceof VirtualFileSystem)
+ {
+ // vfsProvider does not implement AbstractFileProvider
+ vfsProvider.closeFileSystem(filesystem);
+ }
}
/**
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VirtualFileProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VirtualFileProvider.java?rev=1640477&r1=1640476&r2=1640477&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VirtualFileProvider.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VirtualFileProvider.java Wed Nov 19 03:56:29 2014
@@ -18,9 +18,11 @@ package org.apache.commons.vfs2.impl;
import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystem;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileType;
import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileSystem;
import org.apache.commons.vfs2.provider.AbstractVfsContainer;
@@ -61,4 +63,20 @@ public class VirtualFileProvider extends
addComponent(fs);
return fs.getRoot();
}
+
+ /**
+ * Close a VirtualFileSystem by removing it from the
+ * {@code #components} list of this provider.
+ * <p>
+ * This gets called from DefaultFileManager#_closeFileSystem.
+ *
+ * @param filesystem the file system remembered by this provider.
+ */
+ void closeFileSystem(final FileSystem filesystem)
+ {
+ final AbstractFileSystem fs = (AbstractFileSystem) filesystem;
+
+ removeComponent(fs);
+ fs.close();
+ }
}
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VirtualFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VirtualFileSystem.java?rev=1640477&r1=1640476&r2=1640477&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VirtualFileSystem.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/VirtualFileSystem.java Wed Nov 19 03:56:29 2014
@@ -196,4 +196,11 @@ public class VirtualFileSystem extends A
// None
return null;
}
+
+ @Override
+ public void close()
+ {
+ super.close();
+ junctions.clear();
+ }
}
Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1640477&r1=1640476&r2=1640477&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Wed Nov 19 03:56:29 2014
@@ -26,6 +26,10 @@
<!-- <action issue="VFS-443" dev="ggregory" type="update" due-to="nickallen"> -->
<!-- [Local] Need an easy way to convert from a FileObject to a File. -->
<!-- </action> -->
+ <action issue="VFS-544" dev="ecki" type="fix">
+ [Virtual] Allow virtual file systems and virtual file system provider
+ to be closed, to avoid memory leak.
+ </action>
<action issue="VFS-142" dev="ecki" type="fix" due-to="Ryan Boettcher">
Use ThreadLocal.remove() to clean out FileContentThreadData objects.
</action>