Add a class similar to .NET's FileSystemWatcher that "listens to the file system change notifications and raises events when a directory, or file in a directory, changes."
I notice that FAM only works one level deep. In other words you don't get notified of changes in subdirectories (if a file in an immediate subdirectory changes, you get a hint in that the subdirectory is notified as having changed). By contrast FileSystemWatcher can provide notification of changes in an entire directory tree.
This subdirectory property could be easily
emulated by a code on top of fam.
If someone want to start a project on this,
i could help to write the linux version (perhaps the unix
version because it seems that there is only one
fam implementation (from SGI)).
Perhaps an active implementation in pure
java must be provided too, at least because
windows95 doesn't support FileSystemWatcher.
While it would be easy to emulate monitoring of subdirectories it wouldn't be efficient. FAM also limits the total number of directories which can be monitored to 1000 or so. Any beyond this would have to be watched by polling. Many of my file systems have tens of thousands of directories and millions of files. Emulation is not going to be practical in cases like this.
I synchronize my development area on my home and work computers over the net. This currently contains a few thousand directories and around 200000 files. The process is slow even when only a handful of files have changed (and chronically unreliable due to problems with the Windows implementation of rsync). I have been contemplating writing an alternative in Java, and for this something like FileSystemWatcher would be useful but only if it could cope efficiently with large directory trees.
There is i think another way to implements this
on unix. When a file is changed, it's directory
and all super-directory until the root directory
(in fact the mount point)) have their
modification time changed. So
it's easy to know if a file in the sub-directory
has changed if you have pre-saved the modification
time of all files of the subdirectory (oups).
This solution needs lot of memory but it's feasible.
The other solution is to choose the lowest common
denominator and to not support subdirectory watching.
> The other solution is to choose the lowest common
> denominator and to not support subdirectory
Alternatively point out to the implementors of Linux/Solaris/etc that the (lack of) support for file system change notification is rather lame, and hope that they do something about it.
In the mean time watching a single directory is feasible with a fallback polling implementation. Unfortunately there is a lot of potential for a programmer to use it in ways that work well on one OS and very poorly or not at all on another. For example, as far as I know Windows does not propagate directory modification times towards the root.
It's supported in Mono which uses FAM otherwise creates a monitor thread.
Leaving other vendors who port VM on their platform, it can be done in windows and *nix(supporting FAM). I think that could cover lot of bases.
I suggest that all ideas like this should be implemented as a opensource library (jni) first. If the proof-of-concept implementation works, then it's time to consider adding it to the jdk.
With Linux 2.6.13, there comes inotify, a musch more sophisticated mechanism.
Please, look here also:
Do any common operating systems support the ability to monitor reads to a file tree? Here are two potential uses of such a capability.
1) A coarse coverage tool for testing environments where no other coverage tool is available. Granted, finer granularity would be desirable, but there is a definite benefit in knowing a file isn't even touched by your tests. It means you have a hole.
2) A "forensic" workflow tool. When you are trying to generate the next version of something, you might not remember where you got the inputs from the previous version. A database of filesystem read history could give you helpful hints, if not answers.
Evidently, this is available for Windows, if not elsewhere.
"FileMon monitors and displays file system activity on a system in real-time. Its advanced capabilities make it a powerful tool for exploring the way Windows works, seeing how applications use the files and DLLs, or tracking down problems in system or application file configurations. Filemon's timestamping feature will show you precisely when every open, read, write or delete, happens, and its status column tells you the outcome. FileMon is so easy to use that you'll be an expert within minutes. It begins monitoring when you start it, and its output window can be saved to a file for off-line viewing. It has full search capability, and if you find that you're getting information overload, simply set up one or more filters.
FileMon works on NT 4.0, Windows 2000, Windows XP, Windows XP and Windows Server 2003 64-bit Edition, Windows 2003 Server, Windows 95, Windows 98 and Windows ME."
Let's contribute these codes to JDNC :)
Not all platforms support this. UNIX, in general, doesn't - the only way is to poll. And when you poll, you cannot detect directory changes like renaming or moving.
It's a nice idea, but very limited by platform diversity (something which .NET doesn't need to bother).
Windows 9x and ME don't support it either (you can be notified that something has changed, but get little information on what has changed).
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.