Example usage for org.apache.commons.vfs.impl DefaultFileMonitor start

List of usage examples for org.apache.commons.vfs.impl DefaultFileMonitor start

Introduction

In this page you can find the example usage for org.apache.commons.vfs.impl DefaultFileMonitor start.

Prototype

public void start() 

Source Link

Document

Starts monitoring the files that have been added.

Usage

From source file:com.sonatype.nexus.plugin.groovyconsole.DefaultScriptStorage.java

public void initialize() throws InitializationException {
    scripts = new LinkedHashMap<String, String>();

    FileObject listendir;/*from  w ww .java  2 s.  co m*/
    try {
        FileSystemManager fsManager = VFS.getManager();
        scriptDir = applicationConfiguration.getWorkingDirectory("scripts");
        if (!scriptDir.exists()) {
            scriptDir.mkdirs();

            try {
                new File(scriptDir, "place your .groovy files here.txt").createNewFile();
            } catch (IOException e) {
                throw new InitializationException(e.getMessage(), e);
            }
        }

        listendir = fsManager.resolveFile(scriptDir.getAbsolutePath());
    } catch (FileSystemException e) {
        throw new InitializationException(e.getMessage(), e);
    }

    FileSelector selector = new FileSelector() {
        public boolean traverseDescendents(FileSelectInfo arg0) throws Exception {
            return true;
        }

        public boolean includeFile(FileSelectInfo arg0) throws Exception {
            return isScriptFile(arg0.getFile());
        }
    };

    try {
        FileObject[] availableScripts = listendir.findFiles(selector);
        for (FileObject fileObject : availableScripts) {
            updateScript(fileObject);
        }
    } catch (FileSystemException e) {
        getLogger().warn("Unable to perform initial directory scan.", e);
    }

    DefaultFileMonitor fm = new DefaultFileMonitor(this);
    fm.setRecursive(true);
    fm.addFile(listendir);
    fm.start();

    this.fileMonitor = fm;
}

From source file:org.innobuilt.fincayra.FincayraApplication.java

public void watch(String fileName) {
    if (this.getReloadRootScope()) {

        LOGGER.info("Adding file to root scope watch: {}", fileName);
        try {/*  w  w w. ja v a 2s . co  m*/
            FileSystemManager fsManager = VFS.getManager();
            FileObject listendir = fsManager.resolveFile(fileName);

            DefaultFileMonitor fm = new DefaultFileMonitor(new FincayraFileListener());
            fm.setRecursive(true);
            fm.addFile(listendir);
            fm.start();
        } catch (FileSystemException e) {
            LOGGER.error("Unable to watch directory: {}", fileName);
        }
    }
}