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}.
*
*/
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::executeSequence);
+ }
+
+ private FcpKeyPair executeSequence() 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());
}