public void run()

in baremaps-server/src/main/java/org/apache/baremaps/server/ChangeResource.java [91:126]


    public void run() {
      try (WatchService watchService = FileSystems.getDefault().newWatchService()) {
        if (tileset != null && Files.exists(tileset)) {
          registerRecursively(tileset.toAbsolutePath().getParent(), watchService);
        }
        if (style != null && Files.exists(style)) {
          registerRecursively(style.toAbsolutePath().getParent(), watchService);
        }
        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
              changes.tryEmitNext(ServerSentEvent.ofData(styleObjectNode.toString()));
            }
          }
          key.reset();
        }
      } catch (InterruptedException | IOException e) {
        logger.error(e.getMessage());
        Thread.currentThread().interrupt();
      }
    }