WatchService

Alan Bateman Alan.Bateman at oracle.com
Mon Jan 10 07:03:06 PST 2011


Wolfgang Baltes wrote:
>
> Hi Alan,
>
> I took the WatchDir sample code and modified it as follows:
> - The directory parsing and event loop runs in a separate thread, 
> which allows me to delete files and directories programmatically.
> - Added a few extra console outputs to better catch what is going on.
> - In the event loop, added a section to catch the particular condition 
> in which we are interested.
>
> The bottom line of what I found is that the behavior changes depending 
> on whether the deleted subdirectory is empty or not. To reproduce:
>
> 1: Change the code to create a parent directory to your liking. This 
> is in line 241: final Path dir = Paths.get("c:\\watchtest");
>
> 2: Run the code without other modification. It will create the before 
> mentioned directory, plus a subdirectory, plus two files in that 
> subdirectory, then waits for something to happen.
>
> 3: Manually delete "subdir". The output is:
>       Scanning c:\watchtest ...
>       register: c:\watchtest
>       register: c:\watchtest\subdir
>       Done with registering directories.
>       ENTRY_DELETE: c:\watchtest\subdir
>       c:\watchtest\subdir does not exist... ... but key is valid.
>       ENTRY_MODIFY: c:\watchtest\subdir\file1.txt
>       ENTRY_MODIFY: c:\watchtest\subdir\file2.txt
>
> 4: Kill the thread and start over.
>
> 5: Manually delete first the two files in subdir, and then subdir. The 
> output is:
>       Scanning c:\watchtest ...
>       register: c:\watchtest
>       register: c:\watchtest\subdir
>       Done with registering directories.
>       ENTRY_DELETE: c:\watchtest\subdir\file1.txt
>       ENTRY_MODIFY: c:\watchtest\subdir
>       ENTRY_DELETE: c:\watchtest\subdir\file2.txt
>       ENTRY_MODIFY: c:\watchtest\subdir
>       Removing watch key for c:\watchtest\subdir.
>       ENTRY_DELETE: c:\watchtest\subdir
>
> 6: You can kill the watch thread by deleting directory "watchtest".
>
> 7: You can remove the comments from lines 265 to 273 to automate step 5.
>
> For me it is important to make step 3 above work correctly. This is 
> what a user would do when a directory needs to be removed manually.
>
> I hope this helps. Please let me know how I can be of further help.
> Wolfgang.
Continuing the thread from December 16.  I followed the instructions 
above and duplicated the issue you are seeing on Windows Server 2008 R2. 
I couldn't duplicate it on Windows XP. I need to debug it further but it 
looks like we are just aren't getting any notification from Windows to 
indicate that watch on subdir is no longer valid. At step 3 the event 
you are seeing is for directory watchtest to say that an entry has been 
deleted. I'll send mail once I've had time to debug it further.

-Alan.


More information about the nio-dev mailing list