当前位置: 首页>>代码示例>>Java>>正文


Java FileAlterationObserver.addListener方法代码示例

本文整理汇总了Java中org.apache.commons.io.monitor.FileAlterationObserver.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java FileAlterationObserver.addListener方法的具体用法?Java FileAlterationObserver.addListener怎么用?Java FileAlterationObserver.addListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.io.monitor.FileAlterationObserver的用法示例。


在下文中一共展示了FileAlterationObserver.addListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addFileAlterationObserver

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
/**
 * Add {@link org.apache.commons.io.monitor.FileAlterationMonitor}s for the given
 * root directory and any nested subdirectories under the root directory to the given
 * {@link org.apache.commons.io.monitor.FileAlterationMonitor}.
 *
 * @param monitor a {@link org.apache.commons.io.monitor.FileAlterationMonitor}
 * @param listener a {@link org.apache.commons.io.monitor.FileAlterationListener}
 * @param rootDir root directory
 */
public static void addFileAlterationObserver(FileAlterationMonitor monitor, FileAlterationListener listener,
    File rootDir) {
  // Add a observer for the current root directory
  FileAlterationObserver observer = new FileAlterationObserver(rootDir);
  observer.addListener(listener);
  monitor.addObserver(observer);

  // List subdirectories under the current root directory
  File[] subDirs = rootDir.listFiles(new FileFilter() {
    @Override
    public boolean accept(File file) {
      return file.isDirectory();
    }
  });

  if (subDirs == null || subDirs.length == 0) {
    return;
  }

  // Recursively add a observer for each subdirectory
  for (File subDir : subDirs) {
    addFileAlterationObserver(monitor, listener, subDir);
  }
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:34,代码来源:SchedulerUtils.java

示例2: registerDirectory

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
@Override
public synchronized void registerDirectory(final Path directory, final FileSystemListener listener) throws IOException {
    log.debug("Registering " + directory);

    final FileAlterationObserver observer = new FileAlterationObserver(directory.toFile(), this.fileNameFilter);
    try {
        // Force the registered directory to be read into memory before we start observing changes,
        // otherwise the first run will generate a 'create' event for each file and directory.
        observer.initialize();
    } catch (Exception e) {
        throw new IOException("Failed to initialize observer for " + directory, e);
    }
    observer.addListener(this);
    listeners.put(directory, listener);
    monitor.addObserver(observer);
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:17,代码来源:FileSystemPoller.java

示例3: check1

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
/**
 * 只监控文件发送变化,如果是子目录的文件改变,则目录会变,由于没有过滤目录发生变化,则目录下的文件改变不会监控到
 * @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();
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:21,代码来源:FileMonitor.java

示例4: check2

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
public void check2(String dir) throws Exception
	{
		File directory = new File(dir);
	    // 轮询间隔 5 秒
	    long interval = TimeUnit.SECONDS.toMillis(5);
	    //后缀过滤器
	    IOFileFilter filefilter=FileFilterUtils.or(FileFilterUtils.suffixFileFilter(".class"),
	    		FileFilterUtils.suffixFileFilter(".jar"));
	    //子目录的后缀
	    IOFileFilter subFilefilter=FileFilterUtils.or(FileFilterUtils.directoryFileFilter(),filefilter);
	    //根目录和子目录变化
	    IOFileFilter filter = FileFilterUtils.or(filefilter,subFilefilter);
	    FileAlterationObserver observer = new FileAlterationObserver(directory,filter);
	    //设置文件变化监听器
	    observer.addListener(new MyFileListener());
	    FileAlterationMonitor monitor = new FileAlterationMonitor(interval);
	    monitor.addObserver(observer);//文件观察
	    monitor.start();
//	    monitor.addObserver(observer);//文件观察,如果在start后面加,则会触发所有文件创建
	}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:21,代码来源:FileMonitor.java

示例5: registerFileListener

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
/**
 * Creates and registers a file listener with the help of the specified build command.
 * 
 * @param command The build command.
 * 
 * @throws Exception If any exception occurs.
 */

private final void registerFileListener(final BuildCommand command) throws Exception {
	final DocsProject project = command.getProject();
	
	final FileAlterationObserver observer = new FileAlterationObserver(project.getDirectory());
	observer.addListener(new FileAlterationListenerAdaptor() {
		
		@Override
		public final void onDirectoryChange(final File directory) {
			rebuildIfNeeded(command, directory);
		}
		
		@Override
		public final void onFileChange(final File file) {
			rebuildIfNeeded(command, file);
		}
		
	});
	monitor.addObserver(observer);
	monitor.start();
}
 
开发者ID:Skyost,项目名称:SkyDocs,代码行数:29,代码来源:ServeCommand.java

示例6: azkabanConfigFileMonitor

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
public static void azkabanConfigFileMonitor(String[] args, Props props1) {
    try {
        props = props1;
        configFilePath = props.getString(AZKABAN_CONFIG_FILE_PATH);//配置文件路径
        long interval = props.getLong(AZKABAN_CONFIG_FILE_MONIITE_INTERVAL, 5000);//监听间隔
        String dirPath = System.getProperty("user.dir") + configFilePath;
        logger.error("azkabanConfigFileMonitor method, monitor path= " + dirPath);
        //构造观察类:主要提供要观察的文件或目录,当然还有详细信息的filter
        FileAlterationObserver observer = new FileAlterationObserver(new File(dirPath), new FileFilterImpl());
        //构造收听类
        FileListenerAdaptor listener = new FileListenerAdaptor(args);
        //为观察对象添加收听对象
        observer.addListener(listener);
        //配置Monitor,第一个参数单位是毫秒,是监听的间隔;第二个参数就是绑定我们之前的观察对象。
        FileAlterationMonitor fileMonitor = new FileAlterationMonitor(interval, new FileAlterationObserver[]{observer});
        //启动开始监听
        fileMonitor.start();
    } catch (Exception e) {
        logger.error("azkabanConfigFileMonitor method error", e);
    }

}
 
开发者ID:JasonBian,项目名称:azkaban,代码行数:23,代码来源:AzkabanConfigFileMonitor.java

示例7: start

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:Exslims,项目名称:MercuryTrade,代码行数:23,代码来源:FileMonitor.java

示例8: activate

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
public synchronized void activate() throws MojoExecutionException
{   
  IOFileFilter logFilter = FileFilterUtils.and(
          FileFilterUtils.fileFileFilter(),
          FileFilterUtils.nameFileFilter(engineLog.getName()));
  FileAlterationObserver fileObserver = new FileAlterationObserver(engineLog.getParent(), logFilter);
  fileObserver.addListener(new LogModificationListener());
  monitor = new FileAlterationMonitor(100);
  monitor.addObserver(fileObserver);
  try
  {
    monitor.start();
  }
  catch (Exception ex)
  {
    throw new MojoExecutionException("Failed to activate deploy log forwarder", ex);
  }
}
 
开发者ID:axonivy,项目名称:project-build-plugin,代码行数:19,代码来源:FileLogForwarder.java

示例9: OpenCmsConfiguration

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
/**
 * Creates a new OpenCmsConfiguration instance, prepares the XML helper for parsing configuration files, starts
 * a FileAlterationObserver used to handle changes to configuration files.
 * @param config the project level plugin configuration data
 */
public OpenCmsConfiguration(OpenCmsPluginConfigurationData config) {
	this.config = config;

	File configurationFolder = new File(config.getWebappRoot() + CONFIGPATH);
	this.moduleConfigurationFile = new File(config.getWebappRoot() + CONFIGPATH + MODULECONFIGFILE);

	// Create an Observer for configuration changes
	FileAlterationObserver configurationChangeObserver = new FileAlterationObserver(configurationFolder);
	configurationChangeObserver.addListener(new ConfigurationAlterationListener());
	configurationChangeMonitor = new FileAlterationMonitor(5000, configurationChangeObserver);

	try {
		xmlHelper = new XmlHelper();
	}
	catch (Exception e) {
		LOG.warn("Exception during initialization of the module configuration: " + e);
	}

	parseConfiguration();
}
 
开发者ID:mediaworx,项目名称:opencms-intellijplugin,代码行数:26,代码来源:OpenCmsConfiguration.java

示例10: DirectoryMonitor

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
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);

    }
 
开发者ID:ow2-chameleon,项目名称:fuchsia,代码行数:21,代码来源:DirectoryMonitor.java

示例11: addMonitor

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
/**
 * 增加监视器
 *
 * @param path     监听的文件夹路径
 * @param listener 事件回调接口
 * @return 监听器的id
 * @throws JNotifyException {@link JNotifyException}
 */
public static int addMonitor(String path, FileAlterationListener listener) throws JNotifyException {
    File file = new File(path);
    FileAlterationObserver observer = new FileAlterationObserver(file);
    observer.checkAndNotify();
    observer.addListener(listener);
    int mask = JNotify.FILE_CREATED | JNotify.FILE_DELETED
            | JNotify.FILE_MODIFIED;
    return JNotify.addWatch(path, mask, false, new FileEventListener(observer));
}
 
开发者ID:baidu,项目名称:openrasp,代码行数:18,代码来源:FileScanMonitor.java

示例12: monitorDir

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
/**
 * 监视目录
 * @param directory
 * @param filter
 * @throws Exception 
 */
protected void monitorDir(String directory,IOFileFilter filter) throws Exception
{
	FileAlterationObserver observer=new FileAlterationObserver(directory,filter);
	observer.initialize();
	observer.addListener(fileListener);
	observers.add(observer);
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:14,代码来源:DefaultClassSource.java

示例13: init

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
protected void init() throws Exception
{
	FileAlterationObserver observer=buildFileAlterationObserver(scriptDir);
	observer.addListener(new FileListener());
	FileAlterationMonitor monitor=new FileAlterationMonitor(updateInterval);
	monitor.addObserver(observer);
	monitor.start();
	scanResources();
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:10,代码来源:DefaultScriptSource.java

示例14: monitor

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:xiaolongzuo,项目名称:everyone-java-blog,代码行数:12,代码来源:SensitiveWordMonitor.java

示例15: monitorCollection

import org.apache.commons.io.monitor.FileAlterationObserver; //导入方法依赖的package包/类
/**

@method monitorCollection
*/
   private FileAlterationMonitor monitorCollection (String collection) throws Exception {
   	// prtln ("monitorCollection() - " + collection);
   	
   	AssetCollection assetCollection = this.getCollection(collection);
   	
       if (assetCollection == null) {
           // Test to see if monitored folder exists
           throw new RuntimeException("AssetCollection not found: " + collection);
       }
       
       File folder = assetCollection.getDirectory();
       if (!folder.exists())
       	throw new RuntimeException("Folder not found at: " + folder);

       FileAlterationObserver observer = new FileAlterationObserver(folder);
       FileAlterationMonitor monitor =
               new FileAlterationMonitor(pollingInterval);
               
	FileAlterationListener listener = new AssetFileListener(collection, this);

       observer.addListener(listener);
       monitor.addObserver(observer);
       monitor.start();
       // prtln (" .. monitoring " + collection);
       return monitor;
   }
 
开发者ID:NCAR,项目名称:dls-repository-stack,代码行数:31,代码来源:AssetFileManager.java


注:本文中的org.apache.commons.io.monitor.FileAlterationObserver.addListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。