public synchronized void dealWithWatchEntity(String originPattern) {
        WatchEntity entity = watchers.get(originPattern);
        if (entity == null) {
            LOGGER.error("Can't find the watch entity for originPattern: " + originPattern);
            return;
        }
        try {
            entity.removeDeletedWatchDir();
            /* Get all creation events until all events are consumed. */
            for (int i = 0; i < entity.getTotalPathSize(); i++) {
                // maybe the watchService is closed ,but we catch this exception!
                final WatchKey key = entity.getWatchService().poll();
                if (key == null) {
                    return;
                }
                dealWithWatchKey(entity, key);
            }
        } catch (Exception e) {
            LOGGER.error("deal with creation event error: ", e);
        }
    }
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