X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fquelaton%2FGenerateKeypairCommandImpl.java;h=5f8cd5bc8117f19e3e9ceb1de5edd4fbc34e5164;hb=1d2048edc0856425c91337bb103ee526de663e9d;hp=6f5df331d86d065a2fab6f880a4cf3320fc8337b;hpb=7980851d84be2f31d0db3837619eb1548c3847c7;p=jFCPlib.git diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/GenerateKeypairCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/GenerateKeypairCommandImpl.java index 6f5df33..5f8cd5b 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/GenerateKeypairCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/GenerateKeypairCommandImpl.java @@ -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 execute() { - return threadPool.submit(() -> new FcpKeyPairReplySequence().send(new GenerateSSK()).get()); + public ListenableFuture execute() { + return threadPool.submit(this::executeSequence); + } + + private FcpKeyPair executeSequence() throws InterruptedException, ExecutionException, IOException { + try (FcpKeyPairDialog fcpKeyPairDialog = new FcpKeyPairDialog()) { + return fcpKeyPairDialog.send(new GenerateSSK()).get(); + } } - private class FcpKeyPairReplySequence extends FcpReplySequence { + private class FcpKeyPairDialog extends FcpDialog { private AtomicReference keyPair = new AtomicReference<>(); - public FcpKeyPairReplySequence() throws IOException { + public FcpKeyPairDialog() throws IOException { super(GenerateKeypairCommandImpl.this.threadPool, GenerateKeypairCommandImpl.this.connectionSupplier.get()); }