You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by manco <me...@yahoo.com> on 2005/05/17 19:00:32 UTC

[VFS] VFS.getManager().getFilesCache() - exists() vs findFiles()

Hi,
 
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) fileIter.next();
                  if (srcFo.exists())                                   <<<<< problem
                   {
                      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 again
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
 
Manco
 


 

		
---------------------------------
Discover Yahoo!
 Have fun online with music videos, cool games, IM & more. Check it out!

Re: [VFS] VFS.getManager().getFilesCache() - exists() vs findFiles()

Posted by Mario Ivankovits <ma...@ops.co.at>.
Andy Lewis wrote:
>Wouldn't it make sense to have findFiles() update cache entries? Or is
>that the plan for 2.0?
>  
I dont know exactly in which direction I will go with the caching stuff.

Currently I think about refactoring VFS to be able to run without 
caching at all, and thus its planned for version 2.0
Currently there is a NullCache, but this introduce some memory leaks.

Though, I take your suggestion into account and will see how this could 
work, maybe this is something for 1.1



Wouldnt it be nice to be able to write code like:

FileObject fo = vfs.resolveFile(....)
while (!fo.exists())
{
    wait
}

Sure, then exists() needs to hit the server every time, but today this 
might not be that problem. And if the user needs caching it might be 
possible to wrap a FileObject into a ChachedFileObject.
That could make the whole caching cleaner ....

And from my point of view this is exactly what I would like to get from VFS.
In VFS there are some glitches which makes it hard to fix it. But hey, 
we need some work for a 2.0 release.

Every comment is still welcome!
I need to see what users expect from VFS.

---
Mario


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


Re: [VFS] VFS.getManager().getFilesCache() - exists() vs findFiles()

Posted by Andy Lewis <aj...@ascii27.net>.
Wouldn't it make sense to have findFiles() update cache entries? Or is
that the plan for 2.0?


Mario Ivankovits wrote:

> manco wrote:
>
>>
>> I dont see why the findFiles() sees it but the exist() fails
>>  
>
> It has something to do with the cache, this is correct (and it drives
> me crazy, but this will be something for vfs 2.0).
> findFiles finds the file on the filesystem but get the cached object
> which might be in state "file deleted".
>
> To refresh its cached informations you could call ".close()" on the
> fileobject in question. This is the intended way to do this.
>
> e.g.
>
> for (FileObject fo : foundFiles)
> {
>    fo.close();
>    if (fo.exists())
>    {
>       ......
>    }
> }
>
> ---
> Mario
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org



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


Re: [VFS] VFS.getManager().getFilesCache() - exists() vs findFiles()

Posted by Mario Ivankovits <ma...@ops.co.at>.
manco wrote:
> 
>I dont see why the findFiles() sees it but the exist() fails
>  
It has something to do with the cache, this is correct (and it drives me 
crazy, but this will be something for vfs 2.0).
findFiles finds the file on the filesystem but get the cached object 
which might be in state "file deleted".

To refresh its cached informations you could call ".close()" on the 
fileobject in question. This is the intended way to do this.

e.g.

for (FileObject fo : foundFiles)
{
    fo.close();
    if (fo.exists())
    {
       ......
    }
}

---
Mario


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