X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fmain%2FSonePlugin.java;h=ae34c1c4c7440f1c2077caa0d9239ca8eadf6b29;hb=5bcdc1b924c598b1e59551d44e2302ef29258dad;hp=5b28b85a76d05a6e6cefa63cc69994ed9f554c74;hpb=351ac31925b0f8f6ba1a4132997e85b7175c48da;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 5b28b85..ae34c1c 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–2012 David Roden + * Sone - SonePlugin.java - Copyright © 2010–2013 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 @@ -17,6 +17,8 @@ package net.pterodactylus.sone.main; +import static com.google.common.base.Optional.of; + import java.io.File; import java.util.logging.Level; import java.util.logging.LogRecord; @@ -25,10 +27,19 @@ import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.core.FreenetInterface; import net.pterodactylus.sone.core.WebOfTrustUpdater; +import net.pterodactylus.sone.core.WebOfTrustUpdaterImpl; +import net.pterodactylus.sone.database.Database; +import net.pterodactylus.sone.database.PostBuilderFactory; +import net.pterodactylus.sone.database.PostProvider; +import net.pterodactylus.sone.database.PostReplyBuilderFactory; +import net.pterodactylus.sone.database.SoneProvider; +import net.pterodactylus.sone.database.memory.MemoryDatabase; import net.pterodactylus.sone.fcp.FcpInterface; import net.pterodactylus.sone.freenet.PluginStoreConfigurationBackend; import net.pterodactylus.sone.freenet.plugin.PluginConnector; +import net.pterodactylus.sone.freenet.wot.Context; import net.pterodactylus.sone.freenet.wot.IdentityManager; +import net.pterodactylus.sone.freenet.wot.IdentityManagerImpl; import net.pterodactylus.sone.freenet.wot.WebOfTrustConnector; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.util.config.Configuration; @@ -37,9 +48,23 @@ import net.pterodactylus.util.config.MapConfigurationBackend; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.logging.LoggingListener; import net.pterodactylus.util.version.Version; + +import com.google.common.base.Optional; +import com.google.common.eventbus.EventBus; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Singleton; +import com.google.inject.TypeLiteral; +import com.google.inject.matcher.Matchers; +import com.google.inject.spi.InjectionListener; +import com.google.inject.spi.TypeEncounter; +import com.google.inject.spi.TypeListener; + import freenet.client.async.DatabaseDisabledException; import freenet.l10n.BaseL10n.LANGUAGE; import freenet.l10n.PluginL10n; +import freenet.node.Node; import freenet.pluginmanager.FredPlugin; import freenet.pluginmanager.FredPluginBaseL10n; import freenet.pluginmanager.FredPluginFCP; @@ -84,7 +109,7 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr } /** The version. */ - public static final Version VERSION = new Version(0, 8, 4); + public static final Version VERSION = new Version(0, 8, 9); /** The logger. */ private static final Logger logger = Logging.getLogger(SonePlugin.class); @@ -107,9 +132,6 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr /** The web of trust connector. */ private WebOfTrustConnector webOfTrustConnector; - /** The identity manager. */ - private IdentityManager identityManager; - // // ACCESSORS // @@ -178,44 +200,78 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr } } - boolean startupFailed = true; - try { - /* create freenet interface. */ - FreenetInterface freenetInterface = new FreenetInterface(pluginRespirator.getNode()); + final Configuration startConfiguration; + if ((newConfiguration != null) && (oldConfiguration != newConfiguration)) { + logger.log(Level.INFO, "Setting configuration to file-based configuration."); + startConfiguration = newConfiguration; + } else { + startConfiguration = oldConfiguration; + } + final EventBus eventBus = new EventBus(); - /* create web of trust connector. */ - PluginConnector pluginConnector = new PluginConnector(pluginRespirator); - webOfTrustConnector = new WebOfTrustConnector(pluginConnector); - identityManager = new IdentityManager(webOfTrustConnector, "Sone"); + /* Freenet injector configuration. */ + AbstractModule freenetModule = new AbstractModule() { - /* create trust updater. */ - WebOfTrustUpdater trustUpdater = new WebOfTrustUpdater(webOfTrustConnector); - trustUpdater.init(); + @Override + @SuppressWarnings("synthetic-access") + protected void configure() { + bind(PluginRespirator.class).toInstance(SonePlugin.this.pluginRespirator); + bind(Node.class).toInstance(SonePlugin.this.pluginRespirator.getNode()); + } + }; + /* Sone injector configuration. */ + AbstractModule soneModule = new AbstractModule() { - /* create core. */ - core = new Core(oldConfiguration, freenetInterface, identityManager, trustUpdater); + @Override + protected void configure() { + bind(EventBus.class).toInstance(eventBus); + bind(Configuration.class).toInstance(startConfiguration); + Context context = new Context("Sone"); + bind(Context.class).toInstance(context); + bind(getOptionalContextTypeLiteral()).toInstance(of(context)); + bind(SonePlugin.class).toInstance(SonePlugin.this); + bindListener(Matchers.any(), new TypeListener() { + + @Override + public void hear(TypeLiteral typeLiteral, TypeEncounter typeEncounter) { + typeEncounter.register(new InjectionListener() { + + @Override + public void afterInjection(I injectee) { + eventBus.register(injectee); + } + }); + } + }); + } + + private TypeLiteral> getOptionalContextTypeLiteral() { + return new TypeLiteral>() { + }; + } - /* create the web interface. */ - webInterface = new WebInterface(this); - core.addCoreListener(webInterface); + }; + Injector injector = Guice.createInjector(freenetModule, soneModule); + core = injector.getInstance(Core.class); - /* create FCP interface. */ - fcpInterface = new FcpInterface(core); - core.setFcpInterface(fcpInterface); + /* create web of trust connector. */ + webOfTrustConnector = injector.getInstance(WebOfTrustConnector.class); - /* create the identity manager. */ - identityManager.addIdentityListener(core); + /* create FCP interface. */ + fcpInterface = injector.getInstance(FcpInterface.class); + core.setFcpInterface(fcpInterface); + + /* create the web interface. */ + webInterface = injector.getInstance(WebInterface.class); + + boolean startupFailed = true; + try { /* start core! */ core.start(); - if ((newConfiguration != null) && (oldConfiguration != newConfiguration)) { - logger.log(Level.INFO, "Setting configuration to file-based configuration."); - core.setConfiguration(newConfiguration); - } webInterface.start(); webInterface.setFirstStart(firstStart); webInterface.setNewConfig(newConfig); - identityManager.start(); startupFailed = false; } finally { if (startupFailed) { @@ -241,9 +297,6 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr /* stop the core. */ core.stop(); - /* stop the identity manager. */ - identityManager.stop(); - /* stop the web of trust connector. */ webOfTrustConnector.stop(); } catch (Throwable t1) {