@Override protected void watchEventsOccurred() { walkTreeAndSetWatches(); unregisterStaleWatches(); }
@Override protected void beforePollEventLoop() { walkTreeAndSetWatches(); }
private synchronized void unregisterStaleWatches() { Set<Path> paths = new HashSet<Path>(watchPathKeyMap.keySet()); Set<Path> stalePaths = new HashSet<Path>(); for (Path path : paths) { if (!Files.exists(path, LinkOption.NOFOLLOW_LINKS)) { stalePaths.add(path); } } if (stalePaths.size() > 0) { logger.log(Level.INFO, "Cancelling stale path watches ..."); for (Path stalePath : stalePaths) { unregisterWatch(stalePath); } } }
/** * Creates a recursive watcher for the given root path. The returned watcher * will ignore the ignore paths and fire an event through the {@link WatchListener} * as soon as the settle delay (in ms) has passed. * * <p>The method returns a platform-specific recursive watcher: {@link WindowsRecursiveWatcher} * for Windows and {@link DefaultRecursiveWatcher} for other operating systems. */ public static RecursiveWatcher createRecursiveWatcher(Path root, List<Path> ignorePaths, int settleDelay, WatchListener listener) { if (EnvironmentUtil.isWindows()) { return new WindowsRecursiveWatcher(root, ignorePaths, settleDelay, listener); } else { return new DefaultRecursiveWatcher(root, ignorePaths, settleDelay, listener); } }