improved context cache
This commit is contained in:
parent
f6f2402b07
commit
e7e251dac8
|
@ -3,8 +3,10 @@ package org.gcube.informationsystem.resourceregistry.api.contexts;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -49,11 +51,11 @@ public class ContextCache {
|
||||||
cleanCache(Calendar.getInstance());
|
cleanCache(Calendar.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanCache(Calendar now) {
|
protected void cleanCache(Calendar now) {
|
||||||
this.contexts = null;
|
this.contexts = null;
|
||||||
this.uuidToContext = new HashMap<>();
|
this.uuidToContext = new LinkedHashMap<>();
|
||||||
this.uuidToContextFullName = new HashMap<>();
|
this.uuidToContextFullName = new LinkedHashMap<>();
|
||||||
this.contextFullNameToUUID = new HashMap<>();
|
this.contextFullNameToUUID = new TreeMap<>();
|
||||||
this.creationTime = Calendar.getInstance();
|
this.creationTime = Calendar.getInstance();
|
||||||
this.creationTime.setTimeInMillis(now.getTimeInMillis());
|
this.creationTime.setTimeInMillis(now.getTimeInMillis());
|
||||||
this.expiringTime = Calendar.getInstance();
|
this.expiringTime = Calendar.getInstance();
|
||||||
|
@ -78,6 +80,10 @@ public class ContextCache {
|
||||||
cleanCache(now);
|
cleanCache(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ContextCacheRenewal getContextCacheRenewal() {
|
||||||
|
return contextCacheRenewal;
|
||||||
|
}
|
||||||
|
|
||||||
public void setContextCacheRenewal(ContextCacheRenewal contextCacheRenewal) {
|
public void setContextCacheRenewal(ContextCacheRenewal contextCacheRenewal) {
|
||||||
if(this.contextCacheRenewal==null) {
|
if(this.contextCacheRenewal==null) {
|
||||||
this.contextCacheRenewal = contextCacheRenewal;
|
this.contextCacheRenewal = contextCacheRenewal;
|
||||||
|
@ -106,7 +112,7 @@ public class ContextCache {
|
||||||
return contexts;
|
return contexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setContexts(List<Context> contexts) {
|
protected void setContexts(List<Context> contexts) {
|
||||||
this.contexts = new ArrayList<>();
|
this.contexts = new ArrayList<>();
|
||||||
|
|
||||||
for(Context c : contexts) {
|
for(Context c : contexts) {
|
||||||
|
@ -144,7 +150,7 @@ public class ContextCache {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getContextFullName(Context context) {
|
protected String getContextFullName(Context context) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
IsParentOf ipo = context.getParent();
|
IsParentOf ipo = context.getParent();
|
||||||
if(ipo!=null) {
|
if(ipo!=null) {
|
||||||
|
|
|
@ -49,8 +49,7 @@ public class ContextUtility {
|
||||||
return uuids;
|
return uuids;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getContextFullNameSet(Collection<UUID> uuids) throws Exception {
|
public static Set<String> getContextFullNameSet(ContextCache contextCache, Collection<UUID> uuids) throws Exception {
|
||||||
ContextCache contextCache = ContextCache.getInstance();
|
|
||||||
Set<String> contextFullNames = new HashSet<>();
|
Set<String> contextFullNames = new HashSet<>();
|
||||||
try {
|
try {
|
||||||
Map<UUID, String> uuidToContextFullNameAssociation = contextCache.getUUIDToContextFullNameAssociation();
|
Map<UUID, String> uuidToContextFullNameAssociation = contextCache.getUUIDToContextFullNameAssociation();
|
||||||
|
|
Loading…
Reference in New Issue