X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fmain%2FSonePlugin.java;h=ecf7f5b7a47b6234d5e8b9dd8c4aeee05fe65dd5;hb=1a151ba84834dcf909a41c010538900b8c8b2664;hp=7ac2c8387e1ec90377ae60b05a78cdec8445aaf3;hpb=df67609c4eebc32a728bd35bfb9729a8e63c5bf7;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index 7ac2c83..ecf7f5b 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.main; import java.io.File; import java.util.Collections; import java.util.logging.Level; +import java.util.logging.LogRecord; import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; @@ -31,6 +32,7 @@ import net.pterodactylus.util.config.ConfigurationException; import net.pterodactylus.util.config.MapConfigurationBackend; import net.pterodactylus.util.config.XMLConfigurationBackend; import net.pterodactylus.util.logging.Logging; +import net.pterodactylus.util.logging.LoggingListener; import net.pterodactylus.util.version.Version; import freenet.client.async.DatabaseDisabledException; import freenet.l10n.BaseL10n.LANGUAGE; @@ -41,6 +43,7 @@ import freenet.pluginmanager.FredPluginL10n; import freenet.pluginmanager.FredPluginThreadless; import freenet.pluginmanager.FredPluginVersioned; import freenet.pluginmanager.PluginRespirator; +import freenet.pluginmanager.PluginStore; /** * This class interfaces with Freenet. It is the class that is loaded by the @@ -53,10 +56,30 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10 static { /* initialize logging. */ Logging.setup("sone"); + Logging.addLoggingListener(new LoggingListener() { + + @Override + public void logged(LogRecord logRecord) { + Class loggerClass = Logging.getLoggerClass(logRecord.getLoggerName()); + int recordLevel = logRecord.getLevel().intValue(); + if (recordLevel < Level.FINE.intValue()) { + freenet.support.Logger.debug(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown()); + } else if (recordLevel < Level.INFO.intValue()) { + freenet.support.Logger.minor(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown()); + } else if (recordLevel < Level.WARNING.intValue()) { + freenet.support.Logger.normal(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown()); + } else if (recordLevel < Level.SEVERE.intValue()) { + freenet.support.Logger.warning(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown()); + } else { + freenet.support.Logger.error(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown()); + } + } + + }); } /** The version. */ - private static final Version VERSION = new Version("SNAPSHOT", 0, 1); + public static final Version VERSION = new Version("RC2", 0, 1); /** The logger. */ private static final Logger logger = Logging.getLogger(SonePlugin.class); @@ -73,6 +96,9 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10 /** The l10n helper. */ private PluginL10n l10n; + /** The plugin store. */ + private PluginStore pluginStore; + // // ACCESSORS // @@ -118,7 +144,7 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10 /* create a configuration. */ Configuration configuration; try { - configuration = new Configuration(new PluginStoreConfigurationBackend(pluginRespirator.getStore())); + configuration = new Configuration(new PluginStoreConfigurationBackend(pluginStore = pluginRespirator.getStore())); } catch (DatabaseDisabledException dde1) { logger.log(Level.WARNING, "Could not load plugin store, using XML files."); try { @@ -141,8 +167,21 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10 core.freenetInterface(freenetInterface); /* start core! */ - core.start(); - webInterface.start(); + boolean startupFailed = true; + try { + core.start(); + webInterface.start(); + startupFailed = false; + } finally { + if (startupFailed) { + /* + * we let the exception bubble up but shut the logging down so + * that the logfile is not swamped by the installed logging + * handlers of the failed instances. + */ + Logging.shutdown(); + } + } } /** @@ -150,16 +189,24 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10 */ @Override public void terminate() { - /* stop the web interface. */ - webInterface.stop(); + try { + /* stop the web interface. */ + webInterface.stop(); - /* stop the core. */ - core.stop(); + /* stop the core. */ + core.stop(); - /* TODO wait for core to stop? */ + /* TODO wait for core to stop? */ + try { + pluginRespirator.putStore(pluginStore); + } catch (DatabaseDisabledException dde1) { + logger.log(Level.WARNING, "Could not store plugin store, database is disabled.", dde1); + } - /* shutdown logger. */ - Logging.shutdown(); + } finally { + /* shutdown logger. */ + Logging.shutdown(); + } } //