From: David ‘Bombe’ Roden Date: Sat, 27 Jun 2015 23:08:53 +0000 (+0200) Subject: Refactoring X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=aa659bcdaa77efb1e902a279a3505964d26e09ff;p=jFCPlib.git Refactoring --- diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java index e0c6e12..9cb0981 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java @@ -80,18 +80,33 @@ public class DefaultFcpClient implements FcpClient { public Future execute() { return threadPool.submit(() -> { connect(); - GenerateSSK generateSSK = new GenerateSSK(); - AtomicReference keyPair = new AtomicReference<>(); + Sequence sequence = new Sequence(); FcpReplySequence replySequence = new FcpReplySequence(threadPool, fcpConnection.get()); - replySequence.handle(SSKKeypair.class) - .with((message) -> keyPair.set( - new FcpKeyPair(message.getRequestURI(), message.getInsertURI()))); - replySequence.waitFor(() -> keyPair.get() != null); - replySequence.send(generateSSK).get(); - return keyPair.get(); + replySequence.handle(SSKKeypair.class).with(sequence::handleSSKKeypair); + replySequence.waitFor(sequence::isFinished); + replySequence.send(new GenerateSSK()).get(); + return sequence.getKeyPair(); }); } + private class Sequence { + + private AtomicReference keyPair = new AtomicReference<>(); + + public void handleSSKKeypair(SSKKeypair sskKeypair) { + keyPair.set(new FcpKeyPair(sskKeypair.getRequestURI(), sskKeypair.getInsertURI())); + } + + public boolean isFinished() { + return keyPair.get() != null; + } + + public FcpKeyPair getKeyPair() { + return keyPair.get(); + } + + } + } }