From aa659bcdaa77efb1e902a279a3505964d26e09ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 28 Jun 2015 01:08:53 +0200 Subject: [PATCH] Refactoring --- .../fcp/quelaton/DefaultFcpClient.java | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) 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(); + } + + } + } } -- 2.7.4