Made error handling more robust for managers

This commit is contained in:
Ziver Koc 2021-12-04 21:31:48 +01:00
parent b65a9f0bd3
commit b91f006d8b
2 changed files with 14 additions and 13 deletions

View file

@ -51,6 +51,8 @@ public class HalServer {
// init logging
LogUtil.readConfiguration("logging.properties");
HalAlertManager.initialize();
http = new HttpServer(HalContext.getIntegerProperty(HalContext.CONFIG_HTTP_PORT));
http.setDefaultPage(new StartupWebPage());
http.start();
@ -95,7 +97,6 @@ public class HalServer {
logger.info("Initializing managers.");
HalAlertManager.initialize();
TriggerManager.initialize(pluginManager);
for (Iterator<HalAbstractControllerManager> it = pluginManager.getSingletonIterator(HalAbstractControllerManager.class); it.hasNext(); ) {
@ -175,9 +176,13 @@ public class HalServer {
* @param daemon registers the given daemon and starts execution of the Runnable.
*/
public static void registerDaemon(HalDaemon daemon){
logger.info("Registering daemon: " + daemon.getClass());
daemons.add(daemon);
daemon.initiate(daemonExecutor);
try {
logger.info("Registering daemon: " + daemon.getClass());
daemons.add(daemon);
daemon.initiate(daemonExecutor);
} catch (Exception e) {
logger.log(Level.SEVERE, "Unable to initialize daemon: " + daemon.getClass(), e);
}
}

View file

@ -121,15 +121,11 @@ public class HalExternalWebDaemon implements HalDaemon {
UserMessageManager.MessageLevel.WARNING, "No SSL certificate is configured for external web-server.", UserMessageManager.MessageTTL.DISMISSED));
certificate = null;
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Unable to request cert from ACME service.", e);
HalAlertManager.getInstance().addAlert(new UserMessageManager.UserMessage(
UserMessageManager.MessageLevel.WARNING, "Was unable to generate SSL certificate for external web-server: " + e.getMessage(), UserMessageManager.MessageTTL.DISMISSED));
}
// Cleanup
if (tmpHttpServer != null) {
tmpHttpServer.close();
} finally {
// Cleanup
if (tmpHttpServer != null) {
tmpHttpServer.close();
}
}
}
}