/** * Construct a monitor with the specified interval and set of observers. * * @param interval The amount of time in miliseconds to wait between * checks of the file system * @param observers The set of observers to add to the monitor. */ public FileChangeMonitor(long interval, FileChangeObserver... observers) { this(interval); if (observers != null) { for (FileChangeObserver observer : observers) { addObserver(observer); } } }
/** * Stop monitoring. * * @throws Exception if an error occurs initializing the observer */ public synchronized void stop() throws Exception { stop(interval); }
monitor = new FileChangeMonitor(2000); monitor.addObserver(new FileChangeObserver(dir1, listener)); monitor.addObserver(new FileChangeObserver(dir2, listener)); Try.throwUnchecked(() -> monitor.start()); log.info("Watching doc changes...");
FileChangeMonitor monitor = new FileChangeMonitor(2000); monitor.addObserver(createObserver(dir, listener)); monitor.start(); log.info("Reload enabled, watching [{}]...", toPaths(dirs));
@Override public void addObserver(FileChangeObserver observer) { super.addObserver(observer); if(!running) { if(config.isReloadEnabled()) { log.trace("Start app file monitor at interval : " + interval); Try.throwUnchecked(this::start); } } }
public void close() { if(null != monitor) { Try.catchAll(() -> monitor.stop()); } }