commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r476349 - in /jakarta/commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs/cache/ sandbox/src/main/java/org/apache/commons/vfs/provider/mime/ sandbox/src/main/java/org/apache/commons/vfs/util/
Date Fri, 17 Nov 2006 22:52:44 GMT
Author: imario
Date: Fri Nov 17 14:52:44 2006
New Revision: 476349

URL: http://svn.apache.org/viewvc?view=rev&rev=476349
Log:
added WeakRefFilesCache which should be a little bit faster in freeing resources, though,
not sure about it yet.
optimized freeing resources int SharedRandomContentInputStream

Added:
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/WeakRefFilesCache.java
  (with props)
Modified:
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java
    jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java
    jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/util/SharedRandomContentInputStream.java

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java?view=diff&rev=476349&r1=476348&r2=476349
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java
Fri Nov 17 14:52:44 2006
@@ -145,7 +145,7 @@
 
 		Map files = getOrCreateFilesystemCache(file.getFileSystem());
 
-		Reference ref = new SoftReference(file, refqueue);
+		Reference ref = createReference(file, refqueue);
 		FileSystemAndNameKey key = new FileSystemAndNameKey(file
 				.getFileSystem(), file.getName());
 
@@ -156,13 +156,18 @@
 		}
 	}
 
+	protected Reference createReference(FileObject file, ReferenceQueue refqueue)
+	{
+		return new SoftReference(file, refqueue);
+	}
+
 	public FileObject getFile(final FileSystem filesystem, final FileName name)
 	{
 		Map files = getOrCreateFilesystemCache(filesystem);
 
 		synchronized (files)
 		{
-			SoftReference ref = (SoftReference) files.get(name);
+			Reference ref = (Reference) files.get(name);
 			if (ref == null)
 			{
 				return null;

Added: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/WeakRefFilesCache.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/WeakRefFilesCache.java?view=auto&rev=476349
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/WeakRefFilesCache.java
(added)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/WeakRefFilesCache.java
Fri Nov 17 14:52:44 2006
@@ -0,0 +1,26 @@
+package org.apache.commons.vfs.cache;
+
+import org.apache.commons.vfs.FileObject;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+
+/**
+ * This implementation caches every file as long as it is strongly reachable by
+ * the java vm. As soon as the object is no longer reachable it will be discarded.
+ * In contrast to the SoftRefFilesCache this implementation might free resources faster
+ * as it don't wait until a memory limitation.
+ * 
+ * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
+ * @version $Revision$ $Date: 2005-09-30 09:02:41 +0200 (Fr, 30 Sep
+ *          2005) $
+ * @see java.lang.ref.WeakReference
+ */
+public class WeakRefFilesCache extends SoftRefFilesCache
+{
+	protected Reference createReference(FileObject file, ReferenceQueue refqueue)
+	{
+		return new WeakReference(file, refqueue);
+	}
+}

Propchange: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/WeakRefFilesCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/WeakRefFilesCache.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/WeakRefFilesCache.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java?view=diff&rev=476349&r1=476348&r2=476349
==============================================================================
--- jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java
(original)
+++ jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java
Fri Nov 17 14:52:44 2006
@@ -76,14 +76,13 @@
 	{
 		try
 		{
-			if (mimeStream instanceof SharedRandomContentInputStream)
+			if (mimeStream == null)
 			{
-				((SharedRandomContentInputStream) mimeStream).closeAll();
-			}
-			else
-			{
-				mimeStream.close();
+				return;
 			}
+
+			closeMimeStream();
+			mimeStream = null;
 		}
 		catch (IOException e)
 		{
@@ -91,8 +90,25 @@
 		}
 	}
 
-	public Part createCommunicationLink() throws FileSystemException, MessagingException
+	private void closeMimeStream() throws IOException
 	{
+		if (mimeStream instanceof SharedRandomContentInputStream)
+		{
+			((SharedRandomContentInputStream) mimeStream).closeAll();
+		}
+		else
+		{
+			mimeStream.close();
+		}
+	}
+
+	public Part createCommunicationLink() throws IOException, MessagingException
+	{
+		if (mimeStream != null)
+		{
+			closeMimeStream();
+		}
+
 		FileObject parentLayer = getParentLayer();
 		if (!parentLayer.exists())
 		{

Modified: jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/util/SharedRandomContentInputStream.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/util/SharedRandomContentInputStream.java?view=diff&rev=476349&r1=476348&r2=476349
==============================================================================
--- jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/util/SharedRandomContentInputStream.java
(original)
+++ jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/util/SharedRandomContentInputStream.java
Fri Nov 17 14:52:44 2006
@@ -25,7 +25,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Set;
 
 /**
@@ -60,7 +59,7 @@
 
 		synchronized(createdStreams)
 		{
-			createdStreams.add(is);
+			createdStreams.add(this);
 		}
 	}
 
@@ -214,20 +213,11 @@
 	{
 		synchronized(createdStreams)
 		{
-			Iterator iterCreatedStreams = createdStreams.iterator();
-			while (iterCreatedStreams.hasNext())
+			SharedRandomContentInputStream[] streams = new SharedRandomContentInputStream[createdStreams.size()];
+			createdStreams.toArray(streams);
+			for (int i = 0; i<streams.length; i++)
 			{
-				Object stream = iterCreatedStreams.next();
-				iterCreatedStreams.remove();
-
-				if (stream instanceof InputStream)
-				{
-					((InputStream) stream).close();
-				}
-				else if (stream instanceof RandomAccessContent)
-				{
-					((RandomAccessContent) stream).close();
-				}
+				streams[i].close();
 			}
 		}
 	}



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


Mime
View raw message