X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fquelaton%2FClientHelloImpl.java;h=3ded685a0c4877af938292fcb23ad28e4601c5f4;hb=54b77863a4a3d63a0298157a87afb09007b03fc4;hp=9c03291c170b7cd68cafba96f7afcfb215ae0163;hpb=4db57d2ff54b90a07f3659e31bad206d07576136;p=jFCPlib.git diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ClientHelloImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ClientHelloImpl.java index 9c03291..3ded685 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ClientHelloImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ClientHelloImpl.java @@ -3,11 +3,9 @@ package net.pterodactylus.fcp.quelaton; import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import net.pterodactylus.fcp.ClientHello; -import net.pterodactylus.fcp.CloseConnectionDuplicateClientName; import net.pterodactylus.fcp.FcpConnection; import net.pterodactylus.fcp.NodeHello; @@ -16,7 +14,7 @@ import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; /** - * Internal ClientHello implementation based on {@link FcpReplySequence}. + * Internal ClientHello implementation based on {@link FcpDialog}. * * @author David ‘Bombe’ Roden */ @@ -39,15 +37,14 @@ public class ClientHelloImpl { } private ListenableFuture execute() { - return threadPool.submit(() -> establishConnection()); + return threadPool.submit(this::establishConnection); } private FcpConnection establishConnection() throws IOException { FcpConnection connection = new FcpConnection(hostname, port); connection.connect(); - ClientHelloReplySequence nodeHelloSequence = new ClientHelloReplySequence(connection); ClientHello clientHello = new ClientHello(clientName.get(), "2.0"); - try { + try (ClientHelloDialog nodeHelloSequence = new ClientHelloDialog(connection)) { if (nodeHelloSequence.send(clientHello).get()) { return connection; } @@ -59,18 +56,17 @@ public class ClientHelloImpl { throw new IOException(String.format("Could not connect to %s:%d.", hostname, port)); } - private class ClientHelloReplySequence extends FcpReplySequence { + private class ClientHelloDialog extends FcpDialog { private final AtomicReference receivedNodeHello = new AtomicReference<>(); - private final AtomicBoolean receivedClosed = new AtomicBoolean(); - public ClientHelloReplySequence(FcpConnection connection) { + public ClientHelloDialog(FcpConnection connection) { super(ClientHelloImpl.this.threadPool, connection); } @Override protected boolean isFinished() { - return receivedNodeHello.get() != null || receivedClosed.get(); + return receivedNodeHello.get() != null; } @Override @@ -83,12 +79,6 @@ public class ClientHelloImpl { receivedNodeHello.set(nodeHello); } - @Override - protected void consumeCloseConnectionDuplicateClientName( - CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) { - receivedClosed.set(true); - } - } }