@PreDestroy private void shutdown() { executorService.shutdown(); active = false; if (ws != null) { ws.close(); } }
@Override public WatchKey register(WatchService watcher, Kind<?>... events) throws UnsupportedOperationException, IllegalArgumentException, ClosedWatchServiceException, IOException, SecurityException { return watcher.poll(); }
@Override public void execute(final IOWatchServiceExecutor wsExecutor) { while (!isDisposed) { final WatchKey wk; try { wk = ws.take(); } catch (final Exception ex) { break; } try { wsExecutor.execute(wk, AbstractIOWatchService.this); } catch (final Exception ex) { LOG.error("Unexpected error during WatchService execution", ex); } // Reset the key -- this step is critical if you want to // receive further watch events. If the key is no longer valid, // the directory is inaccessible so exit the loop. boolean valid = wk.reset(); if (!valid) { break; } } }
wk = ws.take(); } catch (final Exception ex) { break;
@Override public void dispose() { watchServicesByFS.values() .forEach(ws -> ws.close()); activeIndexerDispatchers.forEach(d -> d.dispose()); super.dispose(); }
wk = ws.take(); } catch (final Exception ex) { break;
@Override public WatchKey register(WatchService watcher, Kind<?>[] events, Modifier... modifiers) throws UnsupportedOperationException, IllegalArgumentException, ClosedWatchServiceException, IOException, SecurityException { return watcher.poll(); }
@Override public void dispose() { watchServicesByFS.values() .forEach(ws -> ws.close()); activeIndexerDispatchers.forEach(d -> d.dispose()); super.dispose(); }
wk = ws.take(); } catch (final Exception ex) { break;
@Override public WatchKey register(WatchService watcher, Kind<?>... events) throws UnsupportedOperationException, IllegalArgumentException, ClosedWatchServiceException, IOException, SecurityException { return watcher.poll(); }
watchService.close();
StandardWatchEventKind.ENTRY_RENAME); final WatchKey k = ws.take();
@Override public WatchKey register(WatchService watcher, Kind<?>[] events, Modifier... modifiers) throws UnsupportedOperationException, IllegalArgumentException, ClosedWatchServiceException, IOException, SecurityException { return watcher.poll(); }
@PreDestroy protected void dispose() { isDisposed = true; for (final WatchService watchService : watchServices) { watchService.close(); } for (final Future<?> job : jobs) { if (!job.isCancelled() && !job.isDone()) { job.cancel(true); } } executorService.shutdown(); // Disable new tasks from being submitted try { // Wait a while for existing tasks to terminate if (!executorService.awaitTermination(AWAIT_TERMINATION_TIMEOUT, TimeUnit.SECONDS)) { executorService.shutdownNow(); // Cancel currently executing tasks // Wait a while for tasks to respond to being cancelled if (!executorService.awaitTermination(AWAIT_TERMINATION_TIMEOUT, TimeUnit.SECONDS)) { LOG.error("Thread pool did not terminate"); } } } catch (InterruptedException ie) { // (Re-)Cancel if current thread also interrupted executorService.shutdownNow(); // Preserve interrupt status Thread.currentThread().interrupt(); } }
StandardWatchEventKind.ENTRY_RENAME); final WatchKey k = ws.take();
false); List<WatchEvent<?>> watchEvents = fsDora1.poll().pollEvents(); assertEquals(3, watchEvents.size()); watchEvents = fsDora2.poll().pollEvents(); assertEquals(3, watchEvents.size()); false); watchEvents = fsDora2.poll().pollEvents(); assertEquals(3, watchEvents.size()); watchEvents = fsDora2.poll().pollEvents(); assertEquals(2, watchEvents.size()); watchEvents = fsDora1.poll().pollEvents(); assertEquals(3, watchEvents.size()); watchEvents = fsDora1.poll().pollEvents(); assertEquals(2, watchEvents.size());