@SuppressWarnings ( "unchecked" ) private void handleEvent ( final WatchEvent<?> event ) { final Kind<?> kind = event.kind (); if ( kind == StandardWatchEventKinds.OVERFLOW ) { // FIXME: full rescan return; } final Path path = this.path.resolve ( ( (WatchEvent<Path>)event ).context () ); if ( kind == StandardWatchEventKinds.ENTRY_CREATE ) { this.listener.event ( path, Event.ADDED ); } else if ( kind == StandardWatchEventKinds.ENTRY_DELETE ) { this.listener.event ( path, Event.REMOVED ); } else if ( kind == StandardWatchEventKinds.ENTRY_MODIFY ) { this.listener.event ( path, Event.MODIFIED ); } }
/** * A method to register all the files which will be under the given start path to look * @param start the path to start the search files to be registered * @throws IOException */ public void registerAll(Path start) throws IOException { try { // walk all folders here recursively call the below method for each folder(not file!) the variable dir is a Path Object!!! Kind[] events = { ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY}; walkFiles( start.toFile(), events); /*Files.walk(start) .filter(path -> Files.isDirectory(path)) .forEach(path -> { try { path.register(folderWatcher, events, SensitivityWatchEventModifier.HIGH); // System.out.println("The reg path: " + path); } catch (IOException ex) { Logger.getLogger(RealTimeFolderWatcher.class.getName()).log(Level.SEVERE, null, ex); } });*/ } catch (IOException ex) { Logger.getLogger(RealTimeFolderWatcher.class.getName()).log(Level.SEVERE, null, ex); } }
@SuppressWarnings("unchecked") @Override public void run() { while (running) { try { final WatchKey watchKey = watcher.take(); for (final WatchEvent<?> event : watchKey.pollEvents()) { Path changed = (Path) event.context(); if (changed == null || event.kind() == StandardWatchEventKinds.OVERFLOW) { System.out.println("bad file watch event: " + event); continue; } changed = watchedDirectory.resolve(changed); for (final ListenerAndPath x : listeners) { if (Thread.interrupted() && !running) return; if (changed.startsWith(x.startPath)) { x.listener.fileChanged(changed, (Kind<Path>) event.kind()); } } } watchKey.reset(); } catch (final InterruptedException e) {} } }
/** Notify file system event. */ void processEvent() { while(true) { WatchKey signal; try { signal = watcher.take(); } catch (InterruptedException e) { return; } for(WatchEvent<?> event : signal.pollEvents()) { Kind<?> kind = event.kind(); if(kind == StandardWatchEventKinds.OVERFLOW) { continue; } Path name = (Path)event.context(); notify(name.toAbsolutePath().toString(), kind); } key.reset(); } }
@Override protected boolean processEvent(Kind<?> kind, Path filename) throws IOException { if (!isMetadataFile(filename)) { return false; } LOG.trace("Handling {} event on {}", kind, filename); Optional<TailMetadata> tail = read(Paths.get(baseConfiguration.getLogWatcherMetadataDirectory()).resolve(filename)); if (!tail.isPresent()) { return false; } synchronized (listeners) { for (TailMetadataListener listener : listeners) { listener.tailChanged(tail.get()); } } return true; }
private void processWatchEvent(final Kind<Path> watchEventKind, final Path path) { final String dropboxPathLower = PathUtil.extractDropboxPath(localDir, path) .toLowerCase(Locale.getDefault()); if (globalOperationsTracker.isTracked(dropboxPathLower)) { LOG.trace("Path already tracked. Skipping: {}", () -> path); } else { final LocalFolderChangeType changeType = LocalFolderChangeType .fromWatchEventKind(watchEventKind); final LocalFolderData localPathChange = new LocalFolderData(path, changeType); LOG.trace("Local event {} on path {}", changeType, path); try { localPathChanges.put(localPathChange); } catch (final Exception ex) { LOG.error("Interrupted", ex); } } }
public static void main(String[] args) throws Throwable { String tempDirPath = "/tmp"; System.out.println("Starting watcher for " + tempDirPath); Path p = Paths.get(tempDirPath); WatchService watcher = FileSystems.getDefault().newWatchService(); Kind<?>[] watchKinds = { ENTRY_CREATE, ENTRY_MODIFY }; p.register(watcher, watchKinds); mainRunner = Thread.currentThread(); new Thread(new DemoService()).start(); while (!done) { WatchKey key = watcher.take(); for (WatchEvent<?> e : key.pollEvents()) { System.out.println( "Saw event " + e.kind() + " on " + e.context()); if (e.context().toString().equals("MyFileSema.for")) { System.out.println("Semaphore found, shutting down watcher"); done = true; } } if (!key.reset()) { System.err.println("Key failed to reset!"); } } }
public void watch( final Path dir, final Kind<Path>[] kinds) throws IOException { WatchService service = FileSystems.getDefault().newWatchService(); // Rationale for SensitivityWatchEventModifier.HIGH: // http://stackoverflow.com/questions/9588737/is-java-7-watchservice-slow-for-anyone-else dir.register( service, kinds, SensitivityWatchEventModifier.HIGH); m_logger.info("Watching directory: {}", dir); m_watcher = new WatcherThread(service, m_eventBus); m_watcher.start(); // Start watcher thread }
EphemeralFsWatchKey( EphemeralFsWatchService watchService, EphemeralFsPath watchable, INode iNode, EphemeralFsFileSystem fs, Kind<?>... events) { this.watchService = watchService; if(!watchable.isAbsolute()) { throw new IllegalArgumentException("path must be absolute"); } this.watchable = watchable; this.iNode = iNode; this.fs = fs; interestOps = new HashSet<>(); for(Kind<?> event : events) { interestOps.add(event); } }
private void processEvent(Path dir, WatchEvent<Path> event) { // Context for directory entry event is the file name of entry Path relChild = event.context(); Path child = dir.resolve(relChild); Kind<Path> kind = event.kind(); if(kind == ENTRY_MODIFY) { handleModification(child, externalInitiator); } else if(kind == ENTRY_CREATE) { handleCreation(child, externalInitiator); } else if(kind == ENTRY_DELETE) { model.delete(child, externalInitiator); } else { throw new AssertionError("unreachable code"); } }
/** * Precondition: Event and child must not be null. * @param kind type of the event (create, modify, ...) * @param source Identifies the related file. */ private void handleEvent(Kind<Path> kind, Path source) { try { if(PathUtils.isFileHidden(source)){ return; } if (kind.equals(ENTRY_CREATE)) { addNotifyEvent(new NotifyFileCreated(source)); } else if (kind.equals(ENTRY_MODIFY)) { addNotifyEvent(new NotifyFileModified(source)); } else if (kind.equals(ENTRY_DELETE)) { addNotifyEvent(new NotifyFileDeleted(source)); } else if (kind.equals(OVERFLOW)) { // error - overflow... should not happen here (continue if such an event occurs). // handled already logger.warn("Overflow event from watch service. Too many events?"); } else { logger.warn("Unknown event received"); } } catch (InterruptedException iex) { // put into queue failed logger.info("Handling event interrupted.", iex); } }
public Watcher(final BiConsumer<Kind<?>, Path> listener, final Path... dirs) throws IOException { this.watcher = FileSystems.getDefault().newWatchService(); this.keys = new HashMap<WatchKey, Path>(); this.listener = listener; for (Path dir : dirs) { registerAll(dir); } this.scanner = new Thread(() -> { boolean process = true; while (!stopped && process) { process = processEvents(); } }, "HotswapScanner"); scanner.setDaemon(true); }
@SuppressWarnings("unchecked") @Test public void registerTreeRecursive() throws Exception { new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class, WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class) .expect(newThread) .expect(registerTree(true, false)) .expect(takeInterrupt) .run(unit -> { FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class), unit.get(WatchService.class), ImmutableSet.of(unit.get(FileEventOptions.class))); unit.captured(ThreadFactory.class).get(0).newThread(monitor); }, unit -> { unit.captured(Runnable.class).get(0).run(); unit.captured(FileVisitor.class).get(0).preVisitDirectory(unit.get(Path.class), null); }); }
@Test public void registerTree() throws Exception { new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class, WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class) .expect(newThread) .expect(registerTree(false, false)) .expect(takeInterrupt) .run(unit -> { FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class), unit.get(WatchService.class), ImmutableSet.of(unit.get(FileEventOptions.class))); unit.captured(ThreadFactory.class).get(0).newThread(monitor); }, unit -> { unit.captured(Runnable.class).get(0).run(); }); }
@Test public void registerTreeErr() throws Exception { new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class, WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class) .expect(newThread) .expect(registerTree(false, true)) .expect(takeInterrupt) .run(unit -> { FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class), unit.get(WatchService.class), ImmutableSet.of(unit.get(FileEventOptions.class))); unit.captured(ThreadFactory.class).get(0).newThread(monitor); }, unit -> { unit.captured(Runnable.class).get(0).run(); }); }
@Test public void pollIgnoreMissing() throws Exception { new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class, WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class) .expect(newThread) .expect(registerTree(false, false)) .expect(takeIgnore) .expect(takeInterrupt) .run(unit -> { FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class), unit.get(WatchService.class), ImmutableSet.of(unit.get(FileEventOptions.class))); unit.captured(ThreadFactory.class).get(0).newThread(monitor); }, unit -> { unit.captured(Runnable.class).get(0).run(); }); }
@Test public void pollEvents() throws Exception { Path path = Paths.get("target/foo.txt"); new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class, WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class, WatchEvent.class, PathMatcher.class, FileEventHandler.class) .expect(newThread) .expect(registerTree(false, false)) .expect(take) .expect(poll(StandardWatchEventKinds.ENTRY_MODIFY, path)) .expect(filter(true)) .expect(handler(StandardWatchEventKinds.ENTRY_MODIFY, false)) .expect(recursive(false, false)) .expect(reset(true)) .expect(takeInterrupt) .run(unit -> { FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class), unit.get(WatchService.class), ImmutableSet.of(unit.get(FileEventOptions.class))); unit.captured(ThreadFactory.class).get(0).newThread(monitor); }, unit -> { unit.captured(Runnable.class).get(0).run(); }); }
@Test public void pollEventsInvalid() throws Exception { Path path = Paths.get("target/foo.txt"); new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class, WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class, WatchEvent.class, PathMatcher.class, FileEventHandler.class) .expect(newThread) .expect(registerTree(false, false)) .expect(take) .expect(poll(StandardWatchEventKinds.ENTRY_MODIFY, path)) .expect(filter(true)) .expect(handler(StandardWatchEventKinds.ENTRY_MODIFY, false)) .expect(recursive(false, false)) .expect(reset(false)) .run(unit -> { FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class), unit.get(WatchService.class), ImmutableSet.of(unit.get(FileEventOptions.class))); unit.captured(ThreadFactory.class).get(0).newThread(monitor); }, unit -> { unit.captured(Runnable.class).get(0).run(); }); }
@Test public void pollEventsRecursive() throws Exception { Path path = Paths.get("target/foo.txt"); new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class, WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class, WatchEvent.class, PathMatcher.class, FileEventHandler.class) .expect(newThread) .expect(registerTree(false, false)) .expect(take) .expect(poll(StandardWatchEventKinds.ENTRY_CREATE, path)) .expect(filter(true)) .expect(handler(StandardWatchEventKinds.ENTRY_CREATE, false)) .expect(recursive(true, false)) .expect(reset(true)) .expect(takeInterrupt) .run(unit -> { FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class), unit.get(WatchService.class), ImmutableSet.of(unit.first(FileEventOptions.class))); unit.captured(ThreadFactory.class).get(0).newThread(monitor); }, unit -> { unit.captured(Runnable.class).get(0).run(); }); }
@Test public void pollEventsRecursiveErr() throws Exception { Path path = Paths.get("target/foo.txt"); new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class, WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class, WatchEvent.class, PathMatcher.class, FileEventHandler.class) .expect(newThread) .expect(registerTree(false, false)) .expect(take) .expect(poll(StandardWatchEventKinds.ENTRY_CREATE, path)) .expect(filter(true)) .expect(handler(StandardWatchEventKinds.ENTRY_CREATE, false)) .expect(recursive(true, true)) .expect(reset(true)) .expect(takeInterrupt) .run(unit -> { FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class), unit.get(WatchService.class), ImmutableSet.of(unit.first(FileEventOptions.class))); unit.captured(ThreadFactory.class).get(0).newThread(monitor); }, unit -> { unit.captured(Runnable.class).get(0).run(); }); }
@Test public void pollEventWithHandleErr() throws Exception { Path path = Paths.get("target/foo.txt"); new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class, WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class, WatchEvent.class, PathMatcher.class, FileEventHandler.class) .expect(newThread) .expect(registerTree(false, false)) .expect(take) .expect(poll(StandardWatchEventKinds.ENTRY_MODIFY, path)) .expect(filter(true)) .expect(handler(StandardWatchEventKinds.ENTRY_MODIFY, true)) .expect(recursive(false, false)) .expect(reset(true)) .expect(takeInterrupt) .run(unit -> { FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class), unit.get(WatchService.class), ImmutableSet.of(unit.get(FileEventOptions.class))); unit.captured(ThreadFactory.class).get(0).newThread(monitor); }, unit -> { unit.captured(Runnable.class).get(0).run(); }); }
@Test public void pollEventsNoMatches() throws Exception { Path path = Paths.get("target/foo.txt"); new MockUnit(Injector.class, Env.class, WatchService.class, FileEventOptions.class, Path.class, WatchEvent.Kind.class, WatchEvent.Modifier.class, WatchKey.class, WatchEvent.class, PathMatcher.class, FileEventHandler.class) .expect(newThread) .expect(registerTree(false, false)) .expect(take) .expect(poll(StandardWatchEventKinds.ENTRY_MODIFY, path)) .expect(filter(false)) .expect(recursive(false, false)) .expect(reset(true)) .expect(takeInterrupt) .run(unit -> { FileMonitor monitor = new FileMonitor(unit.get(Injector.class), unit.get(Env.class), unit.get(WatchService.class), ImmutableSet.of(unit.get(FileEventOptions.class))); unit.captured(ThreadFactory.class).get(0).newThread(monitor); }, unit -> { unit.captured(Runnable.class).get(0).run(); }); }
@SuppressWarnings("rawtypes") private Block poll(final Kind kind, final Path path) { return unit -> { WatchEvent event = unit.get(WatchEvent.class); expect(event.kind()).andReturn(kind); expect(event.context()).andReturn(path); Path source = unit.get(Path.class); Path resolved = unit.mock(Path.class); unit.registerMock(Path.class, resolved); expect(source.resolve(path)).andReturn(resolved); WatchEvent overflow = unit.mock(WatchEvent.class); expect(overflow.kind()).andReturn(StandardWatchEventKinds.OVERFLOW); expect(overflow.context()).andReturn(path); WatchKey key = unit.get(WatchKey.class); expect(key.pollEvents()).andReturn(ImmutableList.of(event, overflow)); }; }
public Watcher(final BiConsumer<Kind<?>, Path> listener, final Path... dirs) throws IOException { this.watcher = FileSystems.getDefault().newWatchService(); this.keys = new HashMap<WatchKey, Path>(); this.listener = listener; for (Path dir : dirs) { registerAll(dir); } this.scanner = new Thread(() -> { boolean process = true; listener.accept(ENTRY_MODIFY, dirs[0]); try { while (process) { process = processEvents(); } } catch (ClosedWatchServiceException ex) { log.trace("watch service closed", ex); } }, "asset-compiler"); scanner.setDaemon(true); }
public static WatchEvent<Path> createPathEvent(final Path file, final Kind<Path> kind) { return new WatchEvent<Path>() { @Override public Kind<Path> kind() { return kind; } @Override public int count() { return 0; } @Override public Path context() { return file; } }; }
public static WatchEvent<Object> createOverflowEvent() { return new WatchEvent<Object>() { @Override public Kind<Object> kind() { return StandardWatchEventKinds.OVERFLOW; } @Override public int count() { return 0; } @Override public Object context() { return null; } }; }
private void notifyFileChange(Kind<?> kind, Path child) { WatchFolderNotifyInfo notifyInfo = new WatchFolderNotifyInfo(); notifyInfo.setId(watchHandle); notifyInfo.setExtraInfo(extraInfo); if (kind == ENTRY_CREATE) { notifyInfo.setKind(EWatchFolderNotifyKind.EntryCreated); } else if (kind == ENTRY_MODIFY) { notifyInfo.setKind(EWatchFolderNotifyKind.EntryModified); } else if (kind == ENTRY_DELETE) { notifyInfo.setKind(EWatchFolderNotifyKind.EntryDeleted); } FileInfo fileInfo = FileInfoHelper.makeFileInfo(child.toFile()); notifyInfo.setFileInfo(fileInfo); try { notifyService.notify(notifyInfo); } catch (RemoteException e) { e.printStackTrace(); } }
@Override public void run() { try (WatchService watchService = this.path.getFileSystem().newWatchService()) { this.path.register(watchService, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE); this.log.debug("Watch configuration change on {}", this.path.toString()); WatchKey watchKey; do { watchKey = watchService.take(); for (final WatchEvent<?> event : watchKey.pollEvents()) { Kind<?> kind = event.kind(); if (StandardWatchEventKinds.ENTRY_CREATE.equals(kind) || StandardWatchEventKinds.ENTRY_MODIFY.equals(kind)) { this.log.debug("Reloading configuration"); this.configuration.reload(); return; } } } while (watchKey.reset()); this.log.info("Configuration watching service stopped"); watchKey.cancel(); watchService.close(); } catch (IOException | InterruptedException e) { this.log.error("Configuration watching service stopped", e); } }
/** * Handles all events given events for the given watch key. * * @param key * @param events */ private void handleEvents(final WatchKey key, final List<WatchEvent<?>> events) { final Path parent = (Path) key.watchable(); logger.debug("An event occured in parent {}", parent.toAbsolutePath()); for (final WatchEvent<?> event : events) { Path path = (Path) event.context(); path = parent.resolve(path); @SuppressWarnings("unchecked") final Kind<Path> kind = (Kind<Path>) event.kind(); logger.debug("Received an event at context: {} of kind: {}", path .toAbsolutePath(), kind.name()); handleEvent(kind, path.toFile()); } key.reset(); }
/** * Handles the given event for the given file. * * @param kind; either created/modified/deleted * @param file; the file that the event occurred on/to. */ private void handleEvent(final Kind<Path> kind, final File file) { if (kind == ENTRY_CREATE) { // Watch this file/directory and any sub-directories. This will // generate created events for the given file and any children // of the given file. watch(file); } else if (kind == ENTRY_MODIFY) { // We don't dispatch MODIFY events for directories as they don't // indicate what happened within the directory. if (file.isFile()) { connector.fireModifyEvent(file); } } else if (kind == ENTRY_DELETE) { // When a directory is deleted the Java watch services does not // generate events for any files or sub-directories within // it, so we must do that ourselves. The WatchKeys for // sub-directories will be correctly cancelled by the watch service // so we don't need to worry about deallocating // them. recursivelyFireDeleteEvent(file); } }
/** * Handles file change event * * @param dir * @param currentEvent * @throws IOException */ private void handleEvent(Path dir, WatchEvent<Path> event) throws IOException { if (ObjectUtils.notNull(event)) { Path prePath = event.context(); Path path = dir.resolve(prePath); String fileName = path.toString(); int count = event.count(); Kind<?> kind = event.kind(); if (kind == StandardWatchEventKinds.ENTRY_MODIFY) { LogUtils.info(LOG, MODIFY_MESSAGE, fileName, count); redeployFile(fileName); } else if (kind == StandardWatchEventKinds.ENTRY_DELETE) { LogUtils.info(LOG, DELETE_MESSAGE, fileName, count); undeployFile(fileName); } else if (kind == StandardWatchEventKinds.ENTRY_CREATE) { LogUtils.info(LOG, CREATE_MESSAGE, fileName, count); redeployFile(fileName); } } }
public void walkFiles( File folder, Kind[] events) throws IOException { Queue<File> dirsq = new LinkedList<>(); dirsq.add(folder); while (!dirsq.isEmpty()) { for (File f : dirsq.poll().listFiles()) { if (f.isDirectory()) { dirsq.add(f); f.toPath().register(folderWatcher, events, SensitivityWatchEventModifier.HIGH); } } } }
@Override public final void fileChanged(final Path path, final Kind<Path> kind) { if (ignoreChange(path)) return; synchronized (listenersToUpdate) { // make this section atomic with regard to the one in the thread listenersToUpdate.remove(this); nextUpdate = System.currentTimeMillis() + delayMS; listenersToUpdate.add(this); } thread.interrupt(); }
public FileWatcher(final Path watchedDirectory) throws IOException { this.watchedDirectory = toCanonicalPath(watchedDirectory); watcher = FileSystems.getDefault().newWatchService(); watchedDirectory.register(watcher, new Kind[] {StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY}, ExtendedWatchEventModifier.FILE_TREE); thread.setDaemon(true); thread.start(); }
/** * Polls the configuration file for changes. */ private void pollConfigFileForChanges() { WatchKey key = watcher.poll(); try { if (key == null) { return; } for (WatchEvent<?> event : key.pollEvents()) { Kind<?> kind = event.kind(); if (StandardWatchEventKinds.OVERFLOW == kind) { continue; } // The filename is the context of the event. Path filename = (Path) event.context(); if (configFile.endsWith(filename.toString())) { LOG.info("CORS Filter: Detected change in " + configFile + " , configuration reload required"); reloadRequired = true; } } } finally { if (key != null) { key.reset(); } } }
@Override protected boolean processEvent(Kind<?> kind, final Path filename) throws IOException { metrics.getFilesystemEventsMeter().mark(); if (!isS3MetadataFile(filename)) { return false; } runLock.lock(); try { if (isStopped()) { LOG.warn("Driver is stopped, ignoring file watch event for {}", filename); return false; } final Path fullPath = Paths.get(baseConfiguration.getS3UploaderMetadataDirectory()).resolve(filename); if (kind.equals(StandardWatchEventKinds.ENTRY_DELETE)) { Optional<SingularityS3Uploader> found = Iterables.tryFind(metadataToUploader.values(), new Predicate<SingularityS3Uploader>() { @Override public boolean apply(SingularityS3Uploader input) { return input.getMetadataPath().equals(fullPath); } }); LOG.trace("Found {} to match deleted path {}", found, filename); if (found.isPresent()) { expiring.add(found.get()); } } else { return handleNewOrModifiedS3Metadata(fullPath); } return false; } finally { runLock.unlock(); } }
@Override protected boolean processEvent(Kind<?> kind, Path filename) throws IOException { if (!filename.equals(logfile.getFileName())) { LOG.trace("Ignoring a modification to {} (only care about {})", filename, logfile.getFileName()); return true; } checkRead(false); return true; }
@Override public WatchKey register(WatchService watcher, Kind<?>[] events, Modifier... modifiers) throws IOException { if (!CloudWatchService.class.isAssignableFrom(watcher.getClass())) { throw new IllegalArgumentException("The file system watcher must be of type " + CloudWatchService.class + " but was " + watcher.getClass()); } return ((CloudWatchService)watcher).register(this, events, modifiers); }
protected JWatchKey register(JPath path, Kind<?>[] events, Modifier ... modifiers) { JWatchKey key = new JWatchKey(this, path, events, modifiers); synchronized (this) { _watchList.add(key); } return key; }
public JWatchKey(JWatchService watchService, JPath path, Kind<?>[] events, Modifier ... modifiers) { Objects.requireNonNull(events); _watchService = watchService; _path = path; _events = events; _modifiers = modifiers; _watchHandle = path.getBfsFile().watch(pathString -> onWatch(pathString)); }