commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From manco <>
Subject [VFS] VFS.getManager().getFilesCache() - exists() vs findFiles()
Date Tue, 17 May 2005 17:00:32 GMT
I am using VFS in an application running in its own jvm. It is acting as a
transfer agent between a producer of files and a consumer. The producer
async. puts files in a dir and the consumer expects the files to show up async. 
in a prespecified destination dir. 
The producer is local and the consumer is remote via sftp. I use RegEx 
to list the src/producer files:
public List getFiles() throws Exception
      private FileObject[]  srcFiles;
       FileFilter fileFilter = (FileFilter)new VfsFileFilter(oprnd.getRegEx());
       FileFilterSelector selector = new FileFilterSelector(fileFilter);
       srcFiles = srcFileObj.findFiles(selector);
       list = Arrays.asList(srcFiles);

this all works fine and dandy! 
I then iterate throught the list and ck to see if the file exists prior to attempting transfer.
methodName ()
           // Looks like external updates to the filesystem are not picked
           // up, unless we clear the VFS cache. We were able to do a find
           // files from the Regex which means a dir listing was updated,
           // but the exist() method would fail. so now we clear...
            VFS.getManager().getFilesCache().close(); // needed to get things working ...
            files = srcTransporter.getFiles();   <<< method shown above
            if(files != null)
               Iterator fileIter = files.iterator();
               while (fileIter.hasNext()) {
                  srcFo = (FileObject);
                  if (srcFo.exists())                                   <<<<<
                      mv /cp SRC to DEST
Things work fine as long as my producer NEVER produces a file of the SAME name twice.
I call the above method from a loop, where I call the method() then sleep() and then repeat
I test this by starting the transfer app and then manually moving files into the SRC directory.
Then I watch to see if they wind up in the Dest dir. As long as I dont put the same filename
back into the SRC dir things work fine. However, if I put  TestFileX.ext into the src dir
it shows up in the FileObject.findFiles() output list, which tells me somebody knows its there,
but it FAILS the   FileObject.exists() method! So somewhere there is a disconnect.
I was able to get around the problem by inserting the following line to clear the cache
            VFS.getManager().getFilesCache().close(); // needed to get things working ...
I dont see why the findFiles() sees it but the exist() fails


Discover Yahoo!
 Have fun online with music videos, cool games, IM & more. Check it out!
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message