From bef220d188092e22dd96c06025f2a5d137ecc505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prante?= Date: Wed, 22 May 2024 17:49:37 +0200 Subject: [PATCH] improve logging after init --- .../event/clock/ClockEventManagerService.java | 8 ++++---- .../path/FileFollowEventManagerService.java | 12 +++++------ .../event/path/PathEventManagerService.java | 20 +++++++++---------- .../event/timer/TimerEventManagerService.java | 8 ++++---- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/event-common/src/main/java/org/xbib/event/clock/ClockEventManagerService.java b/event-common/src/main/java/org/xbib/event/clock/ClockEventManagerService.java index 5b3f6a2..9a40879 100644 --- a/event-common/src/main/java/org/xbib/event/clock/ClockEventManagerService.java +++ b/event-common/src/main/java/org/xbib/event/clock/ClockEventManagerService.java @@ -28,9 +28,9 @@ public class ClockEventManagerService extends AbstractEventManagerService implem super(); } + @Override public ClockEventManagerService init(EventManager eventManager) { this.eventManager = eventManager; - Settings settings = eventManager.getSettings(); ThreadFactory threadFactory = new ThreadFactory() { int n = 1; @Override @@ -39,9 +39,9 @@ public class ClockEventManagerService extends AbstractEventManagerService implem } }; ScheduledExecutorService scheduledExecutorService = - Executors.newScheduledThreadPool(settings.getAsInt("pool.size", 2), threadFactory); + Executors.newScheduledThreadPool(eventManager.getSettings().getAsInt("pool.size", 2), threadFactory); this.cronSchedule = new CronSchedule<>(scheduledExecutorService); - for (Map.Entry mapEntry : settings.getGroups("event.clock").entrySet()) { + for (Map.Entry mapEntry : eventManager.getSettings().getGroups("event.clock").entrySet()) { String name = mapEntry.getKey(); Settings entrySettings = mapEntry.getValue(); if (entrySettings.getAsBoolean("enabled", true)) { @@ -62,8 +62,8 @@ public class ClockEventManagerService extends AbstractEventManagerService implem logger.log(Level.WARNING, "clock event service in configuration not enabled, name = " + name ); } } - logger.log(Level.INFO, "entries = " + cronSchedule.getEntries()); cronSchedule.start(); + logger.log(Level.INFO, "after init: entries = " + cronSchedule.getEntries()); return this; } diff --git a/event-common/src/main/java/org/xbib/event/path/FileFollowEventManagerService.java b/event-common/src/main/java/org/xbib/event/path/FileFollowEventManagerService.java index 4045ef2..bd84027 100644 --- a/event-common/src/main/java/org/xbib/event/path/FileFollowEventManagerService.java +++ b/event-common/src/main/java/org/xbib/event/path/FileFollowEventManagerService.java @@ -24,19 +24,18 @@ public class FileFollowEventManagerService extends AbstractEventManagerService i private EventManager eventManager; - private Map, FileFollowEventService> eventServiceMap; + private final Map, FileFollowEventService> services; public FileFollowEventManagerService() { super(); + this.services = new LinkedHashMap<>(); } @Override public FileFollowEventManagerService init(EventManager eventManager) { this.eventManager = eventManager; - Settings settings = eventManager.getSettings(); ExecutorService executorService = eventManager.getExecutorService(); - this.eventServiceMap = new LinkedHashMap<>(); - for (Map.Entry entry : settings.getGroups("event.filefollow").entrySet()) { + for (Map.Entry entry : eventManager.getSettings().getGroups("event.filefollow").entrySet()) { String name = entry.getKey(); Settings definition = entry.getValue(); if (definition.getAsBoolean("enabled", true)) { @@ -51,7 +50,7 @@ public class FileFollowEventManagerService extends AbstractEventManagerService i FileFollowEventService fileFollowEventService = new FileFollowEventService(this, type, name, base, pattern); Future future = executorService.submit(fileFollowEventService); - eventServiceMap.put(future, fileFollowEventService); + services.put(future, fileFollowEventService); logger.log(Level.INFO, "file follow service " + name + " with type " + type + " with base " + base + " and pattern " + pattern + " added"); @@ -60,12 +59,13 @@ public class FileFollowEventManagerService extends AbstractEventManagerService i } } } + logger.log(Level.INFO, "after init: event services = " + services); return this; } @Override public void shutdown() throws IOException { - for (Map.Entry, FileFollowEventService> entry : eventServiceMap.entrySet()) { + for (Map.Entry, FileFollowEventService> entry : services.entrySet()) { try { entry.getValue().setKeepWatching(false); entry.getKey().cancel(true); diff --git a/event-common/src/main/java/org/xbib/event/path/PathEventManagerService.java b/event-common/src/main/java/org/xbib/event/path/PathEventManagerService.java index 3b72ffa..81ff10f 100644 --- a/event-common/src/main/java/org/xbib/event/path/PathEventManagerService.java +++ b/event-common/src/main/java/org/xbib/event/path/PathEventManagerService.java @@ -33,19 +33,18 @@ public class PathEventManagerService extends AbstractEventManagerService impleme private ExecutorService executorService; - private Map, PathEventService> eventServiceMap; + private final Map, PathEventService> services; public PathEventManagerService() { super(); + this.services = new LinkedHashMap<>(); } @Override public PathEventManagerService init(EventManager eventManager) { this.eventManager = eventManager; - Settings settings = eventManager.getSettings(); this.executorService = eventManager.getExecutorService(); - this.eventServiceMap = new LinkedHashMap<>(); - for (Map.Entry entry : settings.getGroups("event.path").entrySet()) { + for (Map.Entry entry : eventManager.getSettings().getGroups("event.path").entrySet()) { try { String name = entry.getKey(); Settings definition = entry.getValue(); @@ -65,6 +64,7 @@ public class PathEventManagerService extends AbstractEventManagerService impleme logger.log(Level.SEVERE, "unable to create event path service " + entry.getKey() + ", reason " + e.getMessage(), e); } } + logger.log(Level.INFO, "after init: event services = " + services); return this; } @@ -80,16 +80,16 @@ public class PathEventManagerService extends AbstractEventManagerService impleme public void add(PathEventService pathEventService) { Future future = executorService.submit(pathEventService); - eventServiceMap.put(future, pathEventService); + services.put(future, pathEventService); logger.log(Level.INFO, "path event service " + pathEventService + " added for path " + pathEventService.getPath()); } public Collection getPathEventServices() { - return eventServiceMap.values(); + return services.values(); } public PathEventService getPathEventService(String name) { - return eventServiceMap.values().stream().filter(p -> p.getName().equals(name)).findFirst().orElse(null); + return services.values().stream().filter(p -> p.getName().equals(name)).findFirst().orElse(null); } public void publish(String eventType, Path path) { @@ -109,7 +109,7 @@ public class PathEventManagerService extends AbstractEventManagerService impleme @Override public void shutdown() throws IOException { logger.log(Level.INFO, "shutting down all path event services"); - eventServiceMap.forEach((k, v) -> { + services.forEach((k, v) -> { k.cancel(true); try { v.close(); @@ -121,7 +121,7 @@ public class PathEventManagerService extends AbstractEventManagerService impleme public void destroy() { logger.log(Level.INFO, "shutting down and destroying all path event files"); - eventServiceMap.forEach((k, v) -> { + services.forEach((k, v) -> { k.cancel(true); try { v.close(); @@ -165,7 +165,7 @@ public class PathEventManagerService extends AbstractEventManagerService impleme writer.write(payload); } // obligatory purge. This is hacky. - eventServiceMap.forEach((k, v) -> { + services.forEach((k, v) -> { try { v.purge(); } catch (IOException e) { diff --git a/event-common/src/main/java/org/xbib/event/timer/TimerEventManagerService.java b/event-common/src/main/java/org/xbib/event/timer/TimerEventManagerService.java index 9318af3..1bf0719 100644 --- a/event-common/src/main/java/org/xbib/event/timer/TimerEventManagerService.java +++ b/event-common/src/main/java/org/xbib/event/timer/TimerEventManagerService.java @@ -27,18 +27,17 @@ public class TimerEventManagerService extends AbstractEventManagerService implem private EventManager eventManager; - private Map services; + private final Map services; public TimerEventManagerService() { super(); + this.services = new LinkedHashMap<>(); } @Override public TimerEventManagerService init(EventManager eventManager) { this.eventManager = eventManager; - Settings settings = eventManager.getSettings(); - this.services = new LinkedHashMap<>(); - for (Map.Entry entry : settings.getGroups("event.timer").entrySet()) { + for (Map.Entry entry : eventManager.getSettings().getGroups("event.timer").entrySet()) { String name = entry.getKey(); Settings timerSettings = entry.getValue(); try { @@ -50,6 +49,7 @@ public class TimerEventManagerService extends AbstractEventManagerService implem logger.log(Level.WARNING, "unable to activate timer " + name + ", reason: " + e.getMessage(), e); } } + logger.log(Level.INFO, "after init: event services = " + services); return this; }