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