X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fquelaton%2FAddPeerCommandImpl.java;h=b34d2ba2c99808aa80bf67c7abdd77f595642a66;hb=7a3be5ca037785f4f1acb225381578db12d15eb1;hp=4fab83c089a1eece7a8df4fb0c48520fe8ee9dae;hpb=91de0a638af50527fc314ed97a095d1beaf36866;p=jFCPlib.git 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();