Reconnect when connection fails
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / quelaton / GetNodeCommandImpl.java
index 23c5ad0..2447179 100644 (file)
@@ -1,6 +1,7 @@
 package net.pterodactylus.fcp.quelaton;
 
 import java.io.IOException;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
@@ -23,6 +24,7 @@ public class GetNodeCommandImpl implements GetNodeCommand {
        private final ConnectionSupplier connectionSupplier;
        private final AtomicBoolean giveOpennetRef = new AtomicBoolean(false);
        private final AtomicBoolean includePrivate = new AtomicBoolean(false);
+       private final AtomicBoolean includeVolatile = new AtomicBoolean(false);
 
        public GetNodeCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
                this.threadPool = MoreExecutors.listeningDecorator(threadPool);
@@ -42,10 +44,22 @@ public class GetNodeCommandImpl implements GetNodeCommand {
        }
 
        @Override
+       public GetNodeCommand includeVolatile() {
+               includeVolatile.set(true);
+               return this;
+       }
+
+       @Override
        public ListenableFuture<NodeData> execute() {
+               return threadPool.submit(this::executeSequence);
+       }
+
+       private NodeData executeSequence() throws InterruptedException, ExecutionException, IOException {
                GetNode getNode = new GetNode(new RandomIdentifierGenerator().generate(), giveOpennetRef.get(),
-                       includePrivate.get(), false);
-               return threadPool.submit(() -> new GetNodeReplySequence().send(getNode).get());
+                       includePrivate.get(), includeVolatile.get());
+               try (GetNodeReplySequence getNodeReplySequence = new GetNodeReplySequence()) {
+                       return getNodeReplySequence.send(getNode).get();
+               }
        }
 
        private class GetNodeReplySequence extends FcpReplySequence<NodeData> {