You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by im...@apache.org on 2005/09/30 09:02:47 UTC

svn commit: r292651 - in /jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs: cache/SoftRefFilesCache.java provider/AbstractFileSystem.java provider/zip/ZipFileObject.java provider/zip/ZipFileSystem.java

Author: imario
Date: Fri Sep 30 00:02:41 2005
New Revision: 292651

URL: http://svn.apache.org/viewcvs?rev=292651&view=rev
Log:
enh: try to close the zip file if no one access it

Modified:
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/zip/ZipFileObject.java
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystem.java

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java?rev=292651&r1=292650&r2=292651&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java Fri Sep 30 00:02:41 2005
@@ -79,16 +79,13 @@
                         continue;
                     }
 
-                    if (ref != null)
+                    synchronized (SoftRefFilesCache.this)
                     {
-                        synchronized (SoftRefFilesCache.this)
-                        {
-                            FileSystemAndNameKey key = (FileSystemAndNameKey) refReverseMap.get(ref);
+                        FileSystemAndNameKey key = (FileSystemAndNameKey) refReverseMap.get(ref);
 
-                            if (key != null)
-                            {
-                                removeFile(key);
-                            }
+                        if (key != null)
+                        {
+                            removeFile(key);
                         }
                     }
                 }
@@ -131,11 +128,15 @@
 
     public void putFile(final FileObject file)
     {
+        if (log.isDebugEnabled())
+        {
+            log.debug("putFile: " + file.getName());
+        }
         synchronized (this)
         {
             Map files = getOrCreateFilesystemCache(file.getFileSystem());
 
-            SoftReference ref = new SoftReference(file, refqueue);
+            Reference ref = new SoftReference(file, refqueue);
             FileSystemAndNameKey key = new FileSystemAndNameKey(file.getFileSystem(), file.getName());
             files.put(file.getName(), ref);
             refReverseMap.put(ref, key);
@@ -189,6 +190,10 @@
 
     private void filesystemClose(FileSystem filesystem)
     {
+        if (log.isDebugEnabled())
+        {
+            log.debug("close fs: " + filesystem.getRootName());
+        }
         filesystemCache.remove(filesystem);
         if (filesystemCache.size() < 1)
         {
@@ -222,6 +227,10 @@
 
     private void removeFile(final FileSystemAndNameKey key)
     {
+        if (log.isDebugEnabled())
+        {
+            log.debug("removeFile: " + key.getFileName());
+        }
         synchronized (this)
         {
             Map files = getOrCreateFilesystemCache(key.getFileSystem());

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java?rev=292651&r1=292650&r2=292651&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java Fri Sep 30 00:02:41 2005
@@ -1,12 +1,12 @@
 /*
  * Copyright 2002-2005 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -61,7 +61,7 @@
     /**
      * Map from FileName to FileObject.
      */
-    private FilesCache files;
+    // private FilesCache files;
 
     /**
      * Map from FileName to an ArrayList of listeners for that file.
@@ -89,7 +89,7 @@
         this.rootName = rootName;
         this.fileSystemOptions = fileSystemOptions;
 
-        this.files = null;
+        // this.files = null;
     }
 
     /**
@@ -113,7 +113,7 @@
     /**
      * Close the underlaying link used to access the files
      */
-    protected void closeCommunicationLink()
+    public void closeCommunicationLink()
     {
         synchronized (this)
         {
@@ -159,16 +159,17 @@
 
     private FilesCache getCache()
     {
-        if (this.files == null)
+        FilesCache files;
+        //if (this.files == null)
         {
-            this.files = getContext().getFileSystemManager().getFilesCache();
-            if (this.files == null)
+            files = getContext().getFileSystemManager().getFilesCache();
+            if (files == null)
             {
                 throw new RuntimeException(Messages.getString("vfs.provider/files-cache-missing.error"));
             }
         }
 
-        return this.files;
+        return files;
     }
 
     /**

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/zip/ZipFileObject.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/zip/ZipFileObject.java?rev=292651&r1=292650&r2=292651&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/zip/ZipFileObject.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/zip/ZipFileObject.java Fri Sep 30 00:02:41 2005
@@ -19,9 +19,12 @@
 import org.apache.commons.vfs.FileObject;
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.util.MonitorInputStream;
 import org.apache.commons.vfs.provider.AbstractFileObject;
+import org.apache.commons.vfs.provider.AbstractFileSystem;
 
 import java.io.InputStream;
+import java.io.IOException;
 import java.util.HashSet;
 import java.util.zip.ZipEntry;
 
@@ -134,6 +137,17 @@
      */
     protected InputStream doGetInputStream() throws Exception
     {
-        return fs.getZipFile().getInputStream(entry);
+        return new MonitorInputStream(fs.getZipFile().getInputStream(entry))
+        {
+            protected void onClose() throws IOException
+            {
+                ZipFileObject.this.close();
+                AbstractFileSystem fs = (AbstractFileSystem) getFileSystem();
+                if (fs.isReleaseable())
+                {
+                    fs.closeCommunicationLink();
+                }
+            }
+        };
     }
 }

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystem.java?rev=292651&r1=292650&r2=292651&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystem.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystem.java Fri Sep 30 00:02:41 2005
@@ -1,12 +1,12 @@
 /*
  * Copyright 2002-2005 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -69,7 +69,7 @@
             return;
         }
 
-        zipFile = createZipFile(this.file);
+        // zipFile = createZipFile(this.file);
     }
 
     public void init() throws FileSystemException
@@ -119,6 +119,7 @@
                 parent.attachChild(fileObj.getName());
             }
         }
+        closeCommunicationLink();
     }
 
     protected ZipFile getZipFile() throws FileSystemException



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org