in baremaps-server/src/main/java/org/apache/baremaps/server/ChangeResource.java [99:134]
public void run() {
try (WatchService watchService = FileSystems.getDefault().newWatchService()) {
if (tileset != null && Files.exists(tileset)) {
tileset.toAbsolutePath().getParent().register(watchService, ENTRY_MODIFY);
}
if (style != null && Files.exists(style)) {
style.toAbsolutePath().getParent().register(watchService, ENTRY_MODIFY);
}
WatchKey key;
while ((key = watchService.take()) != null) {
Path dir = (Path) key.watchable();
for (WatchEvent<?> event : key.pollEvents()) {
Path path = dir.resolve((Path) event.context()).toAbsolutePath();
logger.info("Change detected in {}", path);
if (style != null) {
var value = configReader.read(style);
var styleObjectNode = objectMapper.readValue(value, ObjectNode.class);
// reload the page if changes affected the tileset
if (tileset != null && path.endsWith(tileset.getFileName())) {
styleObjectNode.put("reload", true);
}
// broadcast the changes
sseBroadcaster.broadcast(sseEventBuilder.data(styleObjectNode.toString()).build());
}
}
key.reset();
}
} catch (InterruptedException | IOException e) {
logger.error(e.getMessage());
Thread.currentThread().interrupt();
}
}