From 5bcdc1b924c598b1e59551d44e2302ef29258dad Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 29 Aug 2014 18:26:20 +0200 Subject: [PATCH] =?utf8?q?Move=20dependency=20injection=20configuration=20?= =?utf8?q?closer=20to=20where=20it=E2=80=99s=20useful.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/core/Core.java | 2 ++ .../java/net/pterodactylus/sone/core/FreenetInterface.java | 2 ++ .../java/net/pterodactylus/sone/core/WebOfTrustUpdater.java | 3 +++ .../net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java | 2 ++ src/main/java/net/pterodactylus/sone/database/Database.java | 4 ++++ .../net/pterodactylus/sone/database/PostBuilderFactory.java | 5 +++++ .../java/net/pterodactylus/sone/database/PostProvider.java | 3 +++ .../sone/database/PostReplyBuilderFactory.java | 5 +++++ .../java/net/pterodactylus/sone/database/SoneProvider.java | 3 +++ .../pterodactylus/sone/database/memory/MemoryDatabase.java | 2 ++ src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java | 2 ++ .../pterodactylus/sone/freenet/plugin/PluginConnector.java | 2 ++ .../net/pterodactylus/sone/freenet/wot/IdentityManager.java | 2 ++ .../pterodactylus/sone/freenet/wot/IdentityManagerImpl.java | 2 ++ .../pterodactylus/sone/freenet/wot/WebOfTrustConnector.java | 2 ++ src/main/java/net/pterodactylus/sone/main/SonePlugin.java | 13 ------------- 16 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 87f858b..1229448 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -101,6 +101,7 @@ import com.google.common.collect.Multimaps; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; import com.google.inject.Inject; +import com.google.inject.Singleton; import freenet.keys.FreenetURI; @@ -109,6 +110,7 @@ import freenet.keys.FreenetURI; * * @author David ‘Bombe’ Roden */ +@Singleton public class Core extends AbstractService implements SoneProvider, PostProvider, PostReplyProvider { /** The logger. */ diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index 9ccf5fc..d4640f8 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -39,6 +39,7 @@ import com.db4o.ObjectContainer; import com.google.common.base.Function; import com.google.common.eventbus.EventBus; import com.google.inject.Inject; +import com.google.inject.Singleton; import freenet.client.ClientMetadata; import freenet.client.FetchException; @@ -66,6 +67,7 @@ import freenet.support.io.ArrayBucket; * * @author David ‘Bombe’ Roden */ +@Singleton public class FreenetInterface { /** The logger. */ diff --git a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java index c3eb24b..908bd96 100644 --- a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java +++ b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java @@ -4,11 +4,14 @@ import net.pterodactylus.sone.freenet.wot.Identity; import net.pterodactylus.sone.freenet.wot.OwnIdentity; import net.pterodactylus.util.service.Service; +import com.google.inject.ImplementedBy; + /** * Updates WebOfTrust identity data. * * @author David ‘Bombe’ Roden */ +@ImplementedBy(WebOfTrustUpdaterImpl.class) public interface WebOfTrustUpdater extends Service { void setTrust(OwnIdentity truster, Identity trustee, Integer score, String comment); diff --git a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java index 05deb29..8a6d083 100644 --- a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java +++ b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java @@ -35,6 +35,7 @@ import net.pterodactylus.util.service.AbstractService; import com.google.common.annotations.VisibleForTesting; import com.google.inject.Inject; +import com.google.inject.Singleton; /** * Updates WebOfTrust identity data in a background thread because communicating @@ -42,6 +43,7 @@ import com.google.inject.Inject; * * @author David ‘Bombe’ Roden */ +@Singleton public class WebOfTrustUpdaterImpl extends AbstractService implements WebOfTrustUpdater { /** The logger. */ diff --git a/src/main/java/net/pterodactylus/sone/database/Database.java b/src/main/java/net/pterodactylus/sone/database/Database.java index ee7a9af..051e442 100644 --- a/src/main/java/net/pterodactylus/sone/database/Database.java +++ b/src/main/java/net/pterodactylus/sone/database/Database.java @@ -17,7 +17,10 @@ package net.pterodactylus.sone.database; +import net.pterodactylus.sone.database.memory.MemoryDatabase; + import com.google.common.util.concurrent.Service; +import com.google.inject.ImplementedBy; /** * Database for Sone data. This interface combines the various provider, store, @@ -26,6 +29,7 @@ import com.google.common.util.concurrent.Service; * * @author David ‘Bombe’ Roden */ +@ImplementedBy(MemoryDatabase.class) public interface Database extends Service, PostDatabase, PostReplyDatabase, AlbumDatabase, ImageDatabase { /** diff --git a/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java b/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java index b89ae28..e74a6bd 100644 --- a/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java +++ b/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java @@ -17,11 +17,16 @@ package net.pterodactylus.sone.database; +import net.pterodactylus.sone.database.memory.MemoryDatabase; + +import com.google.inject.ImplementedBy; + /** * Factory for {@link PostBuilder}s. * * @author David ‘Bombe’ Roden */ +@ImplementedBy(MemoryDatabase.class) public interface PostBuilderFactory { /** diff --git a/src/main/java/net/pterodactylus/sone/database/PostProvider.java b/src/main/java/net/pterodactylus/sone/database/PostProvider.java index 740373e..7d5437a 100644 --- a/src/main/java/net/pterodactylus/sone/database/PostProvider.java +++ b/src/main/java/net/pterodactylus/sone/database/PostProvider.java @@ -20,14 +20,17 @@ package net.pterodactylus.sone.database; import java.util.Collection; import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.database.memory.MemoryDatabase; import com.google.common.base.Optional; +import com.google.inject.ImplementedBy; /** * Interface for objects that can provide {@link Post}s by their ID. * * @author David ‘Bombe’ Roden */ +@ImplementedBy(MemoryDatabase.class) public interface PostProvider { /** diff --git a/src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java b/src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java index 7fd4ae1..cac3e30 100644 --- a/src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java +++ b/src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java @@ -17,11 +17,16 @@ package net.pterodactylus.sone.database; +import net.pterodactylus.sone.database.memory.MemoryDatabase; + +import com.google.inject.ImplementedBy; + /** * Factory for {@link PostReplyBuilder}s. * * @author David ‘Bombe’ Roden */ +@ImplementedBy(MemoryDatabase.class) public interface PostReplyBuilderFactory { /** diff --git a/src/main/java/net/pterodactylus/sone/database/SoneProvider.java b/src/main/java/net/pterodactylus/sone/database/SoneProvider.java index 993804f..f36eaba 100644 --- a/src/main/java/net/pterodactylus/sone/database/SoneProvider.java +++ b/src/main/java/net/pterodactylus/sone/database/SoneProvider.java @@ -19,15 +19,18 @@ package net.pterodactylus.sone.database; import java.util.Collection; +import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import com.google.common.base.Optional; +import com.google.inject.ImplementedBy; /** * Interface for objects that can provide {@link Sone}s by their ID. * * @author David ‘Bombe’ Roden */ +@ImplementedBy(Core.class) public interface SoneProvider { /** diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 67ea671..237d321 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -58,12 +58,14 @@ import com.google.common.collect.SortedSetMultimap; import com.google.common.collect.TreeMultimap; import com.google.common.util.concurrent.AbstractService; import com.google.inject.Inject; +import com.google.inject.Singleton; /** * Memory-based {@link PostDatabase} implementation. * * @author David ‘Bombe’ Roden */ +@Singleton public class MemoryDatabase extends AbstractService implements Database { /** The lock. */ diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index 18c017b..551dc4f 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -41,6 +41,7 @@ import freenet.support.api.Bucket; import com.google.common.annotations.VisibleForTesting; import com.google.inject.Inject; +import com.google.inject.Singleton; /** * Implementation of an FCP interface for other clients or plugins to @@ -48,6 +49,7 @@ import com.google.inject.Inject; * * @author David ‘Bombe’ Roden */ +@Singleton public class FcpInterface { /** diff --git a/src/main/java/net/pterodactylus/sone/freenet/plugin/PluginConnector.java b/src/main/java/net/pterodactylus/sone/freenet/plugin/PluginConnector.java index 47330e8..56ac807 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/plugin/PluginConnector.java +++ b/src/main/java/net/pterodactylus/sone/freenet/plugin/PluginConnector.java @@ -21,6 +21,7 @@ import net.pterodactylus.sone.freenet.plugin.event.ReceivedReplyEvent; import com.google.common.eventbus.EventBus; import com.google.inject.Inject; +import com.google.inject.Singleton; import freenet.pluginmanager.FredPluginTalker; import freenet.pluginmanager.PluginNotFoundException; @@ -35,6 +36,7 @@ import freenet.support.api.Bucket; * * @author David ‘Bombe’ Roden */ +@Singleton public class PluginConnector implements FredPluginTalker { /** The event bus. */ diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java index 99d757b..d3ba606 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java @@ -5,6 +5,7 @@ import java.util.Set; import net.pterodactylus.util.service.Service; import com.google.common.eventbus.EventBus; +import com.google.inject.ImplementedBy; /** * Connects to a {@link WebOfTrustConnector} and sends identity events to an @@ -12,6 +13,7 @@ import com.google.common.eventbus.EventBus; * * @author David ‘Bombe’ Roden */ +@ImplementedBy(IdentityManagerImpl.class) public interface IdentityManager extends Service { boolean isConnected(); diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.java index 3946c04..f568aa4 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.java @@ -32,6 +32,7 @@ import net.pterodactylus.util.service.AbstractService; import com.google.common.collect.Sets; import com.google.common.eventbus.EventBus; import com.google.inject.Inject; +import com.google.inject.Singleton; /** * The identity manager takes care of loading and storing identities, their @@ -44,6 +45,7 @@ import com.google.inject.Inject; * * @author David ‘Bombe’ Roden */ +@Singleton public class IdentityManagerImpl extends AbstractService implements IdentityManager { /** The logger. */ diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java index 7938a09..4996c46 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java @@ -35,6 +35,7 @@ import com.google.common.base.Optional; import com.google.common.collect.MapMaker; import com.google.common.eventbus.Subscribe; import com.google.inject.Inject; +import com.google.inject.Singleton; import freenet.support.SimpleFieldSet; import freenet.support.api.Bucket; @@ -44,6 +45,7 @@ import freenet.support.api.Bucket; * * @author David ‘Bombe’ Roden */ +@Singleton public class WebOfTrustConnector { /** The logger. */ diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index ce2cd40..ae34c1c 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -224,25 +224,12 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr @Override protected void configure() { - bind(Core.class).in(Singleton.class); - bind(MemoryDatabase.class).in(Singleton.class); bind(EventBus.class).toInstance(eventBus); bind(Configuration.class).toInstance(startConfiguration); - bind(FreenetInterface.class).in(Singleton.class); - bind(PluginConnector.class).in(Singleton.class); Context context = new Context("Sone"); bind(Context.class).toInstance(context); bind(getOptionalContextTypeLiteral()).toInstance(of(context)); - bind(WebOfTrustConnector.class).in(Singleton.class); - bind(WebOfTrustUpdater.class).to(WebOfTrustUpdaterImpl.class).in(Singleton.class); - bind(IdentityManager.class).to(IdentityManagerImpl.class).in(Singleton.class); bind(SonePlugin.class).toInstance(SonePlugin.this); - bind(FcpInterface.class).in(Singleton.class); - bind(Database.class).to(MemoryDatabase.class); - bind(PostBuilderFactory.class).to(MemoryDatabase.class); - bind(PostReplyBuilderFactory.class).to(MemoryDatabase.class); - bind(SoneProvider.class).to(Core.class).in(Singleton.class); - bind(PostProvider.class).to(MemoryDatabase.class); bindListener(Matchers.any(), new TypeListener() { @Override -- 2.7.4