From 7a3be5ca037785f4f1acb225381578db12d15eb1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 15 Oct 2015 07:18:52 +0200 Subject: [PATCH] Use a single identifier generator in all commands --- .../fcp/quelaton/AddPeerCommandImpl.java | 11 ++++--- .../fcp/quelaton/ClientGetCommandImpl.java | 7 ++-- .../fcp/quelaton/ClientPutCommandImpl.java | 8 +++-- .../fcp/quelaton/DefaultFcpClient.java | 37 +++++++++++----------- .../fcp/quelaton/GetConfigCommandImpl.java | 7 ++-- .../fcp/quelaton/GetNodeCommandImpl.java | 7 ++-- .../fcp/quelaton/GetPluginInfoCommandImpl.java | 7 ++-- .../fcp/quelaton/ListPeerCommandImpl.java | 11 +++++-- .../fcp/quelaton/ListPeerNotesCommandImpl.java | 8 +++-- .../fcp/quelaton/ListPeersCommandImpl.java | 8 +++-- .../fcp/quelaton/LoadPluginCommandImpl.java | 7 ++-- .../fcp/quelaton/ModifyConfigCommandImpl.java | 6 ++-- .../fcp/quelaton/ModifyPeerCommandImpl.java | 7 ++-- .../fcp/quelaton/ModifyPeerNoteCommandImpl.java | 8 +++-- .../fcp/quelaton/ReloadPluginCommandImpl.java | 7 ++-- .../fcp/quelaton/RemovePeerCommandImpl.java | 7 ++-- .../fcp/quelaton/RemovePluginCommandImpl.java | 7 ++-- .../fcp/quelaton/SubscribeUskCommandImpl.java | 7 ++-- .../fcp/quelaton/UnsubscribeUskCommandImpl.java | 7 ++-- 19 files changed, 107 insertions(+), 67 deletions(-) diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/AddPeerCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/AddPeerCommandImpl.java index 4fab83c..b34d2ba 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/AddPeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/AddPeerCommandImpl.java @@ -8,6 +8,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.AddPeer; import net.pterodactylus.fcp.NodeRef; @@ -27,11 +28,13 @@ public class AddPeerCommandImpl implements AddPeerCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final Supplier identifierSupplier; private final AtomicReference file = new AtomicReference<>(); private final AtomicReference url = new AtomicReference<>(); private final AtomicReference nodeRef = new AtomicReference<>(); - public AddPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public AddPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierSupplier) { + this.identifierSupplier = identifierSupplier; this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; } @@ -61,11 +64,11 @@ public class AddPeerCommandImpl implements AddPeerCommand { private Optional executeDialog() throws IOException, ExecutionException, InterruptedException { AddPeer addPeer; if (file.get() != null) { - addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), file.get().getPath()); + addPeer = new AddPeer(identifierSupplier.get(), file.get().getPath()); } else if (url.get() != null) { - addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), url.get()); + addPeer = new AddPeer(identifierSupplier.get(), url.get()); } else { - addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), nodeRef.get()); + addPeer = new AddPeer(identifierSupplier.get(), nodeRef.get()); } try (AddPeerDialog addPeerDialog = new AddPeerDialog()) { return addPeerDialog.send(addPeer).get(); diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ClientGetCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ClientGetCommandImpl.java index 0c93fc3..d01b82e 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ClientGetCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ClientGetCommandImpl.java @@ -6,6 +6,7 @@ import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; import net.pterodactylus.fcp.AllData; import net.pterodactylus.fcp.ClientGet; @@ -26,6 +27,7 @@ class ClientGetCommandImpl implements ClientGetCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final Supplier identifierGenerator; private boolean ignoreDataStore; private boolean dataStoreOnly; @@ -34,9 +36,10 @@ class ClientGetCommandImpl implements ClientGetCommand { private boolean realTime; private boolean global; - public ClientGetCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public ClientGetCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + this.identifierGenerator = identifierGenerator; } @Override @@ -88,7 +91,7 @@ class ClientGetCommandImpl implements ClientGetCommand { } private ClientGet createClientGetCommand(String uri) { - String identifier = new RandomIdentifierGenerator().generate(); + String identifier = identifierGenerator.get(); ClientGet clientGet = new ClientGet(uri, identifier, ReturnType.direct); if (ignoreDataStore) { clientGet.setIgnoreDataStore(true); diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutCommandImpl.java index 06d54e0..6eeddd9 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutCommandImpl.java @@ -14,6 +14,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; +import java.util.function.Supplier; import net.pterodactylus.fcp.ClientPut; import net.pterodactylus.fcp.FcpMessage; @@ -41,6 +42,7 @@ class ClientPutCommandImpl implements ClientPutCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final Supplier identifierGenerator; private final AtomicReference redirectUri = new AtomicReference<>(); private final AtomicReference file = new AtomicReference<>(); private final AtomicReference payload = new AtomicReference<>(); @@ -48,9 +50,10 @@ class ClientPutCommandImpl implements ClientPutCommand { private final AtomicReference targetFilename = new AtomicReference<>(); private final List> keyGenerateds = new CopyOnWriteArrayList<>(); - public ClientPutCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public ClientPutCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + this.identifierGenerator = identifierGenerator; } @Override @@ -93,8 +96,7 @@ class ClientPutCommandImpl implements ClientPutCommand { } private Optional execute(String uri) throws InterruptedException, ExecutionException, IOException { - String identifier = new RandomIdentifierGenerator().generate(); - ClientPut clientPut = createClientPutCommand(uri, identifier); + ClientPut clientPut = createClientPutCommand(uri, identifierGenerator.get()); try (ClientPutDialog clientPutDialog = new ClientPutDialog()) { return clientPutDialog.send(clientPut).get(); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java index d0bf14a..dc6d950 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java @@ -18,6 +18,7 @@ import com.google.common.util.concurrent.MoreExecutors; */ public class DefaultFcpClient implements FcpClient { + private final RandomIdentifierGenerator randomIdentifierGenerator = new RandomIdentifierGenerator(); private final ListeningExecutorService threadPool; private final String hostname; private final int port; @@ -57,17 +58,17 @@ public class DefaultFcpClient implements FcpClient { @Override public GetNodeCommand getNode() { - return new GetNodeCommandImpl(threadPool, this::connect); + return new GetNodeCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public GetConfigCommand getConfig() { - return new GetConfigCommandImpl(threadPool, this::connect); + return new GetConfigCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public ModifyConfigCommand modifyConfig() { - return new ModifyConfigCommandImpl(threadPool, this::connect); + return new ModifyConfigCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override @@ -77,76 +78,76 @@ public class DefaultFcpClient implements FcpClient { @Override public ClientGetCommand clientGet() { - return new ClientGetCommandImpl(threadPool, this::connect); + return new ClientGetCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public ClientPutCommand clientPut() { - return new ClientPutCommandImpl(threadPool, this::connect); + return new ClientPutCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public ListPeerCommand listPeer() { - return new ListPeerCommandImpl(threadPool, this::connect); + return new ListPeerCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public ListPeersCommand listPeers() { - return new ListPeersCommandImpl(threadPool, this::connect); + return new ListPeersCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public AddPeerCommand addPeer() { - return new AddPeerCommandImpl(threadPool, this::connect); + return new AddPeerCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public ModifyPeerCommand modifyPeer() { - return new ModifyPeerCommandImpl(threadPool, this::connect); + return new ModifyPeerCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public RemovePeerCommand removePeer() { - return new RemovePeerCommandImpl(threadPool, this::connect); + return new RemovePeerCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public ListPeerNotesCommand listPeerNotes() { - return new ListPeerNotesCommandImpl(threadPool, this::connect); + return new ListPeerNotesCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public ModifyPeerNoteCommand modifyPeerNote() { - return new ModifyPeerNoteCommandImpl(threadPool, this::connect); + return new ModifyPeerNoteCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public LoadPluginCommand loadPlugin() { - return new LoadPluginCommandImpl(threadPool, this::connect); + return new LoadPluginCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public ReloadPluginCommand reloadPlugin() { - return new ReloadPluginCommandImpl(threadPool, this::connect); + return new ReloadPluginCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public RemovePluginCommand removePlugin() { - return new RemovePluginCommandImpl(threadPool, this::connect); + return new RemovePluginCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public GetPluginInfoCommand getPluginInfo() { - return new GetPluginInfoCommandImpl(threadPool, this::connect); + return new GetPluginInfoCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } @Override public SubscribeUskCommand subscribeUsk() { - return new SubscribeUskCommandImpl(threadPool, this::connect, activeSubscriptions); + return new SubscribeUskCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate, activeSubscriptions); } private UnsubscribeUskCommand unsubscribeUsk() { - return new UnsubscribeUskCommandImpl(threadPool, this::connect); + return new UnsubscribeUskCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate); } } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java index c2095b3..cac2535 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/GetConfigCommandImpl.java @@ -5,6 +5,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.ConfigData; import net.pterodactylus.fcp.GetConfig; @@ -22,6 +23,7 @@ public class GetConfigCommandImpl implements GetConfigCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final Supplier identifierGenerator; private final AtomicBoolean withCurrent = new AtomicBoolean(); private final AtomicBoolean withDefaults = new AtomicBoolean(); private final AtomicBoolean withSortOrder = new AtomicBoolean(); @@ -31,9 +33,10 @@ public class GetConfigCommandImpl implements GetConfigCommand { private final AtomicBoolean withLongDescription = new AtomicBoolean(); private final AtomicBoolean withDataTypes = new AtomicBoolean(); - public GetConfigCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public GetConfigCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + this.identifierGenerator = identifierGenerator; } @Override @@ -90,7 +93,7 @@ public class GetConfigCommandImpl implements GetConfigCommand { } private ConfigData executeDialog() throws IOException, ExecutionException, InterruptedException { - GetConfig getConfig = new GetConfig(new RandomIdentifierGenerator().generate()); + GetConfig getConfig = new GetConfig(identifierGenerator.get()); getConfig.setWithCurrent(withCurrent.get()); getConfig.setWithDefaults(withDefaults.get()); getConfig.setWithSortOrder(withSortOrder.get()); diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommandImpl.java index 3e9e850..12f936d 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommandImpl.java @@ -5,6 +5,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.GetNode; import net.pterodactylus.fcp.NodeData; @@ -22,13 +23,15 @@ public class GetNodeCommandImpl implements GetNodeCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final Supplier identifierGenerator; private final AtomicBoolean giveOpennetRef = new AtomicBoolean(false); private final AtomicBoolean includePrivate = new AtomicBoolean(false); private final AtomicBoolean includeVolatile = new AtomicBoolean(false); - public GetNodeCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public GetNodeCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + this.identifierGenerator = identifierGenerator; } @Override @@ -55,7 +58,7 @@ public class GetNodeCommandImpl implements GetNodeCommand { } private NodeData executeDialog() throws InterruptedException, ExecutionException, IOException { - GetNode getNode = new GetNode(new RandomIdentifierGenerator().generate(), giveOpennetRef.get(), + GetNode getNode = new GetNode(identifierGenerator.get(), giveOpennetRef.get(), includePrivate.get(), includeVolatile.get()); try (GetNodeDialog getNodeDialog = new GetNodeDialog()) { return getNodeDialog.send(getNode).get(); diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/GetPluginInfoCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/GetPluginInfoCommandImpl.java index 67c3e30..49db826 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/GetPluginInfoCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/GetPluginInfoCommandImpl.java @@ -6,6 +6,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.GetPluginInfo; import net.pterodactylus.fcp.PluginInfo; @@ -22,14 +23,14 @@ import com.google.common.util.concurrent.MoreExecutors; */ public class GetPluginInfoCommandImpl implements GetPluginInfoCommand { - private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator(); private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; - private final GetPluginInfo getPluginInfo = new GetPluginInfo(IDENTIFIER.generate()); + private final GetPluginInfo getPluginInfo; - public GetPluginInfoCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public GetPluginInfoCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + getPluginInfo = new GetPluginInfo(identifierGenerator.get()); } @Override diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ListPeerCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ListPeerCommandImpl.java index 3fb6b74..fc9aeec 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ListPeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ListPeerCommandImpl.java @@ -3,8 +3,10 @@ package net.pterodactylus.fcp.quelaton; import java.io.IOException; import java.util.Optional; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.ListPeer; import net.pterodactylus.fcp.Peer; @@ -12,6 +14,7 @@ import net.pterodactylus.fcp.UnknownNodeIdentifier; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; /** * Default {@link ListPeerCommand} implementation based on {@link FcpDialog}. @@ -22,11 +25,13 @@ public class ListPeerCommandImpl implements ListPeerCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final Supplier identifierGenerator; private final AtomicReference nodeIdentifier = new AtomicReference<>(); - public ListPeerCommandImpl(ListeningExecutorService threadPool, ConnectionSupplier connectionSupplier) { - this.threadPool = threadPool; + public ListPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { + this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + this.identifierGenerator = identifierGenerator; } @Override @@ -52,7 +57,7 @@ public class ListPeerCommandImpl implements ListPeerCommand { } private Optional executeDialog() throws IOException, ExecutionException, InterruptedException { - ListPeer listPeer = new ListPeer(new RandomIdentifierGenerator().generate(), nodeIdentifier.get()); + ListPeer listPeer = new ListPeer(identifierGenerator.get(), nodeIdentifier.get()); try (ListPeerDialog listPeerDialog = new ListPeerDialog()) { return Optional.ofNullable(listPeerDialog.send(listPeer).get()); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ListPeerNotesCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ListPeerNotesCommandImpl.java index 0cd0483..8e1df8c 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ListPeerNotesCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ListPeerNotesCommandImpl.java @@ -6,6 +6,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.EndListPeerNotes; import net.pterodactylus.fcp.ListPeerNotes; @@ -25,11 +26,13 @@ public class ListPeerNotesCommandImpl implements ListPeerNotesCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final Supplier identifierGenerator; private final AtomicReference nodeIdentifier = new AtomicReference<>(); - public ListPeerNotesCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public ListPeerNotesCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + this.identifierGenerator = identifierGenerator; } @Override @@ -55,8 +58,7 @@ public class ListPeerNotesCommandImpl implements ListPeerNotesCommand { } private Optional executeDialog() throws IOException, ExecutionException, InterruptedException { - ListPeerNotes listPeerNotes = - new ListPeerNotes(new RandomIdentifierGenerator().generate(), nodeIdentifier.get()); + ListPeerNotes listPeerNotes = new ListPeerNotes(identifierGenerator.get(), nodeIdentifier.get()); try (ListPeerNotesDialog listPeerNotesDialog = new ListPeerNotesDialog()) { return listPeerNotesDialog.send(listPeerNotes).get(); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ListPeersCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ListPeersCommandImpl.java index f4907f0..6a352d5 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ListPeersCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ListPeersCommandImpl.java @@ -6,6 +6,7 @@ import java.util.HashSet; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; import net.pterodactylus.fcp.EndListPeers; import net.pterodactylus.fcp.ListPeers; @@ -24,12 +25,14 @@ public class ListPeersCommandImpl implements ListPeersCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final Supplier identifierGenerator; private final AtomicBoolean includeMetadata = new AtomicBoolean(false); private final AtomicBoolean includeVolatile = new AtomicBoolean(false); - public ListPeersCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public ListPeersCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + this.identifierGenerator = identifierGenerator; } @Override @@ -50,8 +53,7 @@ public class ListPeersCommandImpl implements ListPeersCommand { } private Collection executeDialog() throws InterruptedException, ExecutionException, IOException { - String identifier = new RandomIdentifierGenerator().generate(); - ListPeers listPeers = new ListPeers(identifier, includeMetadata.get(), includeVolatile.get()); + ListPeers listPeers = new ListPeers(identifierGenerator.get(), includeMetadata.get(), includeVolatile.get()); try (ListPeersDialog listPeersDialog = new ListPeersDialog()) { return listPeersDialog.send(listPeers).get(); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/LoadPluginCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/LoadPluginCommandImpl.java index bd5acd7..9c9e64e 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/LoadPluginCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/LoadPluginCommandImpl.java @@ -6,6 +6,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.LoadPlugin; import net.pterodactylus.fcp.LoadPlugin.OfficialSource; @@ -24,14 +25,14 @@ import com.google.common.util.concurrent.MoreExecutors; */ public class LoadPluginCommandImpl implements LoadPluginCommand { - private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator(); private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; - private final LoadPlugin loadPlugin = new LoadPlugin(IDENTIFIER.generate()); + private final LoadPlugin loadPlugin; - public LoadPluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public LoadPluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + loadPlugin = new LoadPlugin(identifierGenerator.get()); } @Override diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyConfigCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyConfigCommandImpl.java index 3de75c2..6733d25 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyConfigCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyConfigCommandImpl.java @@ -5,6 +5,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.ConfigData; import net.pterodactylus.fcp.ModifyConfig; @@ -20,13 +21,14 @@ import com.google.common.util.concurrent.MoreExecutors; */ public class ModifyConfigCommandImpl implements ModifyConfigCommand { - private final ModifyConfig modifyConfig = new ModifyConfig(new RandomIdentifierGenerator().generate()); private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final ModifyConfig modifyConfig; - public ModifyConfigCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public ModifyConfigCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + modifyConfig = new ModifyConfig(identifierGenerator.get()); } @Override diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java index a675280..9fff845 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java @@ -6,6 +6,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.ModifyPeer; import net.pterodactylus.fcp.Peer; @@ -24,6 +25,7 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final Supplier identifierGenerator; private final AtomicReference nodeIdentifier = new AtomicReference<>(); private final AtomicReference enabled = new AtomicReference<>(); private final AtomicReference allowLocalAddresses = new AtomicReference<>(); @@ -31,9 +33,10 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand { private final AtomicReference listenOnly = new AtomicReference<>(); private final AtomicReference ignoreSource = new AtomicReference<>(); - public ModifyPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public ModifyPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + this.identifierGenerator = identifierGenerator; } @Override @@ -119,7 +122,7 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand { } private Optional executeDialog() throws IOException, ExecutionException, InterruptedException { - ModifyPeer modifyPeer = new ModifyPeer(new RandomIdentifierGenerator().generate(), nodeIdentifier.get()); + ModifyPeer modifyPeer = new ModifyPeer(identifierGenerator.get(), nodeIdentifier.get()); Optional.ofNullable(enabled.get()).ifPresent(enabled -> modifyPeer.setEnabled(enabled)); Optional.ofNullable(allowLocalAddresses.get()).ifPresent(allowed -> modifyPeer.setAllowLocalAddresses(allowed)); Optional.ofNullable(burstOnly.get()).ifPresent(burstOnly -> modifyPeer.setBurstOnly(burstOnly)); diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommandImpl.java index 6e6dcc2..a3b9aa1 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommandImpl.java @@ -6,6 +6,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.FreenetBase64; import net.pterodactylus.fcp.ModifyPeerNote; @@ -26,15 +27,16 @@ import com.google.common.util.concurrent.MoreExecutors; public class ModifyPeerNoteCommandImpl implements ModifyPeerNoteCommand { private static final FreenetBase64 BASE_64 = new FreenetBase64(); - private static final RandomIdentifierGenerator RANDOM_IDENTIFIER_GENERATOR = new RandomIdentifierGenerator(); private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final Supplier identifierGenerator; private final AtomicReference nodeIdentifier = new AtomicReference<>(); private final AtomicReference darknetComment = new AtomicReference<>(); - public ModifyPeerNoteCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public ModifyPeerNoteCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + this.identifierGenerator = identifierGenerator; } @Override @@ -70,7 +72,7 @@ public class ModifyPeerNoteCommandImpl implements ModifyPeerNoteCommand { private Boolean executeDialog() throws IOException, ExecutionException, InterruptedException { ModifyPeerNote modifyPeerNote = - new ModifyPeerNote(RANDOM_IDENTIFIER_GENERATOR.generate(), nodeIdentifier.get()); + new ModifyPeerNote(identifierGenerator.get(), nodeIdentifier.get()); modifyPeerNote.setPeerNoteType(PeerNoteType.PRIVATE_DARKNET_COMMENT); modifyPeerNote.setNoteText(BASE_64.encode(darknetComment.get().getBytes(StandardCharsets.UTF_8))); try (ModifyPeerNoteDialog modifyPeerNoteDialog = new ModifyPeerNoteDialog()) { diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommandImpl.java index 9b08f34..a05963c 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommandImpl.java @@ -6,6 +6,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.PluginInfo; import net.pterodactylus.fcp.ProtocolError; @@ -22,14 +23,14 @@ import com.google.common.util.concurrent.MoreExecutors; */ public class ReloadPluginCommandImpl implements ReloadPluginCommand { - private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator(); private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; - private final ReloadPlugin reloadPlugin = new ReloadPlugin(IDENTIFIER.generate()); + private final ReloadPlugin reloadPlugin; - public ReloadPluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public ReloadPluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + reloadPlugin = new ReloadPlugin(identifierGenerator.get()); } @Override diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java index b12e225..e5083d7 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java @@ -5,6 +5,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import net.pterodactylus.fcp.PeerRemoved; import net.pterodactylus.fcp.RemovePeer; @@ -23,11 +24,13 @@ public class RemovePeerCommandImpl implements RemovePeerCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final Supplier identifierGenerator; private final AtomicReference nodeIdentifier = new AtomicReference<>(); - public RemovePeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public RemovePeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + this.identifierGenerator = identifierGenerator; } @Override @@ -53,7 +56,7 @@ public class RemovePeerCommandImpl implements RemovePeerCommand { } private boolean executeDialog() throws IOException, ExecutionException, InterruptedException { - RemovePeer removePeer = new RemovePeer(new RandomIdentifierGenerator().generate(), nodeIdentifier.get()); + RemovePeer removePeer = new RemovePeer(identifierGenerator.get(), nodeIdentifier.get()); try (RemovePeerDialog removePeerDialog = new RemovePeerDialog()) { return removePeerDialog.send(removePeer).get(); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePluginCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePluginCommandImpl.java index 026682d..2135e2e 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePluginCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePluginCommandImpl.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; import net.pterodactylus.fcp.PluginRemoved; import net.pterodactylus.fcp.ProtocolError; @@ -20,14 +21,14 @@ import com.google.common.util.concurrent.MoreExecutors; */ public class RemovePluginCommandImpl implements RemovePluginCommand { - private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator(); private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; - private final RemovePlugin removePlugin = new RemovePlugin(IDENTIFIER.generate()); + private final RemovePlugin removePlugin; - public RemovePluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public RemovePluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + removePlugin = new RemovePlugin(identifierGenerator.get()); } @Override diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/SubscribeUskCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/SubscribeUskCommandImpl.java index 598aeec..f314247 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/SubscribeUskCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/SubscribeUskCommandImpl.java @@ -5,6 +5,7 @@ import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; import net.pterodactylus.fcp.IdentifierCollision; import net.pterodactylus.fcp.SubscribeUSK; @@ -21,18 +22,18 @@ import com.google.common.util.concurrent.MoreExecutors; */ public class SubscribeUskCommandImpl implements SubscribeUskCommand { - private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator(); private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; - private final SubscribeUSK subscribeUSK = new SubscribeUSK(IDENTIFIER.generate()); + private final SubscribeUSK subscribeUSK; private final ActiveSubscriptions activeSubscriptions; public SubscribeUskCommandImpl( - ExecutorService threadPool, ConnectionSupplier connectionSupplier, + ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator, ActiveSubscriptions activeSubscriptions) { this.activeSubscriptions = activeSubscriptions; this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + subscribeUSK = new SubscribeUSK(identifierGenerator.get()); } @Override diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/UnsubscribeUskCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/UnsubscribeUskCommandImpl.java index 44450b5..3755a05 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/UnsubscribeUskCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/UnsubscribeUskCommandImpl.java @@ -3,6 +3,7 @@ package net.pterodactylus.fcp.quelaton; import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; +import java.util.function.Supplier; import net.pterodactylus.fcp.UnsubscribeUSK; @@ -17,14 +18,14 @@ import com.google.common.util.concurrent.MoreExecutors; */ public class UnsubscribeUskCommandImpl implements UnsubscribeUskCommand { - private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator(); private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; - private final UnsubscribeUSK unsubscribeUSK = new UnsubscribeUSK(IDENTIFIER.generate()); + private final UnsubscribeUSK unsubscribeUSK; - public UnsubscribeUskCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { + public UnsubscribeUskCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier identifierGenerator) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); this.connectionSupplier = connectionSupplier; + unsubscribeUSK = new UnsubscribeUSK(identifierGenerator.get()); } @Override -- 2.7.4