Use a single identifier generator in all commands
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / quelaton / ListPeerNotesCommandImpl.java
index 426917a..8e1df8c 100644 (file)
@@ -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<String> identifierGenerator;
        private final AtomicReference<String> nodeIdentifier = new AtomicReference<>();
 
-       public ListPeerNotesCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+       public ListPeerNotesCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
                this.threadPool = MoreExecutors.listeningDecorator(threadPool);
                this.connectionSupplier = connectionSupplier;
+               this.identifierGenerator = identifierGenerator;
        }
 
        @Override
@@ -51,12 +54,11 @@ public class ListPeerNotesCommandImpl implements ListPeerNotesCommand {
        }
 
        private ListenableFuture<Optional<PeerNote>> execute() {
-               return threadPool.submit(this::executeSequence);
+               return threadPool.submit(this::executeDialog);
        }
 
-       private Optional<PeerNote> executeSequence() throws IOException, ExecutionException, InterruptedException {
-               ListPeerNotes listPeerNotes =
-                       new ListPeerNotes(new RandomIdentifierGenerator().generate(), nodeIdentifier.get());
+       private Optional<PeerNote> executeDialog() throws IOException, ExecutionException, InterruptedException {
+               ListPeerNotes listPeerNotes = new ListPeerNotes(identifierGenerator.get(), nodeIdentifier.get());
                try (ListPeerNotesDialog listPeerNotesDialog = new ListPeerNotesDialog()) {
                        return listPeerNotesDialog.send(listPeerNotes).get();
                }