NativeFileNotifications

RFE #26230

Contents

Platforms

Windows

Windows 2000 and up. ReadDirectoryChangesW

Solaris

Solaris 11 and up. http://blogs.sun.com/praks/entry/file_events_notification

Linux

INotify supported in modern kernels. May need to increase fs.inotify.max_user_watches in /etc/sysctl.conf if /proc/sys/fs/inotify/max_user_watches reports it as too low (default is 8192 on Ubuntu).

BSD

kqueue

Mac OS X

FSEvents.

(KQueue also possible; some notes: http://ochafik.free.fr/blog/?p=119)

The KQueue is not suitable for listening on large number of folders as they require file handle to be opened at least in O_EVTONLY. The KQueues are not recursive, even the change of file content has to be monitored by listening on the file not on the folder containing it.

Mac C projects doing FS listening using BSD kernel queues and FSEventStream File:MacFSListening.tgz

I've tested the implementation of the FileMonitor using kqueues (http://ochafik.free.fr/blog/?p=119). To be able to listen on file changes in the folder it listens also on all files inside the folder (it holds file handle to all these files). For a sample project (lucene core sources copied into single folder) there are 722 opened file handles (lsof).

Implementations

NetBeans Platform

Now implemented directly in NetBeans Platform (API in org.openide.filesystems, implementation in org.netbeans.modules.masterfs) since 7.0; uses JNA on Windows, Mac OS X, Linux (inotify), Solaris (FAM); works on JDK 6 or 7.

JSR 203

http://java.sun.com/javase/7/docs/api/java/nio/file/WatchService.html http://openjdk.java.net/projects/nio/

Linux, Windows, Solaris.

No Mac implementation yet (http://code.google.com/p/barbarywatchservice/ is a clue); have not yet checked JDK 7 Preview.

Supports listening to a full hierarchy where supported by the OS (implemented on Windows), using com.sun.nio.file.ExtendedWatchEventModifier.FILE_TREE. For systems which do not support this natively (Linux), it is straightforward to emulate this at the cost of more watches; this is one of the API usage samples.

Backporting to JDK 6 would have many other advantages (richer API for communication with filesystem); cannot use java.** namespace in that case.

IDEA

http://git.jetbrains.org/?p=idea/community.git;a=tree;f=native

Linux, Mac, Windows. Apache. Uses a separate process (communicates using stdio with main process).

Eclipse

Seems to have some impl for Windows already. Proposals for Linux impl and Mac impl

JNotify

https://sourceforge.net/projects/jnotify/

Linux, Mac, Windows. Apache. Semi-active.

JFileNotify

https://sourceforge.net/projects/jfilenotify/

Linux, Windows. GPL. Inactive.

Demo in JNA

https://guest:guest@jna.dev.java.net/svn/jna/trunk/jnalib/contrib/src/platform/src/com/sun/jna/platform/FileMonitor.java

Just shows that JNA can be used to implement this class of API. Demo implementation only supports Windows.


File:FileSystemWatcher.tgz Implementation of native file system events using JNA based on FSEventStream (Mac OS X 10.5+)

JxFileWatcher

Commercial. http://www.teamdev.com/jxfilewatcher/

jpathwatch

http://jpathwatch.wordpress.com/documentation/features/

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo