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.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<String, Settings> followfiles : settings.getGroups("event.filefollow").entrySet()) {
Settings definition = followfiles.getValue();
for (Map.Entry<String, Settings> 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");
if (baseStr != null && patternStr != null) {
Objects.requireNonNull(patternStr);
try {
Path base = Paths.get(baseStr);
Pattern pattern = Pattern.compile(patternStr);
String className = definition.get("class", DefaultFileFollowEvent.class.getName());
try {
Class<? extends FileFollowEvent> eventClass = (Class<? extends FileFollowEvent>) 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);
}
}
}

View file

@ -40,6 +40,7 @@ public class PathEventManager implements Closeable {
try {
String name = entry.getKey();
Settings definition = entry.getValue();
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());
@ -50,6 +51,7 @@ public class PathEventManager implements Closeable {
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);
}