public void run()

in persistence-commons/persistence-commons-protobuf/src/main/java/org/kie/kogito/persistence/protobuf/ProtobufMonitorService.java [141:172]


        public void run() {
            try (WatchService ws = FileSystems.getDefault().newWatchService()) {
                keys.put(folder.register(ws, ENTRY_MODIFY, ENTRY_CREATE), folder);
                Files.walkFileTree(folder, new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                        keys.put(dir.register(ws, ENTRY_MODIFY, ENTRY_CREATE), dir);
                        return FileVisitResult.CONTINUE;
                    }
                });
                if (onFolderWatch != null) {
                    onFolderWatch.accept(folder);
                }
                WatchKey key;
                while ((key = ws.take()) != null) {
                    for (WatchEvent<?> event : key.pollEvents()) {
                        LOGGER.debug("Event kind: {}. File affected: {}", event.kind(), event.context());
                        Path path = (Path) event.context();
                        Path proto = keys.get(key).resolve(path);
                        if (Files.isDirectory(proto)) {
                            registerFilesFromFolder(proto);
                            keys.put(proto.register(ws, ENTRY_MODIFY, ENTRY_CREATE), proto);
                        } else if (protoFileMatcher.matches(path) && !KOGITO_APPLICATION_PROTO.equals(path.getFileName().toFile().getName())) {
                            consumer.accept(proto);
                        }
                    }
                    key.reset();
                }
            } catch (Exception ex) {
                LOGGER.warn("Exception in proto folder watcher for folder: {}, message: {}", folder, ex.getMessage(), ex);
            }
        }