use of java.nio.file.StandardWatchEventKinds.OVERFLOW in project JMRI by JMRI.
the class WebAppManager method lifeCycleStarted.
private void lifeCycleStarted(LifeCycle lc, Profile profile) {
// register watcher to watch web/app directories everywhere
if (this.watcher.get(profile) != null) {
FileUtil.findFiles("web", ".").stream().filter((file) -> (file.isDirectory())).forEachOrdered((file) -> {
try {
Path path = file.toPath();
WebAppManager.this.watchPaths.put(path.register(this.watcher.get(profile), StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY), path);
} catch (IOException ex) {
log.error("Unable to watch {} for changes.", file);
}
(new Thread() {
@Override
public void run() {
while (WebAppManager.this.watcher.get(profile) != null) {
WatchKey key;
try {
key = WebAppManager.this.watcher.get(profile).take();
} catch (InterruptedException ex) {
return;
}
key.pollEvents().stream().filter((event) -> (event.kind() != OVERFLOW)).forEachOrdered((event) -> {
WebAppManager.this.savePreferences(profile);
});
if (!key.reset()) {
WebAppManager.this.watcher.remove(profile);
}
}
}
}).start();
});
}
}
Aggregations