X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FFcpInterface.java;h=7fb4462347853b2b055fc3b6006da2d6288eb78f;hb=2d15e85a3ea6c752a792aa918bbb5938760d69ac;hp=36e18e65ea4251d8497def0c0a5da4a17d2c59d4;hpb=0747ce52deab6ed6e4c3118959cf76827c2ce495;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index 36e18e6..7fb4462 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -20,7 +20,6 @@ package net.pterodactylus.sone.fcp; import static com.google.common.base.Preconditions.checkNotNull; import static java.util.logging.Logger.getLogger; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; @@ -28,6 +27,8 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; +import javax.inject.Singleton; + import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.fcp.event.FcpInterfaceActivatedEvent; import net.pterodactylus.sone.fcp.event.FcpInterfaceDeactivatedEvent; @@ -45,7 +46,6 @@ import freenet.support.api.Bucket; import com.google.common.annotations.VisibleForTesting; import com.google.common.eventbus.Subscribe; import com.google.inject.Inject; -import com.google.inject.Singleton; /** * Implementation of an FCP interface for other clients or plugins to @@ -84,7 +84,7 @@ public class FcpInterface { private final AtomicReference fullAccessRequired = new AtomicReference(FullAccessRequired.ALWAYS); /** All available FCP commands. */ - private final Map commands = Collections.synchronizedMap(new HashMap()); + private final Map commands; /** * Creates a new FCP interface. @@ -93,22 +93,8 @@ public class FcpInterface { * The core */ @Inject - public FcpInterface(Core core) { - commands.put("Version", new VersionCommand(core)); - commands.put("GetLocalSones", new GetLocalSonesCommand(core)); - commands.put("GetSones", new GetSonesCommand(core)); - commands.put("GetSone", new GetSoneCommand(core)); - commands.put("GetPost", new GetPostCommand(core)); - commands.put("GetPosts", new GetPostsCommand(core)); - commands.put("GetPostFeed", new GetPostFeedCommand(core)); - commands.put("LockSone", new LockSoneCommand(core)); - commands.put("UnlockSone", new UnlockSoneCommand(core)); - commands.put("LikePost", new LikePostCommand(core)); - commands.put("LikeReply", new LikeReplyCommand(core)); - commands.put("CreatePost", new CreatePostCommand(core)); - commands.put("CreateReply", new CreateReplyCommand(core)); - commands.put("DeletePost", new DeletePostCommand(core)); - commands.put("DeleteReply", new DeleteReplyCommand(core)); + public FcpInterface(Core core, CommandSupplier commandSupplier) { + commands = commandSupplier.supplyCommands(core); } // @@ -232,4 +218,29 @@ public class FcpInterface { setFullAccessRequired(fullAccessRequiredChanged.getFullAccessRequired()); } + @Singleton + public static class CommandSupplier { + + public Map supplyCommands(Core core) { + Map commands = new HashMap<>(); + commands.put("Version", new VersionCommand(core)); + commands.put("GetLocalSones", new GetLocalSonesCommand(core)); + commands.put("GetSones", new GetSonesCommand(core)); + commands.put("GetSone", new GetSoneCommand(core)); + commands.put("GetPost", new GetPostCommand(core)); + commands.put("GetPosts", new GetPostsCommand(core)); + commands.put("GetPostFeed", new GetPostFeedCommand(core)); + commands.put("LockSone", new LockSoneCommand(core)); + commands.put("UnlockSone", new UnlockSoneCommand(core)); + commands.put("LikePost", new LikePostCommand(core)); + commands.put("LikeReply", new LikeReplyCommand(core)); + commands.put("CreatePost", new CreatePostCommand(core)); + commands.put("CreateReply", new CreateReplyCommand(core)); + commands.put("DeletePost", new DeletePostCommand(core)); + commands.put("DeleteReply", new DeleteReplyCommand(core)); + return commands; + } + + } + }