Search in sources :

Example 6 with FileAlterationListenerAdaptor

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();
}
Also used : FileAlterationObserver(org.apache.commons.io.monitor.FileAlterationObserver) FileAlterationListenerAdaptor(org.apache.commons.io.monitor.FileAlterationListenerAdaptor) FileAlterationMonitor(org.apache.commons.io.monitor.FileAlterationMonitor) FileAlterationListener(org.apache.commons.io.monitor.FileAlterationListener) File(java.io.File)

Aggregations

File (java.io.File)6 FileAlterationListenerAdaptor (org.apache.commons.io.monitor.FileAlterationListenerAdaptor)6 FileAlterationMonitor (org.apache.commons.io.monitor.FileAlterationMonitor)6 FileAlterationObserver (org.apache.commons.io.monitor.FileAlterationObserver)6 FileAlterationListener (org.apache.commons.io.monitor.FileAlterationListener)4 IOException (java.io.IOException)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FileFilter (java.io.FileFilter)1 InputStream (java.io.InputStream)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1 FileUtils (org.apache.commons.io.FileUtils)1 BooleanUtils (org.apache.commons.lang3.BooleanUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Resource (org.apache.syncope.client.enduser.annotations.Resource)1 ClassPathScanImplementationLookup (org.apache.syncope.client.enduser.init.ClassPathScanImplementationLookup)1