From 12fd2eee903dcfca18a81433ae88ef49e2b8ea21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prante?= Date: Thu, 26 Oct 2023 10:57:44 +0200 Subject: [PATCH] add enabled switch --- .../event/io/file/FileFollowEventManager.java | 23 +++++++++++-------- .../xbib/event/io/path/PathEventManager.java | 22 ++++++++++-------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/xbib/event/io/file/FileFollowEventManager.java b/src/main/java/org/xbib/event/io/file/FileFollowEventManager.java index 221bf65..9b25962 100644 --- a/src/main/java/org/xbib/event/io/file/FileFollowEventManager.java +++ b/src/main/java/org/xbib/event/io/file/FileFollowEventManager.java @@ -7,6 +7,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.logging.Level; @@ -25,22 +26,24 @@ public class FileFollowEventManager { ExecutorService executorService, ClassLoader classLoader) { this.eventServiceMap = new LinkedHashMap<>(); - for (Map.Entry followfiles : settings.getGroups("event.filefollow").entrySet()) { - Settings definition = followfiles.getValue(); - String baseStr = definition.get("base"); - String patternStr = definition.get("pattern"); - if (baseStr != null && patternStr != null) { - Path base = Paths.get(baseStr); - Pattern pattern = Pattern.compile(patternStr); - String className = definition.get("class", DefaultFileFollowEvent.class.getName()); + for (Map.Entry entry : settings.getGroups("event.filefollow").entrySet()) { + Settings definition = entry.getValue(); + if (definition.getAsBoolean("enabled", true)) { + String baseStr = definition.get("base"); + Objects.requireNonNull(baseStr); + String patternStr = definition.get("pattern"); + Objects.requireNonNull(patternStr); try { + Path base = Paths.get(baseStr); + Pattern pattern = Pattern.compile(patternStr); + String className = definition.get("class", DefaultFileFollowEvent.class.getName()); Class eventClass = (Class) classLoader.loadClass(className); FileFollowEventService fileFollowEventService = new FileFollowEventService(definition, eventBus, base, pattern, eventClass); Future future = executorService.submit(fileFollowEventService); eventServiceMap.put(future, fileFollowEventService); - logger.log(Level.INFO, "file follow service " + followfiles.getKey() + " with base " + base + " and pattern " + pattern + " added, event class " + className); + logger.log(Level.INFO, "file follow service " + entry.getKey() + " with base " + base + " and pattern " + pattern + " added, event class " + className); } catch (Exception e) { - logger.log(Level.SEVERE, "unable to create file follow service " + followfiles.getKey() + ", reason " + e.getMessage(), e); + logger.log(Level.SEVERE, "unable to create file follow service " + entry.getKey() + ", reason " + e.getMessage(), e); } } } diff --git a/src/main/java/org/xbib/event/io/path/PathEventManager.java b/src/main/java/org/xbib/event/io/path/PathEventManager.java index 76e829e..6c754c0 100644 --- a/src/main/java/org/xbib/event/io/path/PathEventManager.java +++ b/src/main/java/org/xbib/event/io/path/PathEventManager.java @@ -40,16 +40,18 @@ public class PathEventManager implements Closeable { try { String name = entry.getKey(); Settings definition = entry.getValue(); - int maxBytes = definition.getAsInt("maxfilesize", 10 * 1024 * 1024); // 10 MB - TimeValue lifetime = definition.getAsTime("lifetime", TimeValue.timeValueHours(72)); - String className = definition.get("class", DefaultPathEvent.class.getName()); - Class eventClass = (Class) classLoader.loadClass(className); - Path p = path.resolve(name); - createQueue(name, p); - PathEventService pathEventService = new PathEventService(eventBus, name, p, maxBytes, lifetime, eventClass); - Future future = executorService.submit(pathEventService); - eventServiceMap.put(future, pathEventService); - logger.log(Level.INFO, "path event service " + entry.getKey() + " with path " + p + " and max " + maxBytes + " added, event class " + className); + if (definition.getAsBoolean("enabled", true)) { + int maxBytes = definition.getAsInt("maxfilesize", 10 * 1024 * 1024); // 10 MB + TimeValue lifetime = definition.getAsTime("lifetime", TimeValue.timeValueHours(72)); + String className = definition.get("class", DefaultPathEvent.class.getName()); + Class eventClass = (Class) classLoader.loadClass(className); + Path p = path.resolve(name); + createQueue(name, p); + PathEventService pathEventService = new PathEventService(eventBus, name, p, maxBytes, lifetime, eventClass); + Future future = executorService.submit(pathEventService); + eventServiceMap.put(future, pathEventService); + logger.log(Level.INFO, "path event service " + entry.getKey() + " with path " + p + " and max " + maxBytes + " added, event class " + className); + } } catch (Exception e) { logger.log(Level.SEVERE, "unable to create event path service " + entry.getKey() + ", reason " + e.getMessage(), e); }