1 package net.pterodactylus.fcp.quelaton;
3 import java.io.IOException;
4 import java.util.concurrent.ExecutorService;
5 import java.util.concurrent.Future;
6 import java.util.concurrent.atomic.AtomicReference;
8 import net.pterodactylus.fcp.FcpKeyPair;
9 import net.pterodactylus.fcp.GenerateSSK;
10 import net.pterodactylus.fcp.SSKKeypair;
13 * Implementation of the {@link GenerateKeypairCommand}.
15 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
17 class GenerateKeypairCommandImpl implements GenerateKeypairCommand {
19 private final ExecutorService threadPool;
20 private final ConnectionSupplier connectionSupplier;
22 GenerateKeypairCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
23 this.threadPool = threadPool;
24 this.connectionSupplier = connectionSupplier;
28 public Future<FcpKeyPair> execute() {
29 return threadPool.submit(() -> new FcpKeyPairReplySequence().send(new GenerateSSK()).get());
32 private class FcpKeyPairReplySequence extends FcpReplySequence<FcpKeyPair> {
34 private AtomicReference<FcpKeyPair> keyPair = new AtomicReference<>();
36 public FcpKeyPairReplySequence() throws IOException {
37 super(GenerateKeypairCommandImpl.this.threadPool, GenerateKeypairCommandImpl.this.connectionSupplier.get());
41 protected boolean isFinished() {
42 return keyPair.get() != null;
46 protected FcpKeyPair getResult() {
51 protected void consumeSSKKeypair(SSKKeypair sskKeypair) {
52 keyPair.set(new FcpKeyPair(sskKeypair.getRequestURI(), sskKeypair.getInsertURI()));