X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fquelaton%2FAddPeerCommandImpl.java;h=a54f1666a926ab4dd2eb567e094c9d80823b9d67;hb=3351e5f36c74fc270152688c251ea32365808222;hp=fbfb3142b6e9f8b90a38996b38fa46793a3edcb9;hpb=021111b5eb02f1071aaa306f172e833b73890011;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 fbfb314..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);
@@ -35,7 +37,7 @@ public class AddPeerCommandImpl implements AddPeerCommand {
}
@Override
- public Executable> withFile(File file) {
+ public Executable> fromFile(File file) {
this.file.set(file);
return this::execute;
}
@@ -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<>();