Java Code Examples for org.apache.commons.io.monitor.FileAlterationObserver#addListener()
The following examples show how to use
org.apache.commons.io.monitor.FileAlterationObserver#addListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HbaseConfigMonitor.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
public void init(HbaseAdapter hbaseAdapter, Properties envProperties) { this.hbaseAdapter = hbaseAdapter; this.envProperties = envProperties; File confDir = Util.getConfDirPath(adapterName); try { FileAlterationObserver observer = new FileAlterationObserver(confDir, FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml"))); FileListener listener = new FileListener(); observer.addListener(listener); fileMonitor = new FileAlterationMonitor(3000, observer); fileMonitor.start(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
Example 2
Source File: ESConfigMonitor.java From canal with Apache License 2.0 | 6 votes |
public void init(ESAdapter esAdapter, Properties envProperties) { this.esAdapter = esAdapter; this.envProperties = envProperties; this.adapterName = envProperties.getProperty("es.version"); File confDir = Util.getConfDirPath(adapterName); try { FileAlterationObserver observer = new FileAlterationObserver(confDir, FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml"))); FileListener listener = new FileListener(); observer.addListener(listener); fileMonitor = new FileAlterationMonitor(3000, observer); fileMonitor.start(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
Example 3
Source File: RdbConfigMonitor.java From canal with Apache License 2.0 | 6 votes |
public void init(String key, RdbAdapter rdbAdapter, Properties envProperties) { this.key = key; this.rdbAdapter = rdbAdapter; this.envProperties = envProperties; File confDir = Util.getConfDirPath(adapterName); try { FileAlterationObserver observer = new FileAlterationObserver(confDir, FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml"))); FileListener listener = new FileListener(); observer.addListener(listener); fileMonitor = new FileAlterationMonitor(3000, observer); fileMonitor.start(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
Example 4
Source File: HbaseConfigMonitor.java From canal with Apache License 2.0 | 6 votes |
public void init(HbaseAdapter hbaseAdapter, Properties envProperties) { this.hbaseAdapter = hbaseAdapter; this.envProperties = envProperties; File confDir = Util.getConfDirPath(adapterName); try { FileAlterationObserver observer = new FileAlterationObserver(confDir, FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml"))); FileListener listener = new FileListener(); observer.addListener(listener); fileMonitor = new FileAlterationMonitor(3000, observer); fileMonitor.start(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
Example 5
Source File: ApplicationConfigMonitor.java From canal with Apache License 2.0 | 6 votes |
@PostConstruct public void init() { File confDir = Util.getConfDirPath(); try { FileAlterationObserver observer = new FileAlterationObserver(confDir, FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.prefixFileFilter("application"), FileFilterUtils.suffixFileFilter("yml"))); FileListener listener = new FileListener(); observer.addListener(listener); fileMonitor = new FileAlterationMonitor(3000, observer); fileMonitor.start(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
Example 6
Source File: FileMonitor.java From MercuryTrade with MIT License | 6 votes |
public void start() { String gamePath = Configuration.get().applicationConfiguration().get().getGamePath(); File folder = new File(gamePath + "logs"); this.fileHandler = new MessageFileHandler(gamePath + "logs/Client.txt"); FileAlterationObserver observer = new FileAlterationObserver(folder); monitor = new FileAlterationMonitor(POLLING_INTERVAL); FileAlterationListener listener = new FileAlterationListenerAdaptor() { @Override public void onFileChange(File file) { fileHandler.parse(); } }; observer.addListener(listener); monitor.addObserver(observer); try { monitor.start(); } catch (Exception e) { e.printStackTrace(); } }
Example 7
Source File: FileMonitor.java From util4j with Apache License 2.0 | 6 votes |
/** * 只监控文件发送变化,如果是子目录的文件改变,则目录会变,由于没有过滤目录发生变化,则目录下的文件改变不会监控到 * @param dir * @throws Exception */ public void check1(String dir) throws Exception { File directory = new File(dir); // 轮询间隔 5 秒 long interval = TimeUnit.SECONDS.toMillis(5); // 创建一个文件观察器用于处理文件的格式 IOFileFilter filter=FileFilterUtils.or(FileFilterUtils.suffixFileFilter(".class"), FileFilterUtils.suffixFileFilter(".jar")); FileAlterationObserver observer = new FileAlterationObserver(directory,filter); //设置文件变化监听器 observer.addListener(new MyFileListener()); FileAlterationMonitor monitor = new FileAlterationMonitor(interval); monitor.addObserver(observer);//文件观察 monitor.start(); }
Example 8
Source File: DirectoryMonitor.java From fuchsia with Apache License 2.0 | 6 votes |
public DirectoryMonitor(String directorypath, long polling, String classname) { this.directory = new File(directorypath); this.trackedClassName = classname; this.polling = polling; if (!directory.isDirectory()) { LOG.info("Monitored directory {} not existing - creating directory", directory.getAbsolutePath()); if (!this.directory.mkdirs()) { throw new IllegalStateException("Monitored directory doesn't exist and cannot be created."); } } // We observes all files. FileAlterationObserver observer = new FileAlterationObserver(directory, TrueFileFilter.INSTANCE); observer.checkAndNotify(); observer.addListener(new FileMonitor()); monitor = new FileAlterationMonitor(polling, observer); }
Example 9
Source File: DefaultHttpRequestHandler.java From t-io with Apache License 2.0 | 6 votes |
/** * 扫描文件变化 * @throws Exception */ public void monitorFileChanged() throws Exception { if (httpConfig.monitorFileChange) { if (httpConfig.getPageRoot() != null) { File directory = new File(httpConfig.getPageRoot());//需要扫描的文件夹路径 // 测试采用轮询间隔 5 秒 long interval = TimeUnit.SECONDS.toMillis(5); FileAlterationObserver observer = new FileAlterationObserver(directory, new FileFilter() { @Override public boolean accept(File pathname) { return true; } }); //设置文件变化监听器 observer.addListener(new FileChangeListener(this)); FileAlterationMonitor monitor = new FileAlterationMonitor(interval, observer); monitor.start(); } } }
Example 10
Source File: ESConfigMonitor.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
public void init(ESAdapter esAdapter, Properties envProperties) { this.esAdapter = esAdapter; this.envProperties = envProperties; File confDir = Util.getConfDirPath(adapterName); try { FileAlterationObserver observer = new FileAlterationObserver(confDir, FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml"))); // 文件变化监听采用的common io的类库 FileListener listener = new FileListener(); observer.addListener(listener); fileMonitor = new FileAlterationMonitor(3000, observer); fileMonitor.start(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
Example 11
Source File: RdbConfigMonitor.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
public void init(String key, RdbAdapter rdbAdapter, Properties envProperties) { this.key = key; this.rdbAdapter = rdbAdapter; this.envProperties = envProperties; File confDir = Util.getConfDirPath(adapterName); try { FileAlterationObserver observer = new FileAlterationObserver(confDir, FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml"))); FileListener listener = new FileListener(); observer.addListener(listener); fileMonitor = new FileAlterationMonitor(3000, observer); fileMonitor.start(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
Example 12
Source File: ApplicationConfigMonitor.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
@PostConstruct public void init() { File confDir = Util.getConfDirPath(); try { FileAlterationObserver observer = new FileAlterationObserver(confDir, FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.prefixFileFilter("application"), FileFilterUtils.suffixFileFilter("yml"))); FileListener listener = new FileListener(); observer.addListener(listener); fileMonitor = new FileAlterationMonitor(3000, observer); fileMonitor.start(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
Example 13
Source File: DefaultScriptSource.java From util4j with Apache License 2.0 | 5 votes |
protected void init() throws Exception { FileAlterationObserver observer=buildFileAlterationObserver(scriptDir); observer.addListener(new FileListener()); FileAlterationMonitor monitor=new FileAlterationMonitor(updateInterval); monitor.addObserver(observer); monitor.start(); scanResources(); }
Example 14
Source File: Pipeline.java From wisdom with Apache License 2.0 | 5 votes |
/** * Starts the watching. * * @return the current pipeline. */ public Pipeline watch() { // Delete all error reports before starting the watcher. error = new File(baseDir, "target/pipeline"); FileUtils.deleteQuietly(error); mojo.getLog().debug("Creating the target/pipeline directory : " + error.mkdirs()); // Start the watching process. watcher = new FileAlterationMonitor(Integer.getInteger("watch.period", 2) * 1000); watcher.setThreadFactory(new DefensiveThreadFactory("wisdom-pipeline-watcher", mojo)); FileAlterationObserver srcObserver = new FileAlterationObserver(new File(baseDir, "src"), TrueFileFilter.INSTANCE); PipelineWatcher listener = new PipelineWatcher(this); srcObserver.addListener(listener); watcher.addObserver(srcObserver); if (pomFileMonitoring) { FileAlterationObserver pomObserver = new FileAlterationObserver(baseDir, new FileFilter() { @Override public boolean accept(File file) { return file.equals(new File(baseDir, "pom.xml")); } }); pomObserver.addListener(listener); watcher.addObserver(pomObserver); } try { mojo.getLog().info("Start watching " + baseDir.getAbsolutePath()); watcher.start(); } catch (Exception e) { mojo.getLog().error("Cannot start the watcher", e); } return this; }
Example 15
Source File: KuduConfigMonitor.java From canal with Apache License 2.0 | 5 votes |
public void init(KuduAdapter kuduAdapter, Properties envProperties) { this.kuduAdapter = kuduAdapter; this.envProperties = envProperties; File confDir = Util.getConfDirPath(adapterName); try { FileAlterationObserver observer = new FileAlterationObserver(confDir, FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml"))); FileListener listener = new FileListener(); observer.addListener(listener); fileMonitor = new FileAlterationMonitor(3000, observer); fileMonitor.start(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
Example 16
Source File: SensitiveWordMonitor.java From everyone-java-blog with Apache License 2.0 | 5 votes |
public void monitor(String directory, int interval) { FileAlterationObserver fileAlterationObserver = new FileAlterationObserver(directory, FileFilterUtils.and(FileFilterUtils.nameFileFilter(SENSITIVE_WORD_FILE_NAME)), null); fileAlterationObserver.addListener(this); FileAlterationMonitor fileAlterationMonitor = new FileAlterationMonitor(interval, fileAlterationObserver); try { fileAlterationMonitor.start(); } catch (Exception e) { e.printStackTrace(); } }
Example 17
Source File: DefaultTopologyService.java From knox with Apache License 2.0 | 4 votes |
private void initListener(String monitorName, FileAlterationMonitor monitor, File directory, FileFilter filter, FileAlterationListener listener) { monitors.put(monitorName, monitor); FileAlterationObserver observer = new FileAlterationObserver(directory, filter); observer.addListener(listener); monitor.addObserver(observer); }
Example 18
Source File: TemplateWatcher.java From roboconf-platform with Apache License 2.0 | 4 votes |
/** * Constructor. * @param manager the templating manager, to which event handling is delegated. * @param templateDir the templates directory to watch. * @param pollInterval the poll interval. * @throws IOException if there is a problem watching the template directory. */ public TemplateWatcher( final TemplatingManager manager, final File templateDir, final long pollInterval ) { this.templateDir = templateDir; // Register the custom helpers. this.handlebars.registerHelper( AllHelper.NAME, new AllHelper()); this.handlebars.registerHelper( IsKeyHelper.NAME, new IsKeyHelper()); // Pretty formatting this.handlebars.prettyPrint( true ); // Create the observer, register this object as the event listener. FileFilter fileFilter = FileFilterUtils.or( FileFilterUtils.and( FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter( ".tpl" ), CanReadFileFilter.CAN_READ, new TemplateFileFilter(templateDir)), FileFilterUtils.and( FileFilterUtils.directoryFileFilter(), CanReadFileFilter.CAN_READ, new TemplateSubDirectoryFileFilter(templateDir)) ); FileAlterationObserver observer = new FileAlterationObserver( this.templateDir, fileFilter ); observer.addListener( this ); // Create the monitor. this.monitor = new FileAlterationMonitor( pollInterval, observer ); this.monitor.setThreadFactory( THREAD_FACTORY ); this.manager = manager; this.logger.fine( "Template watcher is watching " + this.templateDir + " with an interval of " + pollInterval + " ms." ); }
Example 19
Source File: FileMonitorTest.java From spring-boot with Apache License 2.0 | 3 votes |
/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // 监控根目录,会递归监控子文件夹变化 String rootDir = "D:\\download"; // 轮询间隔 5 秒,通过重新启动 FileAlterationMonitor 实现 long interval = TimeUnit.SECONDS.toMillis(5); // 创建一个文件观察器用于处理文件的格式 // Create a FileFilter IOFileFilter directories = FileFilterUtils.and(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE); IOFileFilter files = FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter(".java")); IOFileFilter filter = FileFilterUtils.or(directories, files); // Create the File system observer and register File Listeners FileAlterationObserver observer = new FileAlterationObserver(rootDir, filter, null); observer.addListener(new FileMonitorFileListener()); //设置文件变化监听器 //创建文件变化监听器 FileAlterationMonitor monitor = new FileAlterationMonitor(interval, observer); // 开始监控 monitor.start(); }
Example 20
Source File: IncrementalBuilder.java From vertx-maven-plugin with Apache License 2.0 | 3 votes |
/** * Adds an observer listening for changes in the given path. * * @param path the path to observe */ private synchronized void buildObserver(Path path) { logger.info("Observing path:" + path.toString()); FileAlterationObserver observer = new FileAlterationObserver(path.toFile()); observer.addListener(this); observers.put(path, observer); this.monitor.addObserver(observer); }