add enabled switch

This commit is contained in:
Jörg Prante 2023-10-26 10:57:44 +02:00
parent 3792b31fc7
commit 12fd2eee90
2 changed files with 25 additions and 20 deletions

View file

@ -7,6 +7,7 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.logging.Level; import java.util.logging.Level;
@ -25,22 +26,24 @@ public class FileFollowEventManager {
ExecutorService executorService, ExecutorService executorService,
ClassLoader classLoader) { ClassLoader classLoader) {
this.eventServiceMap = new LinkedHashMap<>(); this.eventServiceMap = new LinkedHashMap<>();
for (Map.Entry<String, Settings> followfiles : settings.getGroups("event.filefollow").entrySet()) { for (Map.Entry<String, Settings> entry : settings.getGroups("event.filefollow").entrySet()) {
Settings definition = followfiles.getValue(); Settings definition = entry.getValue();
String baseStr = definition.get("base"); if (definition.getAsBoolean("enabled", true)) {
String patternStr = definition.get("pattern"); String baseStr = definition.get("base");
if (baseStr != null && patternStr != null) { Objects.requireNonNull(baseStr);
Path base = Paths.get(baseStr); String patternStr = definition.get("pattern");
Pattern pattern = Pattern.compile(patternStr); Objects.requireNonNull(patternStr);
String className = definition.get("class", DefaultFileFollowEvent.class.getName());
try { try {
Path base = Paths.get(baseStr);
Pattern pattern = Pattern.compile(patternStr);
String className = definition.get("class", DefaultFileFollowEvent.class.getName());
Class<? extends FileFollowEvent> eventClass = (Class<? extends FileFollowEvent>) classLoader.loadClass(className); Class<? extends FileFollowEvent> eventClass = (Class<? extends FileFollowEvent>) classLoader.loadClass(className);
FileFollowEventService fileFollowEventService = new FileFollowEventService(definition, eventBus, base, pattern, eventClass); FileFollowEventService fileFollowEventService = new FileFollowEventService(definition, eventBus, base, pattern, eventClass);
Future<?> future = executorService.submit(fileFollowEventService); Future<?> future = executorService.submit(fileFollowEventService);
eventServiceMap.put(future, 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) { } 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);
} }
} }
} }

View file

@ -40,16 +40,18 @@ public class PathEventManager implements Closeable {
try { try {
String name = entry.getKey(); String name = entry.getKey();
Settings definition = entry.getValue(); Settings definition = entry.getValue();
int maxBytes = definition.getAsInt("maxfilesize", 10 * 1024 * 1024); // 10 MB if (definition.getAsBoolean("enabled", true)) {
TimeValue lifetime = definition.getAsTime("lifetime", TimeValue.timeValueHours(72)); int maxBytes = definition.getAsInt("maxfilesize", 10 * 1024 * 1024); // 10 MB
String className = definition.get("class", DefaultPathEvent.class.getName()); TimeValue lifetime = definition.getAsTime("lifetime", TimeValue.timeValueHours(72));
Class<? extends PathEvent> eventClass = (Class<? extends PathEvent>) classLoader.loadClass(className); String className = definition.get("class", DefaultPathEvent.class.getName());
Path p = path.resolve(name); Class<? extends PathEvent> eventClass = (Class<? extends PathEvent>) classLoader.loadClass(className);
createQueue(name, p); Path p = path.resolve(name);
PathEventService pathEventService = new PathEventService(eventBus, name, p, maxBytes, lifetime, eventClass); createQueue(name, p);
Future<?> future = executorService.submit(pathEventService); PathEventService pathEventService = new PathEventService(eventBus, name, p, maxBytes, lifetime, eventClass);
eventServiceMap.put(future, pathEventService); Future<?> future = executorService.submit(pathEventService);
logger.log(Level.INFO, "path event service " + entry.getKey() + " with path " + p + " and max " + maxBytes + " added, event class " + className); 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) { } catch (Exception e) {
logger.log(Level.SEVERE, "unable to create event path service " + entry.getKey() + ", reason " + e.getMessage(), e); logger.log(Level.SEVERE, "unable to create event path service " + entry.getKey() + ", reason " + e.getMessage(), e);
} }