private Path resolvePath(WatchKey key, WatchEvent<?> event) { WatchEvent<Path> ev = cast(event); // Context for directory entry event is the file name of entry. Path contextPath = ev.context(); Path baseWatchedDir = null; Path registeredPath = null; synchronized (this) { baseWatchedDir = keyToService.get(key).getSourcePath(); registeredPath = registeredKeys.get(key); } if (registeredPath != null) { // If the path has been registered in the watch service it relative path can be resolved // The context path is resolved by its already registered parent path return registeredPath.resolve(contextPath); } logger.warn( "Detected invalid WatchEvent '{}' and key '{}' for entry '{}' in not registered file or directory of '{}'", event, key, contextPath, baseWatchedDir); return null; }
/** * Method to call on service activation */ public void activate() { Path pathToWatch = getSourcePath(); if (pathToWatch != null) { watchQueueReader = WatchQueueReader.getInstance(); watchQueueReader.customizeWatchQueueReader(this, pathToWatch, watchSubDirectories()); } }
private Path resolvePath(WatchKey key, WatchEvent<?> event) { WatchEvent<Path> ev = cast(event); // Context for directory entry event is the file name of entry. Path contextPath = ev.context(); Path baseWatchedDir = null; Path registeredPath = null; synchronized (this) { baseWatchedDir = keyToService.get(key).getSourcePath(); registeredPath = registeredKeys.get(key); } if (registeredPath != null) { // If the path has been registered in the watch service it relative path can be resolved // The context path is resolved by its already registered parent path return registeredPath.resolve(contextPath); } logger.warn( "Detected invalid WatchEvent '{}' and key '{}' for entry '{}' in not registered file or directory of '{}'", event, key, contextPath, baseWatchedDir); return null; }
/** * Method to call on service activation */ public void activate() { Path pathToWatch = getSourcePath(); if (pathToWatch != null) { watchQueueReader = WatchQueueReader.getInstance(); watchQueueReader.customizeWatchQueueReader(this, pathToWatch, watchSubDirectories()); } }