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/08 12:41:48 UTC
svn commit: r279549 - in /jakarta/commons/proper/vfs/trunk: RELEASE_NOTES.txt
src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java
Author: imario
Date: Thu Sep 8 03:41:38 2005
New Revision: 279549
URL: http://svn.apache.org/viewcvs?rev=279549&view=rev
Log:
enh: try to avoid server roundtrip when deleting files on an ftp server
Modified:
jakarta/commons/proper/vfs/trunk/RELEASE_NOTES.txt
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java
Modified: jakarta/commons/proper/vfs/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/RELEASE_NOTES.txt?rev=279549&r1=279548&r2=279549&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/commons/proper/vfs/trunk/RELEASE_NOTES.txt Thu Sep 8 03:41:38 2005
@@ -1,5 +1,9 @@
2005-
+internals:
+notify which child was added or deleted
+
+
threading:
avoid gc when referencing only inputStream/outputStream of a fileObject
@@ -30,6 +34,8 @@
ignore nonparseable ftp directory entries. It will be logged using the debug log-level
with class org.apache.commons.vfs.provider.ftp.FtpFileObject.
(e.g. empty lines in ftp directory listing)
+
+avoid server-roundtrip ("LIST") if file was deleted. if you add a child this is still needed.
2005-08-13 commons-vfs 1.0 RC3
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java?rev=279549&r1=279548&r2=279549&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java Thu Sep 8 03:41:38 2005
@@ -43,6 +43,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Arrays;
/**
* A partial file object implementation.
@@ -213,7 +214,7 @@
* <p/>
* This implementation does nothing.
*/
- protected void onChildrenChanged() throws Exception
+ protected void onChildrenChanged(FileName child, FileType newType) throws Exception
{
}
@@ -903,7 +904,10 @@
{
doRename(destFile);
+ ((AbstractFileObject) destFile).handleCreate(getType());
+
destFile.close(); // now the destFile is no longer imaginary. force reattach.
+
handleDelete(); // fire delete-events. This file-object (src) is like deleted.
}
catch (final RuntimeException re)
@@ -1271,7 +1275,7 @@
}
// Notify parent that its child list may no longer be valid
- notifyParent();
+ notifyParent(this.getName(), newType);
// Notify the file system
fs.fireFileCreated(this);
@@ -1298,7 +1302,7 @@
}
// Notify parent that its child list may no longer be valid
- notifyParent();
+ notifyParent(this.getName(), FileType.IMAGINARY);
// Notify the file system
fs.fireFileDeleted(this);
@@ -1318,22 +1322,48 @@
/**
* Notifies the file that its children have changed.
*
- * @todo Indicate whether the child was added or removed, and which child.
+ * @deprecated use {@link #childrenChanged(FileName, FileType)}
*/
protected void childrenChanged() throws Exception
{
+ childrenChanged(null, null);
+ }
+
+ /**
+ * Notifies the file that its children have changed.
+ */
+ protected void childrenChanged(FileName childName, FileType newType) throws Exception
+ {
// TODO - this may be called when not attached
- removeChildrenCache();
- // children = null;
- onChildrenChanged();
+ if (children != null)
+ {
+ if (childName != null && newType != null)
+ {
+ // TODO - figure out if children[] can be replaced by list
+ ArrayList list = new ArrayList(Arrays.asList(children));
+ if (newType.equals(FileType.IMAGINARY))
+ {
+ list.remove(childName);
+ }
+ else
+ {
+ list.add(childName);
+ }
+ children = new FileName[list.size()];
+ list.toArray(children);
+ }
+ }
+
+ // removeChildrenCache();
+ onChildrenChanged(childName, newType);
}
/**
* Notify the parent of a change to its children, when a child is created
* or deleted.
*/
- private void notifyParent() throws Exception
+ private void notifyParent(FileName childName, FileType newType) throws Exception
{
if (parent == null)
{
@@ -1347,7 +1377,7 @@
if (parent != null)
{
- parent.childrenChanged();
+ parent.childrenChanged(childName, newType);
}
}
@@ -1465,7 +1495,7 @@
private void setFileType(FileType type)
{
- if (type != FileType.IMAGINARY)
+ if (type != null && type != FileType.IMAGINARY)
{
try
{
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java?rev=279549&r1=279548&r2=279549&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java Thu Sep 8 03:41:38 2005
@@ -33,10 +33,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Collections;
/**
* An FTP file.
@@ -49,14 +52,14 @@
{
private Log log = LogFactory.getLog(FtpFileObject.class);
- private static final FTPFile[] EMPTY_FTP_FILE_ARRAY = {};
+ private static final Map EMPTY_FTP_FILE_MAP = Collections.unmodifiableMap(new TreeMap());
private final FtpFileSystem ftpFs;
private final String relPath;
// Cached info
private FTPFile fileInfo;
- private FTPFile[] children;
+ private Map children;
private FileObject linkDestination;
protected FtpFileObject(final FileName name,
@@ -98,18 +101,8 @@
doGetChildren();
// Look for the requested child
- // TODO - use hash table
- for (int i = 0; i < children.length; i++)
- {
- final FTPFile child = children[i];
- if (child.getName().equals(name))
- {
- // TODO - should be using something else to compare names
- return child;
- }
- }
-
- return null;
+ FTPFile ftpFile = (FTPFile) children.get(name);
+ return ftpFile;
}
/**
@@ -129,12 +122,13 @@
final FTPFile[] tmpChildren = client.listFiles(key, relPath);
if (tmpChildren == null || tmpChildren.length == 0)
{
- children = EMPTY_FTP_FILE_ARRAY;
+ children = EMPTY_FTP_FILE_MAP;
}
else
{
+ children = new TreeMap();
+
// Remove '.' and '..' elements
- final ArrayList childList = new ArrayList();
for (int i = 0; i < tmpChildren.length; i++)
{
final FTPFile child = tmpChildren[i];
@@ -153,10 +147,9 @@
if (!".".equals(child.getName())
&& !"..".equals(child.getName()))
{
- childList.add(child);
+ children.put(child.getName(), child);
}
}
- children = (FTPFile[]) childList.toArray(new FTPFile[childList.size()]);
}
}
finally
@@ -181,16 +174,19 @@
private void getInfo(boolean flush) throws IOException
{
final FtpFileObject parent = (FtpFileObject) getParent();
+ FTPFile newFileInfo;
if (parent != null)
{
- fileInfo = parent.getChildFile(UriParser.decode(getName().getBaseName()), flush);
+ newFileInfo = parent.getChildFile(UriParser.decode(getName().getBaseName()), flush);
}
else
{
// Assume the root is a directory and exists
- fileInfo = new FTPFile();
- fileInfo.setType(FTPFile.DIRECTORY_TYPE);
+ newFileInfo = new FTPFile();
+ newFileInfo.setType(FTPFile.DIRECTORY_TYPE);
}
+
+ this.fileInfo = newFileInfo;
}
/**
@@ -198,16 +194,32 @@
*/
protected void doDetach()
{
- fileInfo = null;
+ this.fileInfo = null;
children = null;
}
/**
* Called when the children of this file change.
*/
- protected void onChildrenChanged()
+ protected void onChildrenChanged(FileName child, FileType newType)
{
- children = null;
+ if (children != null && newType.equals(FileType.IMAGINARY))
+ {
+ try
+ {
+ children.remove(UriParser.decode(child.getBaseName()));
+ }
+ catch (FileSystemException e)
+ {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+ else
+ {
+ // if child was added we have to rescan the children
+ // TODO - get rid of this
+ children = null;
+ }
}
/**
@@ -216,6 +228,14 @@
protected void onChange() throws IOException
{
children = null;
+
+ if (getType().equals(FileType.IMAGINARY))
+ {
+ // file is deleted, avoid server lookup
+ this.fileInfo = null;
+ return;
+ }
+
getInfo(true);
}
@@ -226,19 +246,19 @@
protected FileType doGetType()
throws Exception
{
- if (fileInfo == null)
+ if (this.fileInfo == null)
{
return FileType.IMAGINARY;
}
- else if (fileInfo.isDirectory())
+ else if (this.fileInfo.isDirectory())
{
return FileType.FOLDER;
}
- else if (fileInfo.isFile())
+ else if (this.fileInfo.isFile())
{
return FileType.FILE;
}
- else if (fileInfo.isSymbolicLink())
+ else if (this.fileInfo.isSymbolicLink())
{
return getLinkDestination().getType();
}
@@ -250,7 +270,7 @@
{
if (linkDestination == null)
{
- final String path = fileInfo.getLink();
+ final String path = this.fileInfo.getLink();
FileName relativeTo = getName().getParent();
if (relativeTo == null)
{
@@ -265,7 +285,7 @@
protected FileObject[] doListChildrenResolved() throws Exception
{
- if (fileInfo.isSymbolicLink())
+ if (this.fileInfo.isSymbolicLink())
{
return getLinkDestination().getChildren();
}
@@ -282,11 +302,15 @@
// List the children of this file
doGetChildren();
- final String[] childNames = new String[children.length];
- for (int i = 0; i < children.length; i++)
- {
- final FTPFile child = children[i];
- childNames[i] = child.getName();
+ // TODO - get rid of this children stuff
+ final String[] childNames = new String[children.size()];
+ int childNum = -1;
+ Iterator iterChildren = children.values().iterator();
+ while (iterChildren.hasNext())
+ {
+ childNum++;
+ final FTPFile child = (FTPFile) iterChildren.next();
+ childNames[childNum] = child.getName();
}
return UriParser.encode(childNames);
@@ -301,7 +325,7 @@
final FtpClient ftpClient = ftpFs.getClient();
try
{
- if (fileInfo.isDirectory())
+ if (this.fileInfo.isDirectory())
{
ok = ftpClient.removeDirectory(relPath);
}
@@ -319,8 +343,8 @@
{
throw new FileSystemException("vfs.provider.ftp/delete-file.error", getName());
}
- fileInfo = null;
- children = EMPTY_FTP_FILE_ARRAY;
+ this.fileInfo = null;
+ children = EMPTY_FTP_FILE_MAP;
}
/**
@@ -345,8 +369,8 @@
{
throw new FileSystemException("vfs.provider.ftp/rename-file.error", new Object[]{getName().toString(), newfile});
}
- fileInfo = null;
- children = EMPTY_FTP_FILE_ARRAY;
+ this.fileInfo = null;
+ children = EMPTY_FTP_FILE_MAP;
}
/**
@@ -377,13 +401,13 @@
*/
protected long doGetContentSize() throws Exception
{
- if (fileInfo.isSymbolicLink())
+ if (this.fileInfo.isSymbolicLink())
{
return getLinkDestination().getContent().getSize();
}
else
{
- return fileInfo.getSize();
+ return this.fileInfo.getSize();
}
}
@@ -394,13 +418,13 @@
*/
protected long doGetLastModifiedTime() throws Exception
{
- if (fileInfo.isSymbolicLink())
+ if (this.fileInfo.isSymbolicLink())
{
return getLinkDestination().getContent().getLastModifiedTime();
}
else
{
- Calendar timestamp = fileInfo.getTimestamp();
+ Calendar timestamp = this.fileInfo.getTimestamp();
if (timestamp == null)
{
return 0L;
@@ -420,7 +444,7 @@
*/
protected void doSetLastModifiedTime(final long modtime) throws Exception
{
- if (fileInfo.isSymbolicLink())
+ if (this.fileInfo.isSymbolicLink())
{
getLinkDestination().getContent().setLastModifiedTime(modtime);
}
@@ -429,7 +453,7 @@
final Date d = new Date(modtime);
final Calendar c = new GregorianCalendar();
c.setTime(d);
- fileInfo.setTimestamp(c);
+ this.fileInfo.setTimestamp(c);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org