From: David ‘Bombe’ Roden Date: Mon, 6 Jul 2015 05:06:28 +0000 (+0200) Subject: Refactor anonymous to inner class X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=0594300da2613fc58e794b655b2dd9b27c074b0b;p=jFCPlib.git Refactor anonymous to inner class --- diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java index 30dac91..9c7a705 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java @@ -27,7 +27,7 @@ public class DefaultFcpClient implements FcpClient { private final Supplier expectedVersion; public DefaultFcpClient(ExecutorService threadPool, String hostname, int port, Supplier clientName, - Supplier expectedVersion) { + Supplier expectedVersion) { this.threadPool = threadPool; this.hostname = hostname; this.port = port; @@ -48,25 +48,7 @@ public class DefaultFcpClient implements FcpClient { private FcpConnection createConnection() throws IOException { FcpConnection connection = new FcpConnection(hostname, port); connection.connect(); - FcpReplySequence nodeHelloSequence = new FcpReplySequence(threadPool, connection) { - private final AtomicReference receivedNodeHello = new AtomicReference<>(); - private final AtomicBoolean receivedClosed = new AtomicBoolean(); - @Override - protected boolean isFinished() { - return receivedNodeHello.get() != null || receivedClosed.get(); - } - - @Override - protected void consumeNodeHello(NodeHello nodeHello) { - receivedNodeHello.set(nodeHello); - } - - @Override - protected void consumeCloseConnectionDuplicateClientName( - CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) { - receivedClosed.set(true); - } - }; + FcpReplySequence nodeHelloSequence = new ClientHelloReplySequence(connection); ClientHello clientHello = new ClientHello(clientName.get(), expectedVersion.get()); try { nodeHelloSequence.send(clientHello).get(); @@ -87,5 +69,34 @@ public class DefaultFcpClient implements FcpClient { return new ClientGetCommandImpl(threadPool, this::connect); } + private class ClientHelloReplySequence extends FcpReplySequence { + + private final AtomicReference receivedNodeHello; + private final AtomicBoolean receivedClosed; + + public ClientHelloReplySequence(FcpConnection connection) { + super(DefaultFcpClient.this.threadPool, connection); + receivedNodeHello = new AtomicReference<>(); + receivedClosed = new AtomicBoolean(); + } + + @Override + protected boolean isFinished() { + return receivedNodeHello.get() != null || receivedClosed.get(); + } + + @Override + protected void consumeNodeHello(NodeHello nodeHello) { + receivedNodeHello.set(nodeHello); + } + + @Override + protected void consumeCloseConnectionDuplicateClientName( + CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) { + receivedClosed.set(true); + } + + } + }