From: David ‘Bombe’ Roden Date: Sun, 28 Sep 2014 18:21:57 +0000 (+0200) Subject: Use an atomic reference instead of volatile. X-Git-Tag: 0.9-rc1^2~3^2~92 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d5573f473d20716e78700cde845d3d5a55aa6f3f;p=Sone.git Use an atomic reference instead of volatile. --- 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) {