From d5573f473d20716e78700cde845d3d5a55aa6f3f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 28 Sep 2014 20:21:57 +0200 Subject: [PATCH] Use an atomic reference instead of volatile. --- src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index e49537b..1ddf0a9 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; @@ -78,7 +79,7 @@ public class FcpInterface { private final AtomicBoolean active = new AtomicBoolean(); /** What function full access is required for. */ - private volatile FullAccessRequired fullAccessRequired = FullAccessRequired.ALWAYS; + private final AtomicReference fullAccessRequired = new AtomicReference(FullAccessRequired.ALWAYS); /** All available FCP commands. */ private final Map commands = Collections.synchronizedMap(new HashMap()); @@ -131,7 +132,7 @@ public class FcpInterface { @VisibleForTesting FullAccessRequired getFullAccessRequired() { - return fullAccessRequired; + return fullAccessRequired.get(); } /** @@ -141,7 +142,7 @@ public class FcpInterface { * The action level for which full FCP access is required */ public void setFullAccessRequired(FullAccessRequired fullAccessRequired) { - this.fullAccessRequired = checkNotNull(fullAccessRequired, "fullAccessRequired must not be null"); + this.fullAccessRequired.set(checkNotNull(fullAccessRequired, "fullAccessRequired must not be null")); } // @@ -172,7 +173,7 @@ public class FcpInterface { return; } AbstractSoneCommand command = commands.get(parameters.get("Message")); - if ((accessType == FredPluginFCP.ACCESS_FCP_RESTRICTED) && (((fullAccessRequired == FullAccessRequired.WRITING) && command.requiresWriteAccess()) || (fullAccessRequired == FullAccessRequired.ALWAYS))) { + if ((accessType == FredPluginFCP.ACCESS_FCP_RESTRICTED) && (((fullAccessRequired.get() == FullAccessRequired.WRITING) && command.requiresWriteAccess()) || (fullAccessRequired.get() == FullAccessRequired.ALWAYS))) { try { sendReply(pluginReplySender, null, new ErrorResponse(401, "Not authorized")); } catch (PluginNotFoundException pnfe1) { -- 2.7.4