X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fmain%2FSonePlugin.java;h=82ab065f19045ff65b75c2bf0c79fc2514adaf93;hp=f2cf128f22beabcf531da6a7362a33433c0c129d;hb=HEAD;hpb=18ada47554280f444bb829dafc4d40926312066e diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index f2cf128..82ab065 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -1,5 +1,5 @@ /* - * Sone - SonePlugin.java - Copyright © 2010–2019 David Roden + * Sone - SonePlugin.java - Copyright © 2010–2020 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,10 +22,15 @@ import static java.util.logging.Logger.*; import java.util.logging.Logger; import java.util.logging.*; +import javax.annotation.Nonnull; + import net.pterodactylus.sone.core.*; +import net.pterodactylus.sone.core.event.*; import net.pterodactylus.sone.fcp.*; import net.pterodactylus.sone.freenet.wot.*; import net.pterodactylus.sone.web.*; +import net.pterodactylus.sone.web.notification.NotificationHandler; +import net.pterodactylus.sone.web.notification.NotificationHandlerModule; import freenet.l10n.BaseL10n.*; import freenet.l10n.*; @@ -34,6 +39,7 @@ import freenet.support.*; import freenet.support.api.*; import com.google.common.annotations.*; +import com.google.common.eventbus.*; import com.google.common.cache.*; import com.google.inject.*; import com.google.inject.name.*; @@ -50,12 +56,13 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr static { /* initialize logging. */ soneLogger.setUseParentHandlers(false); + soneLogger.setLevel(Level.ALL); soneLogger.addHandler(new Handler() { private final LoadingCache> classCache = CacheBuilder.newBuilder() .build(new CacheLoader>() { @Override - public Class load(String key) throws Exception { - return Class.forName(key); + public Class load(@Nonnull String key) throws Exception { + return SonePlugin.class.getClassLoader().loadClass(key); } }); @@ -87,9 +94,9 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr } /** The current year at time of release. */ - private static final int YEAR = 2019; + private static final int YEAR = 2020; private static final String SONE_HOMEPAGE = "USK@nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI,DuQSUZiI~agF8c-6tjsFFGuZ8eICrzWCILB60nT8KKo,AQACAAE/sone/"; - private static final int LATEST_EDITION = 79; + private static final int LATEST_EDITION = 81; /** The logger. */ private static final Logger logger = getLogger(SonePlugin.class.getName()); @@ -102,6 +109,9 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr /** The core. */ private Core core; + /** The event bus. */ + private EventBus eventBus; + /** The web interface. */ private WebInterface webInterface; @@ -194,20 +204,42 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr /* create the web interface. */ webInterface = injector.getInstance(WebInterface.class); + /* we need to request this to install all notification handlers. */ + injector.getInstance(NotificationHandler.class); + + /* and this is required to shutdown all tickers. */ + injector.getInstance(TickerShutdown.class); + /* start core! */ core.start(); + + /* start the web interface! */ webInterface.start(); - webInterface.setFirstStart(injector.getInstance(Key.get(Boolean.class, Names.named("FirstStart")))); - webInterface.setNewConfig(injector.getInstance(Key.get(Boolean.class, Names.named("NewConfig")))); + + /* send some events on startup */ + eventBus = injector.getInstance(EventBus.class); + + /* first start? */ + if (injector.getInstance(Key.get(Boolean.class, Names.named("FirstStart")))) { + eventBus.post(new FirstStart()); + } else { + /* new config? */ + if (injector.getInstance(Key.get(Boolean.class, Names.named("NewConfig")))) { + eventBus.post(new ConfigNotRead()); + } + } + + eventBus.post(new Startup()); } @VisibleForTesting protected Injector createInjector() { FreenetModule freenetModule = new FreenetModule(pluginRespirator); - AbstractModule soneModule = new SoneModule(this); + AbstractModule soneModule = new SoneModule(this, new EventBus()); Module webInterfaceModule = new WebInterfaceModule(); + Module notificationHandlerModule = new NotificationHandlerModule(); - return createInjector(freenetModule, soneModule, webInterfaceModule); + return createInjector(freenetModule, soneModule, webInterfaceModule, notificationHandlerModule); } @VisibleForTesting @@ -220,6 +252,9 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr */ @Override public void terminate() { + /* send shutdown event. */ + eventBus.post(new Shutdown()); + try { /* stop the web interface. */ webInterface.stop();