From: David ‘Bombe’ Roden Date: Mon, 6 Jul 2015 04:46:39 +0000 (+0200) Subject: Don’t access fcpConnection container directly X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=8ba2bf0baac5fa3b872c4a1f5020a15d825e525c;p=jFCPlib.git Don’t access fcpConnection container directly --- diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java index 3a33730..6edce63 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java @@ -47,11 +47,14 @@ public class DefaultFcpClient implements FcpClient { this.expectedVersion = expectedVersion; } - private void connect() throws IOException { - if (fcpConnection.get() != null) { - return; + private FcpConnection connect() throws IOException { + FcpConnection fcpConnection = this.fcpConnection.get(); + if (fcpConnection != null) { + return fcpConnection; } - fcpConnection.compareAndSet(null, createConnection()); + fcpConnection = createConnection(); + this.fcpConnection.compareAndSet(null, fcpConnection); + return fcpConnection; } private FcpConnection createConnection() throws IOException { @@ -97,7 +100,7 @@ public class DefaultFcpClient implements FcpClient { public Future execute() { return threadPool.submit(() -> { connect(); - return new FcpReplySequence(threadPool, fcpConnection.get()) { + return new FcpReplySequence(threadPool, connect()) { private AtomicReference keyPair = new AtomicReference<>(); @Override @@ -199,8 +202,7 @@ public class DefaultFcpClient implements FcpClient { clientGet.setGlobal(true); } return threadPool.submit(() -> { - connect(); - FcpReplySequence> replySequence = new FcpReplySequence>(threadPool, fcpConnection.get()) { + FcpReplySequence> replySequence = new FcpReplySequence>(threadPool, connect()) { private final AtomicBoolean finished = new AtomicBoolean(); private final AtomicBoolean failed = new AtomicBoolean();