Use marker variable for whether the contexts have been loaded.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 29 Oct 2010 20:12:35 +0000 (22:12 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 29 Oct 2010 20:12:35 +0000 (22:12 +0200)
src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java

index 2909936..090bf7f 100644 (file)
@@ -45,6 +45,9 @@ public class Identity {
        /** The contexts of the identity. */
        protected final Set<String> contexts = Collections.synchronizedSet(new HashSet<String>());
 
+       /** Whether the contexts have already been loaded. */
+       private volatile boolean contextsLoaded = false;
+
        /** The properties of the identity. */
        private final Map<String, String> properties = Collections.synchronizedMap(new HashMap<String, String>());
 
@@ -121,8 +124,9 @@ public class Identity {
         *             plugin
         */
        public Set<String> getContexts(boolean forceReload) throws PluginException {
-               if (contexts.isEmpty() || forceReload) {
+               if (!contextsLoaded || forceReload) {
                        Set<String> contexts = webOfTrustConnector.loadIdentityContexts(this);
+                       contextsLoaded = true;
                        this.contexts.clear();
                        this.contexts.addAll(contexts);
                }