Rename all remaining occurences of “sequence” to “dialog”
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / quelaton / GenerateKeypairCommandImpl.java
index 6f5df33..69fcf63 100644 (file)
@@ -1,14 +1,18 @@
 package net.pterodactylus.fcp.quelaton;
 
 import java.io.IOException;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicReference;
 
 import net.pterodactylus.fcp.FcpKeyPair;
 import net.pterodactylus.fcp.GenerateSSK;
 import net.pterodactylus.fcp.SSKKeypair;
 
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+
 /**
  * Implementation of the {@link GenerateKeypairCommand}.
  *
@@ -16,24 +20,30 @@ import net.pterodactylus.fcp.SSKKeypair;
  */
 class GenerateKeypairCommandImpl implements GenerateKeypairCommand {
 
-       private final ExecutorService threadPool;
+       private final ListeningExecutorService threadPool;
        private final ConnectionSupplier connectionSupplier;
 
        GenerateKeypairCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
-               this.threadPool = threadPool;
+               this.threadPool = MoreExecutors.listeningDecorator(threadPool);
                this.connectionSupplier = connectionSupplier;
        }
 
        @Override
-       public Future<FcpKeyPair> execute() {
-               return threadPool.submit(() -> new FcpKeyPairReplySequence().send(new GenerateSSK()).get());
+       public ListenableFuture<FcpKeyPair> execute() {
+               return threadPool.submit(this::executeDialog);
+       }
+
+       private FcpKeyPair executeDialog() throws InterruptedException, ExecutionException, IOException {
+               try (FcpKeyPairDialog fcpKeyPairDialog = new FcpKeyPairDialog()) {
+                       return fcpKeyPairDialog.send(new GenerateSSK()).get();
+               }
        }
 
-       private class FcpKeyPairReplySequence extends FcpReplySequence<FcpKeyPair> {
+       private class FcpKeyPairDialog extends FcpDialog<FcpKeyPair> {
 
                private AtomicReference<FcpKeyPair> keyPair = new AtomicReference<>();
 
-               public FcpKeyPairReplySequence() throws IOException {
+               public FcpKeyPairDialog() throws IOException {
                        super(GenerateKeypairCommandImpl.this.threadPool, GenerateKeypairCommandImpl.this.connectionSupplier.get());
                }