/** {@inheritDoc} */ @Override public void postInit() { super.postInit(); synchronized (lock) { if (fileAlterationMonitor == null) { fileWatchListener = new FileWatchListener(ConfigurationUtilities.getInstance()); fileAlterationMonitor = new FileAlterationMonitor(); File confDir = getFilesystemConfiguration().getConfigurationDirectory(); FileAlterationObserver observer = new FileAlterationObserver(confDir); observer.addListener(getFileWatchListener()); fileAlterationMonitor.addObserver(observer); try { fileAlterationMonitor.start(); } catch (Exception exc) { logger.error("Could not start file monitor", exc); } } } }
/** {@inheritDoc} */ @Override public void preDestroy() { super.preDestroy(); synchronized (lock) { try { if (fileAlterationMonitor != null) fileAlterationMonitor.stop(10); if (fileWatchListener != null) fileWatchListener.clear(); fileAlterationMonitor = null; fileWatchListener = null; } catch (Exception exc) { logger.error("Could not stop file monitor", exc); } } }
/** * 从alterationMonitor中删除fileObserver * * @param fileObserver */ private void removeObserver(SeafileObserver fileObserver) { alterationMonitor.removeObserver(fileObserver.getAlterationObserver()); }
/** * 将fileObserver加入到alterationMonitor中 * * @param fileObserver */ private void addObserver(SeafileObserver fileObserver) { alterationMonitor.addObserver(fileObserver.getAlterationObserver()); }
public void stop() throws Exception { alterationMonitor.stop(); }
private void start() throws Exception { if (!started) { alterationMonitor.start(); started = true; } }