use of org.apache.commons.io.monitor.FileAlterationListenerAdaptor in project serverless by bluenimble.
the class KeysMonitor method start.
public void start(final BlueNimble bluenimble) throws Exception {
File folder = BlueNimble.keysFolder();
FileAlterationObserver observer = new FileAlterationObserver(folder);
final FileAlterationMonitor monitor = new FileAlterationMonitor(pollingInterval);
FileAlterationListener listener = new FileAlterationListenerAdaptor() {
@Override
public void onFileCreate(File file) {
if (!file.isFile() || !file.getName().endsWith(CliSpec.KeysExt) || file.length() == 0) {
return;
}
try {
BlueNimble.loadKeys(bluenimble, file);
BlueNimble.useKeys(file.getName().substring(0, file.getName().lastIndexOf(Lang.DOT)));
} catch (Exception e) {
bluenimble.printer().error(e.getMessage());
}
}
@Override
public void onFileChange(File file) {
if (!file.isFile() || !file.getName().endsWith(CliSpec.KeysExt) || file.length() == 0) {
return;
}
try {
BlueNimble.loadKeys(bluenimble, file);
BlueNimble.useKeys(file.getName().substring(0, file.getName().lastIndexOf(Lang.DOT)));
} catch (Exception e) {
bluenimble.printer().error(e.getMessage());
}
}
};
observer.addListener(listener);
monitor.addObserver(observer);
new Thread() {
public void run() {
try {
monitor.start();
} catch (Exception e) {
}
}
}.start();
}
Aggregations