From 8ba2bf0baac5fa3b872c4a1f5020a15d825e525c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 6 Jul 2015 06:46:39 +0200 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20access=20fcpConnection=20contain?= =?utf8?q?er=20directly?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/fcp/quelaton/DefaultFcpClient.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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(); -- 2.7.4