Fixing context cache usage

This commit is contained in:
Luca Frosini 2020-11-04 17:39:26 +01:00
parent e4cde05f77
commit 23b6d836a3
1 changed files with 25 additions and 12 deletions

View File

@ -58,8 +58,19 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
gxHTTPStringRequest.queryParams(queryParams);
}
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
@Override
public List<Context> renew() throws ResourceRegistryException {
return getAllContextFromServer();
}
};
public ResourceRegistryPublisherImpl(String address) {
this.address = address;
ContextCache contextCache = ContextCache.getInstance();
contextCache.setContextCacheRenewal(contextCacheRenewal);
}
public List<Context> getAllContextFromServer() throws ResourceRegistryException {
@ -90,20 +101,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
}
@Override
public List<Context> getAllContext() throws ResourceRegistryException {
ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
@Override
public List<Context> renew() throws ResourceRegistryException {
return getAllContextFromServer();
}
};
ContextCache contextCache = ContextCache.getInstance();
contextCache.setContextCacheRenewal(contextCacheRenewal);
return contextCache.getContexts();
}
@ -139,7 +139,20 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException {
return ContextCache.getInstance().getContextByUUID(uuid);
ContextCache contextCache = ContextCache.getInstance();
Context context = ContextCache.getInstance().getContextByUUID(uuid);;
if(context == null) {
context = getContextFromServer(uuid.toString());
contextCache.cleanCache();
contextCache.refreshContextsIfNeeded();
Context c = contextCache.getContextByUUID(context.getHeader().getUUID());
if(c!=null){
context = c;
}else {
logger.error("Context with UUID {} is {}. It is possibile to get it from the server but not from the cache. This is very strange and should not occur.", uuid, context);
}
}
return context;
}
@Override