use of org.apache.commons.jci.monitor.FilesystemAlterationMonitor in project sdc by onap.
the class ExternalConfiguration method listenForChanges.
public static void listenForChanges() {
String watchingDir = configDir + File.separator + appName;
if (enableReconfigure) {
if (fam == null) {
fam = new FilesystemAlterationMonitor();
fam.setInterval(1000);
fam.addListener(new File(watchingDir), changeListener);
fam.start();
}
}
}
use of org.apache.commons.jci.monitor.FilesystemAlterationMonitor in project struts by apache.
the class ClassReloadingXMLWebApplicationContext method setupReloading.
public void setupReloading(String[] watchList, String acceptClasses, ServletContext servletContext, boolean reloadConfig) {
this.reloadConfig = reloadConfig;
classLoader = new ReloadingClassLoader(ClassReloadingXMLWebApplicationContext.class.getClassLoader());
// make a list of accepted classes
if (StringUtils.isNotBlank(acceptClasses)) {
String[] splitted = acceptClasses.split(",");
Set<Pattern> patterns = new HashSet<>(splitted.length);
for (String pattern : splitted) patterns.add(Pattern.compile(pattern));
classLoader.setAccepClasses(patterns);
}
filesystemAlterationMonitor = new FilesystemAlterationMonitor();
// setup stores
for (String watch : watchList) {
File file = new File(watch);
// make it absolute, if it is a relative path
if (!file.isAbsolute())
file = new File(servletContext.getRealPath(watch));
if (watch.endsWith(".jar")) {
classLoader.addResourceStore(new JarResourceStore(file));
// register with the filesystemAlterationMonitor
filesystemAlterationMonitor.addListener(file, this);
LOG.debug("Watching [{}] for changes", file.getAbsolutePath());
} else {
// get all subdirs
List<File> dirs = new ArrayList<>();
getAllPaths(file, dirs);
classLoader.addResourceStore(new FileResourceStore(file));
for (File dir : dirs) {
// register with the filesystemAlterationMonitor
filesystemAlterationMonitor.addListener(dir, this);
LOG.debug("Watching [{}] for changes", dir.getAbsolutePath());
}
}
}
// setup the bean factory
beanFactory = new ClassReloadingBeanFactory();
beanFactory.setInstantiationStrategy(new ClassReloadingInstantiationStrategy());
beanFactory.setBeanClassLoader(classLoader);
// start watch thread
filesystemAlterationMonitor.start();
}
Aggregations