import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
+import com.google.inject.Singleton;
/**
* Implementation of an FCP interface for other clients or plugins to
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
+@Singleton
public class FcpInterface {
/**
private static final Logger logger = Logging.getLogger(FcpInterface.class);
/** Whether the FCP interface is currently active. */
- private volatile boolean active;
+ private final AtomicBoolean active = new AtomicBoolean();
/** What function full access is required for. */
private volatile FullAccessRequired fullAccessRequired = FullAccessRequired.ALWAYS;
@VisibleForTesting
boolean isActive() {
- return active;
+ return active.get();
}
/**
* deactivate the FCP interface
*/
public void setActive(boolean active) {
- this.active = active;
+ this.active.set(active);
+ }
+
+ @VisibleForTesting
+ FullAccessRequired getFullAccessRequired() {
+ return fullAccessRequired;
}
/**
* {@link FredPluginFCP#ACCESS_FCP_RESTRICTED}
*/
public void handle(PluginReplySender pluginReplySender, SimpleFieldSet parameters, Bucket data, int accessType) {
- if (!active) {
+ if (!active.get()) {
try {
sendReply(pluginReplySender, null, new ErrorResponse(400, "FCP Interface deactivated"));
} catch (PluginNotFoundException pnfe1) {
}
+ public class SetFullAccessRequired implements OptionWatcher<Integer> {
+
+ @Override
+ public void optionChanged(Option<Integer> option, Integer oldValue, Integer newValue) {
+ setFullAccessRequired(FullAccessRequired.values()[newValue]);
+ }
+
+ }
+
}