package org.argeo.cms.jshell;
import java.io.IOException;
+import java.nio.file.ClosedWatchServiceException;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystems;
import java.nio.file.Files;
private Path jtermBase;
private Path jtermLinkedDir;
+ private WatchService watchService;
+
public void start() throws Exception {
// TODO better define application id, make it configurable
String applicationID;
new Thread(() -> {
try {
- WatchService watchService = FileSystems.getDefault().newWatchService();
+ watchService = FileSystems.getDefault().newWatchService();
jshBase.register(watchService, StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE);
}
key.reset();
}
+ } catch (ClosedWatchServiceException e) {
+ if (log.isTraceEnabled())
+ log.trace("JShell file watch service was closed");
} catch (IOException | InterruptedException e) {
- e.printStackTrace();
+ log.error("Unexpected exception in JShell file watch service", e);
}
}, "JShell local sessions watcher").start();
}
}
public void stop() {
+ if (watchService != null)
+ try {
+ watchService.close();
+ } catch (IOException e) {
+ log.error("Cannot close JShell watch service", e);
+ }
try {
Files.delete(jshLinkedDir);
} catch (IOException e) {