X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fquelaton%2FListPeersCommandImpl.java;h=921c0faf9dcffeeaa594b596082e9ec6a00b2fd7;hb=f85a8ea030d563b573acca6f1a117ec87c82cc4e;hp=5638b98504d161e40977dea555ddc64ce1156dcc;hpb=e7fe15a311e143a2154bfc62ed21cdf591b9a27f;p=jFCPlib.git
diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ListPeersCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ListPeersCommandImpl.java
index 5638b98..921c0fa 100644
--- a/src/main/java/net/pterodactylus/fcp/quelaton/ListPeersCommandImpl.java
+++ b/src/main/java/net/pterodactylus/fcp/quelaton/ListPeersCommandImpl.java
@@ -3,19 +3,20 @@ package net.pterodactylus.fcp.quelaton;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import net.pterodactylus.fcp.EndListPeers;
import net.pterodactylus.fcp.ListPeers;
import net.pterodactylus.fcp.Peer;
+import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
/**
- * Default {@link ListPeersCommand} implementation based on {@link FcpReplySequence}.
+ * Default {@link ListPeersCommand} implementation based on {@link FcpDialog}.
*
* @author David âBombeâ Roden
*/
@@ -23,6 +24,8 @@ public class ListPeersCommandImpl implements ListPeersCommand {
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final AtomicBoolean includeMetadata = new AtomicBoolean(false);
+ private final AtomicBoolean includeVolatile = new AtomicBoolean(false);
public ListPeersCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
@@ -30,18 +33,36 @@ public class ListPeersCommandImpl implements ListPeersCommand {
}
@Override
- public Future> execute() {
+ public ListPeersCommand includeMetadata() {
+ includeMetadata.set(true);
+ return this;
+ }
+
+ @Override
+ public ListPeersCommand includeVolatile() {
+ includeVolatile.set(true);
+ return this;
+ }
+
+ @Override
+ public ListenableFuture> execute() {
+ return threadPool.submit(this::executeSequence);
+ }
+
+ private Collection executeSequence() throws InterruptedException, ExecutionException, IOException {
String identifier = new RandomIdentifierGenerator().generate();
- ListPeers listPeers = new ListPeers(identifier);
- return threadPool.submit(() -> new ListPeersReplySequence().send(listPeers).get());
+ ListPeers listPeers = new ListPeers(identifier, includeMetadata.get(), includeVolatile.get());
+ try (ListPeersDialog listPeersDialog = new ListPeersDialog()) {
+ return listPeersDialog.send(listPeers).get();
+ }
}
- private class ListPeersReplySequence extends FcpReplySequence> {
+ private class ListPeersDialog extends FcpDialog> {
private final Collection peers = new HashSet<>();
private final AtomicBoolean finished = new AtomicBoolean(false);
- public ListPeersReplySequence() throws IOException {
+ public ListPeersDialog() throws IOException {
super(threadPool, connectionSupplier.get());
}