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();
}
@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<String, Settings> mapEntry : settings.getGroups("event.clock").entrySet()) {
for (Map.Entry<String, Settings> 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;
}

View file

@ -24,19 +24,18 @@ public class FileFollowEventManagerService extends AbstractEventManagerService i
private EventManager eventManager;
private Map<Future<?>, FileFollowEventService> eventServiceMap;
private final Map<Future<?>, 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<String, Settings> entry : settings.getGroups("event.filefollow").entrySet()) {
for (Map.Entry<String, Settings> 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<Future<?>, FileFollowEventService> entry : eventServiceMap.entrySet()) {
for (Map.Entry<Future<?>, FileFollowEventService> entry : services.entrySet()) {
try {
entry.getValue().setKeepWatching(false);
entry.getKey().cancel(true);

View file

@ -33,19 +33,18 @@ public class PathEventManagerService extends AbstractEventManagerService impleme
private ExecutorService executorService;
private Map<Future<?>, PathEventService> eventServiceMap;
private final Map<Future<?>, 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<String, Settings> entry : settings.getGroups("event.path").entrySet()) {
for (Map.Entry<String, Settings> 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<PathEventService> 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) {

View file

@ -27,18 +27,17 @@ public class TimerEventManagerService extends AbstractEventManagerService implem
private EventManager eventManager;
private Map<String, TimerEventService> services;
private final Map<String, TimerEventService> 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<String, Settings> entry : settings.getGroups("event.timer").entrySet()) {
for (Map.Entry<String, Settings> 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;
}