X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fquelaton%2FAddPeerCommandImpl.java;h=a54f1666a926ab4dd2eb567e094c9d80823b9d67;hb=1d2048edc0856425c91337bb103ee526de663e9d;hp=a4f4452d478efb8c6e94ba311202cb38844a0f63;hpb=6871db2ad88d2a1941341ffbc453c627590b8431;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 a4f4452..a54f166 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/AddPeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/AddPeerCommandImpl.java @@ -10,6 +10,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import net.pterodactylus.fcp.AddPeer; +import net.pterodactylus.fcp.NodeRef; import net.pterodactylus.fcp.Peer; import net.pterodactylus.fcp.ProtocolError; @@ -18,7 +19,7 @@ import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; /** - * Default {@link AddPeerCommand} implementation based on {@link FcpReplySequence}. + * Default {@link AddPeerCommand} implementation based on {@link FcpDialog}. * * @author David ‘Bombe’ Roden */ @@ -28,6 +29,7 @@ public class AddPeerCommandImpl implements AddPeerCommand { private final ConnectionSupplier connectionSupplier; private final AtomicReference file = new AtomicReference<>(); private final AtomicReference url = new AtomicReference<>(); + private final AtomicReference nodeRef = new AtomicReference<>(); public AddPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); @@ -46,23 +48,31 @@ public class AddPeerCommandImpl implements AddPeerCommand { return this::execute; } + @Override + public Executable> fromNodeRef(NodeRef nodeRef) { + this.nodeRef.set(nodeRef); + return this::execute; + } + private ListenableFuture> execute() { return threadPool.submit(this::executeSequence); } private Optional executeSequence() throws IOException, ExecutionException, InterruptedException { - AddPeer addPeer = null; + AddPeer addPeer; if (file.get() != null) { addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), file.get().getPath()); } else if (url.get() != null) { addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), url.get()); + } else { + addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), nodeRef.get()); } try (AddPeerSequence addPeerSequence = new AddPeerSequence()) { return addPeerSequence.send(addPeer).get(); } } - private class AddPeerSequence extends FcpReplySequence> { + private class AddPeerSequence extends FcpDialog> { private final AtomicBoolean finished = new AtomicBoolean(); private final AtomicReference peer = new AtomicReference<>();