创建并初始化监听，监听所有事件
@param path 路径
@param watcher {@link Watcher}
@return {@link WatchMonitor}
494926
public static WatchMonitor createAll(String path, Watcher watcher){
		return createAll(Paths.get(path), watcher);
	}
722027
private static List<String> loadAndWatchDir(Path path, ResourceLoader resourceLoader, String resourcePaths) {
        final List<String> result = new ArrayList<>();
        try {
            Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                        throws IOException {
                    result.addAll(load(file.toAbsolutePath().toString()));
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException ex) {
            LOGGER.error("加载资源失败："+path, ex);
        }
        DirectoryWatcher.WatcherCallback watcherCallback = new DirectoryWatcher.WatcherCallback(){

            private long lastExecute = System.currentTimeMillis();
            @Override
            public void execute(WatchEvent.Kind<?> kind, String path) {
                //一秒内发生的多个相同事件认定为一次，防止短时间内多次加载资源
                if(System.currentTimeMillis() - lastExecute > 1000){
                    lastExecute = System.currentTimeMillis();
                    LOGGER.info("事件："+kind.name()+" ,路径："+path);
                    synchronized(AutoDetector.class){
                        DirectoryWatcher dw = WATCHER_CALLBACKS.get(this);
                        String paths = RESOURCES.get(dw);
                        ResourceLoader loader = RESOURCE_LOADERS.get(dw);
                        LOGGER.info("重新加载数据");
                        loadAndWatch(loader, paths);
                    }
                }
            }

        };
        DirectoryWatcher directoryWatcher = DirectoryWatcher.getDirectoryWatcher(watcherCallback,
                StandardWatchEventKinds.ENTRY_CREATE,
                    StandardWatchEventKinds.ENTRY_MODIFY,
                    StandardWatchEventKinds.ENTRY_DELETE);
        directoryWatcher.watchDirectoryTree(path);

        WATCHER_CALLBACKS.put(watcherCallback, directoryWatcher);
        RESOURCES.put(directoryWatcher, resourcePaths);
        RESOURCE_LOADERS.put(directoryWatcher, resourceLoader);

        return result;
    }
372396
public static WatchMonitor create(URI uri, int maxDepth, WatchEvent.Kind<?>... events){
		return create(Paths.get(uri), maxDepth, events);
	}
1327192
public DirectoryWatcher newWatcher(String dir, String separator) throws IOException {
    return newWatcher(Paths.get(dir), separator);
  }
1159754
def setup_file_watcher(path, use_polling=False):
    
    if use_polling:
        observer_class = watchdog.observers.polling.PollingObserver
    else:
        observer_class = EVENTED_OBSERVER

    file_event_handler = _SourceChangesHandler(patterns=["*.py"])
    file_watcher = observer_class()
    file_watcher.schedule(file_event_handler, path, recursive=True)
    file_watcher.start()
    return file_watcher
228489
@Deprecated
    public void addWatcher(File file, Listener watcher) {
        addWatcher(file.toPath(), watcher);
    }
541086
function Watcher(path, handler) {
    this._ = Fs.watch(path, handler);
    this.a_path = Abs(path);
    this.handler = handler;
}
528759
public static WatchMonitor create(String path, WatchEvent.Kind<?>... events){
		return create(path, 0, events);
	}
1087282
public String createNode(final String path, final boolean watch, final boolean ephimeral) {
		String createdNodePath = null;
		try {

			final Stat nodeStat =  zooKeeper.exists(path, watch);

			if(nodeStat == null) {
				createdNodePath = zooKeeper.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, (ephimeral ?  CreateMode.EPHEMERAL_SEQUENTIAL : CreateMode.PERSISTENT));
			} else {
				createdNodePath = path;
			}

		} catch (KeeperException | InterruptedException e) {
			throw new IllegalStateException(e);
		}

		return createdNodePath;
	}
1144691
function addWatcher(dirPath) {
    Debug._l(dirPath);
    Watcher(dirPath, function (filePath, action) {
        switch (action) {
            case Watcher.ADD_EVENT:
            case Watcher.CHANGE_EVENT:
                Debug._l(generateIdFromFilePath(filePath));
                generateCache(filePath);
                break;

            case Watcher.DELETE_EVENT:
                removeCache(generateIdFromFilePath(filePath));
                break;

        }
    });

}
398941
private void watch(WatcherCallback watcherCallback){
        try {
            while (true) {
                final WatchKey key = watchService.take();
                if(key == null){
                    continue;
                }
                for (WatchEvent<?> watchEvent : key.pollEvents()) {
                    final WatchEvent.Kind<?> kind = watchEvent.kind();
                    //忽略无效事件
                    if (kind == StandardWatchEventKinds.OVERFLOW) {
                        continue;
                    }
                    final WatchEvent<Path> watchEventPath = (WatchEvent<Path>) watchEvent;
                    //path是相对路径（相对于监控目录）
                    final Path contextPath = watchEventPath.context();
                    LOGGER.info("contextPath:"+contextPath);
                    //获取监控目录
                    final Path directoryPath = directories.get(key);
                    LOGGER.info("directoryPath:"+directoryPath);
                    //得到绝对路径
                    final Path absolutePath = directoryPath.resolve(contextPath);
                    LOGGER.info("absolutePath:"+absolutePath);
                    LOGGER.info("kind:"+kind);
                    //判断事件类别
                    switch (kind.name()) {
                        case "ENTRY_CREATE":
                            if (Files.isDirectory(absolutePath, LinkOption.NOFOLLOW_LINKS)) {
                                LOGGER.info("新增目录：" + absolutePath);
                                //为新增的目录及其所有子目录注册监控事件
                                registerDirectoryTree(absolutePath);
                            }else{
                                LOGGER.info("新增文件：" + absolutePath);
                            }
                            break;
                        case "ENTRY_DELETE":
                            LOGGER.info("删除：" + absolutePath);
                            break;
                        case "ENTRY_MODIFY":
                            LOGGER.info("修改：" + absolutePath);
                            break;
                    }
                    //业务逻辑
                    watcherCallback.execute(kind, absolutePath.toAbsolutePath().toString());
                }
                boolean valid = key.reset();
                if (!valid) {
                    if(directories.get(key) != null){
                        LOGGER.info("停止监控目录："+directories.get(key));
                        directories.remove(key);
                    }
                }
            }
        } catch (InterruptedException ex) {
            LOGGER.info("监控目录线程退出");
        } finally{
            try {
                watchService.close();
                LOGGER.info("关闭监控目录服务");
            } catch (IOException ex) {
                LOGGER.error("关闭监控目录服务出错", ex);
            }
        }
    }
383541
@Deprecated
    public void addWatcher(File file, Watcher watcher) {
        addWatcher(file.toPath(), watcher);
    }
1031678
def watch_dir(path: str) -> None:
    """"""
    _compile_exclude_patterns()
    if config.autoreload or config.debug:
        # Add files to watch for autoreload
        p = pathlib.Path(path)
        p.resolve()
        _add_watch_path(p)
400722
function Watch_file(that,          // @arg this
                    watchFilePath, // @arg String   - watch file path
                    callback) {    // @arg Function - callback(null):void
    var timerID = 0;

    if (this._options.verbose) {
        console.log("  file: " + watchFilePath);
    }

    fs.watchFile(watchFilePath, _watchdogCallback);

    function _watchdogCallback() {
        if (timerID) {
            clearTimeout(timerID); timerID = 0;
        }
        timerID = setTimeout(function() {
            clearTimeout(timerID); timerID = 0;

            callback(null);
        }, that._options.delay);
    }
}
214765
private void _watchNode(String path) throws ZooKeeperException {
        try {
            cacheNodeWatcher.get(path);
        } catch (Exception e) {
            if (e instanceof ZooKeeperException) {
                throw (ZooKeeperException) e;
            } else {
                throw new ZooKeeperException(e);
            }
        }
    }
238378
function addWatcher(file, handler, callback)
{
  fs.stat(file, function(err, stat)
  {
    if (err) return callback(false);

    fs.watch(file, handler(file));

    callback(true, stat.mtime.getTime());
  });
}
263862
public void addModificationObserver (String path, ModificationObserver obs)
    {
        ObservedResource resource = _observed.get(path);
        if (resource == null) {
            File file = getResourceFile(path);
            if (file == null) {
                return; // only resource files will ever be modified
            }
            _observed.put(path, resource = new ObservedResource(file));
        }
        resource.observers.add(obs);
    }