1 package net.pterodactylus.fcp.quelaton;
3 import java.io.IOException;
4 import java.util.concurrent.ExecutionException;
5 import java.util.concurrent.ExecutorService;
7 import net.pterodactylus.fcp.FcpKeyPair;
8 import net.pterodactylus.fcp.GenerateSSK;
9 import net.pterodactylus.fcp.SSKKeypair;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.ListeningExecutorService;
13 import com.google.common.util.concurrent.MoreExecutors;
16 * Implementation of the {@link GenerateKeypairCommand}.
18 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
20 class GenerateKeypairCommandImpl implements GenerateKeypairCommand {
22 private final ListeningExecutorService threadPool;
23 private final ConnectionSupplier connectionSupplier;
25 GenerateKeypairCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
26 this.threadPool = MoreExecutors.listeningDecorator(threadPool);
27 this.connectionSupplier = connectionSupplier;
31 public ListenableFuture<FcpKeyPair> execute() {
32 return threadPool.submit(this::executeDialog);
35 private FcpKeyPair executeDialog() throws InterruptedException, ExecutionException, IOException {
36 try (FcpKeyPairDialog fcpKeyPairDialog = new FcpKeyPairDialog()) {
37 return fcpKeyPairDialog.send(new GenerateSSK()).get();
41 private class FcpKeyPairDialog extends FcpDialog<FcpKeyPair> {
43 public FcpKeyPairDialog() throws IOException {
44 super(GenerateKeypairCommandImpl.this.threadPool, GenerateKeypairCommandImpl.this.connectionSupplier.get(), null);
48 protected void consumeSSKKeypair(SSKKeypair sskKeypair) {
49 setResult(new FcpKeyPair(sskKeypair.getRequestURI(), sskKeypair.getInsertURI()));