@Override
    public void run() {
        try {
            WatchKey key;
            while ((key = watchService.take()) != null) {
                final Path dirPath = (Path) key.watchable();
                for (WatchEvent<?> event : key.pollEvents()) {
                    if (event.kind().type() == Path.class) {
                        @SuppressWarnings("unchecked")
                        final Path filePath = dirPath.resolve(((WatchEvent<Path>) event).context());
                        if (event.kind().equals(ENTRY_DELETE)) {
                            logger.warn("Ignoring a deleted file: {}", filePath);
                            continue;
                        }
                        runCallback(filePath);
                    } else if (event.kind().equals(OVERFLOW)) {
                        logger.debug("Watch events may have been lost for path: {}", dirPath);
                        runCallback(dirPath);
                    } else {
                        logger.debug("Ignoring unexpected event type: {}", event.kind().name());
                    }
                }
                final boolean reset = key.reset();
                if (!reset) {
                    logger.info("Path will no longer be watched: {}", dirPath);
                }
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            logger.trace("File watching thread interrupted");
        } catch (ClosedWatchServiceException e) {
            // do nothing
        }
    }
Initializes a runnable which watches files.
@param watchService the {@code WatchService} to receive events from
@param fileSystemWatchContext the context which contains target files
core/src/main/java/com/linecorp/armeria/client/endpoint/FileWatcherRunnable.java