in src/main/java/com/aws/iot/edgeconnectorforkvs/diskmanager/DiskManager.java [121:160]
private void setupWatchService() throws IOException {
try (WatchService watchService = FileSystems.getDefault().newWatchService()) {
try {
edgeConnectorForKVSConfigurationList.forEach(configuration -> {
System.out.println("Start watching!");
Path path = configuration.getVideoRecordFolderPath();
try {
path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE);
log.info(String.format("Start watch service for video record path: %s",
path.getFileName()));
} catch (IOException e) {
log.error(String.format("Start watch service for video record path: %s failed!",
path.toString()));
throw new EdgeConnectorForKVSException(e);
}
});
while (true) {
final WatchKey watchKey = watchService.take();
final Watchable watchable = watchKey.watchable();
if (watchable instanceof Path) {
final Path directoryPath = (Path) watchable;
for (WatchEvent<?> event : watchKey.pollEvents()) {
this.callback.handleWatchEvent(directoryPath, event, diskManagerUtil);
}
}
if (!watchKey.reset()) {
log.warn("Disk Management run into issue. Restarting the process...");
setupDiskManagerThread();
break;
}
}
} catch (InterruptedException e) {
log.error("Disk Management process interrupted! ");
Thread.currentThread().interrupt();
}
}
}