improve logging after init

This commit is contained in:
Jörg Prante 2024-05-22 17:49:37 +02:00
parent df5741785a
commit bef220d188
4 changed files with 24 additions and 24 deletions

View file

@ -28,9 +28,9 @@ public class ClockEventManagerService extends AbstractEventManagerService implem
super(); super();
} }
@Override
public ClockEventManagerService init(EventManager eventManager) { public ClockEventManagerService init(EventManager eventManager) {
this.eventManager = eventManager; this.eventManager = eventManager;
Settings settings = eventManager.getSettings();
ThreadFactory threadFactory = new ThreadFactory() { ThreadFactory threadFactory = new ThreadFactory() {
int n = 1; int n = 1;
@Override @Override
@ -39,9 +39,9 @@ public class ClockEventManagerService extends AbstractEventManagerService implem
} }
}; };
ScheduledExecutorService scheduledExecutorService = ScheduledExecutorService scheduledExecutorService =
Executors.newScheduledThreadPool(settings.getAsInt("pool.size", 2), threadFactory); Executors.newScheduledThreadPool(eventManager.getSettings().getAsInt("pool.size", 2), threadFactory);
this.cronSchedule = new CronSchedule<>(scheduledExecutorService); this.cronSchedule = new CronSchedule<>(scheduledExecutorService);
for (Map.Entry<String, Settings> mapEntry : settings.getGroups("event.clock").entrySet()) { for (Map.Entry<String, Settings> mapEntry : eventManager.getSettings().getGroups("event.clock").entrySet()) {
String name = mapEntry.getKey(); String name = mapEntry.getKey();
Settings entrySettings = mapEntry.getValue(); Settings entrySettings = mapEntry.getValue();
if (entrySettings.getAsBoolean("enabled", true)) { 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.WARNING, "clock event service in configuration not enabled, name = " + name );
} }
} }
logger.log(Level.INFO, "entries = " + cronSchedule.getEntries());
cronSchedule.start(); cronSchedule.start();
logger.log(Level.INFO, "after init: entries = " + cronSchedule.getEntries());
return this; return this;
} }

View file

@ -24,19 +24,18 @@ public class FileFollowEventManagerService extends AbstractEventManagerService i
private EventManager eventManager; private EventManager eventManager;
private Map<Future<?>, FileFollowEventService> eventServiceMap; private final Map<Future<?>, FileFollowEventService> services;
public FileFollowEventManagerService() { public FileFollowEventManagerService() {
super(); super();
this.services = new LinkedHashMap<>();
} }
@Override @Override
public FileFollowEventManagerService init(EventManager eventManager) { public FileFollowEventManagerService init(EventManager eventManager) {
this.eventManager = eventManager; this.eventManager = eventManager;
Settings settings = eventManager.getSettings();
ExecutorService executorService = eventManager.getExecutorService(); ExecutorService executorService = eventManager.getExecutorService();
this.eventServiceMap = new LinkedHashMap<>(); for (Map.Entry<String, Settings> entry : eventManager.getSettings().getGroups("event.filefollow").entrySet()) {
for (Map.Entry<String, Settings> entry : settings.getGroups("event.filefollow").entrySet()) {
String name = entry.getKey(); String name = entry.getKey();
Settings definition = entry.getValue(); Settings definition = entry.getValue();
if (definition.getAsBoolean("enabled", true)) { if (definition.getAsBoolean("enabled", true)) {
@ -51,7 +50,7 @@ public class FileFollowEventManagerService extends AbstractEventManagerService i
FileFollowEventService fileFollowEventService = new FileFollowEventService(this, FileFollowEventService fileFollowEventService = new FileFollowEventService(this,
type, name, base, pattern); type, name, base, pattern);
Future<?> future = executorService.submit(fileFollowEventService); Future<?> future = executorService.submit(fileFollowEventService);
eventServiceMap.put(future, fileFollowEventService); services.put(future, fileFollowEventService);
logger.log(Level.INFO, "file follow service " + name + logger.log(Level.INFO, "file follow service " + name +
" with type " + type + " with type " + type +
" with base " + base + " and pattern " + pattern + " added"); " 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; return this;
} }
@Override @Override
public void shutdown() throws IOException { public void shutdown() throws IOException {
for (Map.Entry<Future<?>, FileFollowEventService> entry : eventServiceMap.entrySet()) { for (Map.Entry<Future<?>, FileFollowEventService> entry : services.entrySet()) {
try { try {
entry.getValue().setKeepWatching(false); entry.getValue().setKeepWatching(false);
entry.getKey().cancel(true); entry.getKey().cancel(true);

View file

@ -33,19 +33,18 @@ public class PathEventManagerService extends AbstractEventManagerService impleme
private ExecutorService executorService; private ExecutorService executorService;
private Map<Future<?>, PathEventService> eventServiceMap; private final Map<Future<?>, PathEventService> services;
public PathEventManagerService() { public PathEventManagerService() {
super(); super();
this.services = new LinkedHashMap<>();
} }
@Override @Override
public PathEventManagerService init(EventManager eventManager) { public PathEventManagerService init(EventManager eventManager) {
this.eventManager = eventManager; this.eventManager = eventManager;
Settings settings = eventManager.getSettings();
this.executorService = eventManager.getExecutorService(); this.executorService = eventManager.getExecutorService();
this.eventServiceMap = new LinkedHashMap<>(); for (Map.Entry<String, Settings> entry : eventManager.getSettings().getGroups("event.path").entrySet()) {
for (Map.Entry<String, Settings> entry : settings.getGroups("event.path").entrySet()) {
try { try {
String name = entry.getKey(); String name = entry.getKey();
Settings definition = entry.getValue(); 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.SEVERE, "unable to create event path service " + entry.getKey() + ", reason " + e.getMessage(), e);
} }
} }
logger.log(Level.INFO, "after init: event services = " + services);
return this; return this;
} }
@ -80,16 +80,16 @@ public class PathEventManagerService extends AbstractEventManagerService impleme
public void add(PathEventService pathEventService) { public void add(PathEventService pathEventService) {
Future<?> future = executorService.submit(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()); logger.log(Level.INFO, "path event service " + pathEventService + " added for path " + pathEventService.getPath());
} }
public Collection<PathEventService> getPathEventServices() { public Collection<PathEventService> getPathEventServices() {
return eventServiceMap.values(); return services.values();
} }
public PathEventService getPathEventService(String name) { 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) { public void publish(String eventType, Path path) {
@ -109,7 +109,7 @@ public class PathEventManagerService extends AbstractEventManagerService impleme
@Override @Override
public void shutdown() throws IOException { public void shutdown() throws IOException {
logger.log(Level.INFO, "shutting down all path event services"); logger.log(Level.INFO, "shutting down all path event services");
eventServiceMap.forEach((k, v) -> { services.forEach((k, v) -> {
k.cancel(true); k.cancel(true);
try { try {
v.close(); v.close();
@ -121,7 +121,7 @@ public class PathEventManagerService extends AbstractEventManagerService impleme
public void destroy() { public void destroy() {
logger.log(Level.INFO, "shutting down and destroying all path event files"); logger.log(Level.INFO, "shutting down and destroying all path event files");
eventServiceMap.forEach((k, v) -> { services.forEach((k, v) -> {
k.cancel(true); k.cancel(true);
try { try {
v.close(); v.close();
@ -165,7 +165,7 @@ public class PathEventManagerService extends AbstractEventManagerService impleme
writer.write(payload); writer.write(payload);
} }
// obligatory purge. This is hacky. // obligatory purge. This is hacky.
eventServiceMap.forEach((k, v) -> { services.forEach((k, v) -> {
try { try {
v.purge(); v.purge();
} catch (IOException e) { } catch (IOException e) {

View file

@ -27,18 +27,17 @@ public class TimerEventManagerService extends AbstractEventManagerService implem
private EventManager eventManager; private EventManager eventManager;
private Map<String, TimerEventService> services; private final Map<String, TimerEventService> services;
public TimerEventManagerService() { public TimerEventManagerService() {
super(); super();
this.services = new LinkedHashMap<>();
} }
@Override @Override
public TimerEventManagerService init(EventManager eventManager) { public TimerEventManagerService init(EventManager eventManager) {
this.eventManager = eventManager; this.eventManager = eventManager;
Settings settings = eventManager.getSettings(); for (Map.Entry<String, Settings> entry : eventManager.getSettings().getGroups("event.timer").entrySet()) {
this.services = new LinkedHashMap<>();
for (Map.Entry<String, Settings> entry : settings.getGroups("event.timer").entrySet()) {
String name = entry.getKey(); String name = entry.getKey();
Settings timerSettings = entry.getValue(); Settings timerSettings = entry.getValue();
try { 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.WARNING, "unable to activate timer " + name + ", reason: " + e.getMessage(), e);
} }
} }
logger.log(Level.INFO, "after init: event services = " + services);
return this; return this;
} }