@PreDestroy private void shutdown() { executorService.shutdown(); active = false; if (ws != null) { ws.close(); } }
@Override public void dispose() { watchServicesByFS.values() .forEach(ws -> ws.close()); activeIndexerDispatchers.forEach(d -> d.dispose()); super.dispose(); }
@Override public void dispose() { watchServicesByFS.values() .forEach(ws -> ws.close()); activeIndexerDispatchers.forEach(d -> d.dispose()); super.dispose(); }
@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(); } }
watchService.close();
watchService.close();
private void cleanupDeletedFS(FileSystem fs) { WatchService ws = watchServicesByFS.remove(fs.getName()); if (ws != null && !ws.isClose()) { ws.close(); } fs.getRootDirectories().forEach(rootPath -> indexEngine.delete(KObjectUtil.toKCluster(rootPath))); }
private void cleanupDeletedFS(FileSystem fs) { WatchService ws = watchServicesByFS.remove(fs.getName()); if (ws != null && !ws.isClose()) { ws.close(); } fs.getRootDirectories().forEach(rootPath -> indexEngine.delete(KObjectUtil.toKCluster(rootPath))); }
@Test public void recreatingFileSystemMakesNewWatchService() throws Exception { URI uri = new URI("test:///some/path"); Map<String, ?> env = Collections.emptyMap(); FileSystem fs1 = ioService.newFileSystem(uri, env); verify(fs1).newWatchService(); FSPath fsPath = mock(FSPath.class); when(fsPath.getFileSystem()).thenReturn(fs1); ioService.delete(fsPath); verify(fs1.newWatchService()).close(); FileSystem fs2 = ioService.newFileSystem(uri, env); // Stubs are reused so this will have been invoked one above in IOService, and once in this test in a verify method. verify(fs2, times(3)).newWatchService(); }
@Test public void recreatingFileSystemMakesNewWatchService() throws Exception { URI uri = new URI("test:///some/path"); Map<String, ?> env = Collections.emptyMap(); FileSystem fs1 = ioService.newFileSystem(uri, env); verify(fs1).newWatchService(); FSPath fsPath = mock(FSPath.class); when(fsPath.getFileSystem()).thenReturn(fs1); ioService.delete(fsPath); verify(fs1.newWatchService()).close(); FileSystem fs2 = ioService.newFileSystem(uri, env); // Stubs are reused so this will have been invoked one above in IOService, and once in this test in a verify method. verify(fs2, times(3)).newWatchService(); }