Trying to fix Server Context Cache

This commit is contained in:
luca.frosini 2023-11-10 14:37:43 +01:00
parent e8a98dd54a
commit 084e223669
1 changed files with 23 additions and 7 deletions

View File

@ -6,6 +6,8 @@ import java.util.Calendar;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.UUID; import java.util.UUID;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException; import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
@ -35,12 +37,12 @@ public class ServerContextCache extends ContextCache {
private static Logger logger = LoggerFactory.getLogger(ServerContextCache.class); private static Logger logger = LoggerFactory.getLogger(ServerContextCache.class);
protected List<Context> contextsNoMeta;
protected Map<UUID, Context> uuidToContextNoMeta;
protected List<Context> contextsMetaPrivacy; protected List<Context> contextsMetaPrivacy;
protected Map<UUID, Context> uuidToContextMetaPrivacy; protected Map<UUID, Context> uuidToContextMetaPrivacy;
protected List<Context> contextsNoMeta;
protected Map<UUID, Context> uuidToContextNoMeta;
protected boolean includeMeta; protected boolean includeMeta;
protected static ServerContextCache singleton; protected static ServerContextCache singleton;
@ -60,10 +62,11 @@ public class ServerContextCache extends ContextCache {
@Override @Override
protected void cleanCache(Calendar now) { protected void cleanCache(Calendar now) {
super.cleanCache(now); super.cleanCache(now);
contextsNoMeta = null;
uuidToContextNoMeta = new LinkedHashMap<>();
contextsMetaPrivacy = null; contextsMetaPrivacy = null;
uuidToContextMetaPrivacy = new LinkedHashMap<>(); uuidToContextMetaPrivacy = null;
contextsNoMeta = null;
uuidToContextNoMeta = null;
} }
public ServerContextCache() { public ServerContextCache() {
@ -148,8 +151,14 @@ public class ServerContextCache extends ContextCache {
@Override @Override
public void setContexts(List<Context> contexts) { public void setContexts(List<Context> contexts) {
this.contexts = new ArrayList<>(); this.contexts = new ArrayList<>();
this.contextsNoMeta = new ArrayList<>(); this.uuidToContext = new LinkedHashMap<>();
this.contextsMetaPrivacy = new ArrayList<>(); this.contextsMetaPrivacy = new ArrayList<>();
this.uuidToContextMetaPrivacy = new LinkedHashMap<>();
this.contextsNoMeta = new ArrayList<>();
this.uuidToContextNoMeta = new LinkedHashMap<>();
ObjectMapper objectMapper = ElementMapper.getObjectMapper(); ObjectMapper objectMapper = ElementMapper.getObjectMapper();
@ -223,5 +232,12 @@ public class ServerContextCache extends ContextCache {
this.contextFullNameToUUID.put(fullName, uuid); this.contextFullNameToUUID.put(fullName, uuid);
} }
SortedSet<String> contextFullNames = new TreeSet<String>(contextFullNameToUUID.keySet());
for(String contextFullName : contextFullNames) {
UUID uuid = contextFullNameToUUID.get(contextFullName);
Context context = uuidToContext.get(uuid);
contextsTree.addNode(context);
}
} }
} }