private void dealWithWatchKey(WatchEntity entity, WatchKey key) throws IOException {
        Path contextPath = entity.getPath(key);
        LOGGER.info("Find creation events in path: {}", contextPath.toAbsolutePath());
        for (WatchEvent<?> watchEvent : key.pollEvents()) {
            Path child = resolvePathFromEvent(watchEvent, contextPath);
            if (child == null) {
                continue;
            }
            if (Files.isDirectory(child)) {
                LOGGER.info("The find creation event is triggered by a directory: {}", child.getFileName());
                entity.registerRecursively(child);
                continue;
            }
            handleFilePath(child, entity);
        }
        resetWatchKey(entity, key, contextPath);
    }
Watch directory, if new valid files are created, create instance correspondingly.
inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/task/logcollection/local/FileTask.java