watchservice

Java 7 WatchService - Ignoring multiple occurrences of the same event

人盡茶涼 提交于 2019-11-27 19:37:57
The javadoc for StandardWatchEventKinds.ENTRY_MODIFY says: Directory entry modified. When a directory is registered for this event then the WatchKey is queued when it is observed that an entry in the directory has been modified. The event count for this event is 1 or greater. When you edit the content of a file through an editor, it'll modify both date (or other metadata) and content. You therefore get two ENTRY_MODIFY events, but each will have a count of 1 (at least that's what I'm seeing). I'm trying to monitor a configuration file ( servers.cfg previously registered with the WatchService )

Java WatchService not generating events while watching mapped drives

允我心安 提交于 2019-11-27 08:02:15
I implemented a file watcher but I noticed that java nio file watcher doesn't generate events for files being copied on mapped drives. For instance, I've run the file watcher on Unix to watch a local directory ( /sharedfolder ) which is mapped on windows ( H:\ ), and then I've put a file in this directory ( H:\ ) but the file watcher hasn't generated any event. Now if I run the file watcher on windows to watcher the mapped drive ( H:\ ) which refers to a unix path ( /sharedfolder ) and from unix I put a file in this folder, the file watcher identifies the change and generates an event. It

Is Java 7 WatchService Slow for Anyone Else?

纵然是瞬间 提交于 2019-11-27 07:12:01
WatchService looks like a great technology but its been too slow to be useful on the OS X and Linux systems I've tested on. To add insult to injury, it doesn't seem to get notified of all events either. This is the case both with my own code and the canonical example from Oracle. ( http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java ) I recognize that the OS X OpenJDK port is unsure of this functionality (see https://wikis.oracle.com/display/OpenJDK/Mac+OS+X+Port+Project+Status ) Has anyone been using this in

WatchService and SwingWorker: how to do it correctly?

狂风中的少年 提交于 2019-11-27 04:39:58
WatchService sounded like an exciting idea ... unfortunately it seems to be as low-level as warned in the tutorial/api plus doesn't really fit into the Swing event model (or I'm missing something obvious, a not-zero probability Taking the code from WatchDir example in the tutorial (simplyfied to handle a single directory only), I basically ended up extend SwingWorker do the registration stuff in the constructor put the endless loop waiting for a key in doInBackground publish each WatchEvent when retrieved via key.pollEvents() process the chunks by firing propertyChangeEvents with the deleted

Java 7 WatchService - Ignoring multiple occurrences of the same event

独自空忆成欢 提交于 2019-11-26 19:57:00
问题 The javadoc for StandardWatchEventKinds.ENTRY_MODIFY says: Directory entry modified. When a directory is registered for this event then the WatchKey is queued when it is observed that an entry in the directory has been modified. The event count for this event is 1 or greater. When you edit the content of a file through an editor, it'll modify both date (or other metadata) and content. You therefore get two ENTRY_MODIFY events, but each will have a count of 1 (at least that's what I'm seeing).

Java WatchService not generating events while watching mapped drives

佐手、 提交于 2019-11-26 14:01:32
问题 I implemented a file watcher but I noticed that java nio file watcher doesn't generate events for files being copied on mapped drives. For instance, I've run the file watcher on Unix to watch a local directory ( /sharedfolder ) which is mapped on windows ( H:\ ), and then I've put a file in this directory ( H:\ ) but the file watcher hasn't generated any event. Now if I run the file watcher on windows to watcher the mapped drive ( H:\ ) which refers to a unix path ( /sharedfolder ) and from

Is Java 7 WatchService Slow for Anyone Else?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 13:01:25
问题 WatchService looks like a great technology but its been too slow to be useful on the OS X and Linux systems I\'ve tested on. To add insult to injury, it doesn\'t seem to get notified of all events either. This is the case both with my own code and the canonical example from Oracle. (http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java) I recognize that the OS X OpenJDK port is unsure of this functionality (see

Can I watch for single file change with WatchService (not the whole directory)?

北慕城南 提交于 2019-11-26 11:44:01
When I'm trying to register a file instead of a directory java.nio.file.NotDirectoryException is thrown. Can I listen for a single file change, not the whole directory? Just filter the events for the file you want in the directory: final Path path = FileSystems.getDefault().getPath(System.getProperty("user.home"), "Desktop"); System.out.println(path); try (final WatchService watchService = FileSystems.getDefault().newWatchService()) { final WatchKey watchKey = path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY); while (true) { final WatchKey wk = watchService.take(); for

WatchService and SwingWorker: how to do it correctly?

廉价感情. 提交于 2019-11-26 11:18:05
问题 WatchService sounded like an exciting idea ... unfortunately it seems to be as low-level as warned in the tutorial/api plus doesn\'t really fit into the Swing event model (or I\'m missing something obvious, a not-zero probability Taking the code from WatchDir example in the tutorial (simplyfied to handle a single directory only), I basically ended up extend SwingWorker do the registration stuff in the constructor put the endless loop waiting for a key in doInBackground publish each WatchEvent

Can I watch for single file change with WatchService (not the whole directory)?

余生长醉 提交于 2019-11-26 05:52:15
问题 When I\'m trying to register a file instead of a directory java.nio.file.NotDirectoryException is thrown. Can I listen for a single file change, not the whole directory? 回答1: Just filter the events for the file you want in the directory: final Path path = FileSystems.getDefault().getPath(System.getProperty("user.home"), "Desktop"); System.out.println(path); try (final WatchService watchService = FileSystems.getDefault().newWatchService()) { final WatchKey watchKey = path.register(watchService