Search in sources :

Example 1 with OVERFLOW

use of java.nio.file.StandardWatchEventKinds.OVERFLOW in project JMRI by JMRI.

the class WebAppManager method lifeCycleStarted.

private void lifeCycleStarted(LifeCycle lc, Profile profile) {
    // register watcher to watch web/app directories everywhere
    if (this.watcher.get(profile) != null) {
        FileUtil.findFiles("web", ".").stream().filter((file) -> (file.isDirectory())).forEachOrdered((file) -> {
            try {
                Path path = file.toPath();
                WebAppManager.this.watchPaths.put(path.register(this.watcher.get(profile), StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY), path);
            } catch (IOException ex) {
                log.error("Unable to watch {} for changes.", file);
            }
            (new Thread() {

                @Override
                public void run() {
                    while (WebAppManager.this.watcher.get(profile) != null) {
                        WatchKey key;
                        try {
                            key = WebAppManager.this.watcher.get(profile).take();
                        } catch (InterruptedException ex) {
                            return;
                        }
                        key.pollEvents().stream().filter((event) -> (event.kind() != OVERFLOW)).forEachOrdered((event) -> {
                            WebAppManager.this.savePreferences(profile);
                        });
                        if (!key.reset()) {
                            WebAppManager.this.watcher.remove(profile);
                        }
                    }
                }
            }).start();
        });
    }
}
Also used : OVERFLOW(java.nio.file.StandardWatchEventKinds.OVERFLOW) LifeCycle(org.eclipse.jetty.util.component.LifeCycle) URL(java.net.URL) AbstractPreferencesManager(jmri.util.prefs.AbstractPreferencesManager) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) InitializationException(jmri.util.prefs.InitializationException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) AngularRoute(jmri.server.web.spi.AngularRoute) WatchKey(java.nio.file.WatchKey) HashSet(java.util.HashSet) WebServer(jmri.web.server.WebServer) StandardWatchEventKinds(java.nio.file.StandardWatchEventKinds) ProfileUtils(jmri.profile.ProfileUtils) Locale(java.util.Locale) Map(java.util.Map) Profile(jmri.profile.Profile) Path(java.nio.file.Path) PropertyChangeEvent(java.beans.PropertyChangeEvent) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ServiceLoader(java.util.ServiceLoader) WebMenuItem(jmri.server.web.spi.WebMenuItem) File(java.io.File) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) WatchService(java.nio.file.WatchService) List(java.util.List) WebManifest(jmri.server.web.spi.WebManifest) WebServerPreferences(jmri.web.server.WebServerPreferences) FileUtil(jmri.util.FileUtil) StringJoiner(java.util.StringJoiner) FileSystems(java.nio.file.FileSystems) Path(java.nio.file.Path) WatchKey(java.nio.file.WatchKey) IOException(java.io.IOException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 FileSystems (java.nio.file.FileSystems)1 Path (java.nio.file.Path)1 StandardWatchEventKinds (java.nio.file.StandardWatchEventKinds)1 OVERFLOW (java.nio.file.StandardWatchEventKinds.OVERFLOW)1 WatchKey (java.nio.file.WatchKey)1 WatchService (java.nio.file.WatchService)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1