use of org.apache.commons.vfs2.impl.DefaultFileMonitor in project motech by motech.
the class ConfigFileMonitor method init.
/**
* Initializes the configuration file monitor. This method will be automatically called after creation and
* dependency injection. It is done to make sure that injected dependencies are set and ready to use.
*/
@PostConstruct
public void init() throws IOException {
BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig();
if (bootstrapConfig != null && bootstrapConfig.getConfigSource() == ConfigSource.FILE) {
// allow custom monitors to be injected
if (fileMonitor == null) {
fileMonitor = new DefaultFileMonitor(this);
// allow raw configs, which are one directory down, under /raw/, to be monitored
fileMonitor.setRecursive(true);
}
fileMonitor.setDelay(DELAY);
final List<File> files = new ArrayList<>();
try {
files.addAll(configLoader.findExistingConfigs());
} catch (MotechConfigurationException ex) {
LOGGER.error(ex.getMessage(), ex);
return;
}
configurationService.processExistingConfigs(files);
startFileMonitor();
}
}
use of org.apache.commons.vfs2.impl.DefaultFileMonitor in project accumulo by apache.
the class VfsClassLoaderTest method testFileMonitor.
@Test
public void testFileMonitor() throws Exception {
MyFileMonitor listener = new MyFileMonitor();
DefaultFileMonitor monitor = new DefaultFileMonitor(listener);
monitor.setRecursive(true);
FileObject testDir = vfs.resolveFile(TEST_DIR.toUri().toString());
monitor.addFile(testDir);
monitor.start();
// Copy jar file to a new file name
URL jarPath = this.getClass().getResource("/HelloWorld.jar");
Path src = new Path(jarPath.toURI().toString());
Path dst = new Path(TEST_DIR, "HelloWorld2.jar");
this.hdfs.copyFromLocalFile(src, dst);
// VFS-487 significantly wait to avoid failure
Thread.sleep(7000);
Assert.assertTrue(listener.isFileCreated());
// Update the jar
jarPath = this.getClass().getResource("/HelloWorld.jar");
src = new Path(jarPath.toURI().toString());
dst = new Path(TEST_DIR, "HelloWorld2.jar");
this.hdfs.copyFromLocalFile(src, dst);
// VFS-487 significantly wait to avoid failure
Thread.sleep(7000);
Assert.assertTrue(listener.isFileChanged());
this.hdfs.delete(dst, false);
// VFS-487 significantly wait to avoid failure
Thread.sleep(7000);
Assert.assertTrue(listener.isFileDeleted());
monitor.stop();
}
Aggregations