enhancement on caching
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@173952 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
31f5762545
commit
37d0816954
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.datatransfer.resolver.caches;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.cache.RemovalListener;
|
||||||
|
import com.google.common.cache.RemovalNotification;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Nov 5, 2018
|
||||||
|
*/
|
||||||
|
public class CatalogueApplicationProfilesGuavaCache {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(CatalogueApplicationProfilesGuavaCache.class);
|
||||||
|
private static LoadingCache<String, String> catalogueApplicationProfiles;
|
||||||
|
|
||||||
|
static{
|
||||||
|
|
||||||
|
CacheLoader<String, String> loader = new CacheLoader<String, String>(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String load(String arg0)
|
||||||
|
throws Exception {
|
||||||
|
|
||||||
|
logger.info(CatalogueApplicationProfilesGuavaCache.class.getSimpleName() +" loaded");
|
||||||
|
//ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(scopeToEncDecr, true);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
RemovalListener<String, String> removalListener = new RemovalListener<String, String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemoval(RemovalNotification<String, String> arg0) {
|
||||||
|
|
||||||
|
logger.info(CatalogueApplicationProfilesGuavaCache.class.getSimpleName() +" cache expired");
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
catalogueApplicationProfiles = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
||||||
|
1, TimeUnit.HOURS).removalListener(removalListener).
|
||||||
|
build(loader);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,8 @@ import com.google.common.cache.RemovalNotification;
|
||||||
public class GeoExplorerApplicationURLGuavaCache {
|
public class GeoExplorerApplicationURLGuavaCache {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(GeoExplorerApplicationURLGuavaCache.class);
|
private static Logger logger = LoggerFactory.getLogger(GeoExplorerApplicationURLGuavaCache.class);
|
||||||
|
|
||||||
|
//A cache (Scope, GeoExplorer-URL)
|
||||||
private static LoadingCache<String, String> geoExplorerApplicationURLCache;
|
private static LoadingCache<String, String> geoExplorerApplicationURLCache;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -35,7 +37,7 @@ public class GeoExplorerApplicationURLGuavaCache {
|
||||||
@Override
|
@Override
|
||||||
public String load(String scope)
|
public String load(String scope)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
logger.info(GeoExplorerApplicationURLGuavaCache.class.getSimpleName() +" instancied");
|
logger.info(GeoExplorerApplicationURLGuavaCache.class.getSimpleName() +" loaded");
|
||||||
return loadGeoExplorerApplicationURL(scope);
|
return loadGeoExplorerApplicationURL(scope);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -48,8 +50,10 @@ public class GeoExplorerApplicationURLGuavaCache {
|
||||||
|
|
||||||
geoExplorerApplicationURLCache =
|
geoExplorerApplicationURLCache =
|
||||||
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
||||||
1, TimeUnit.HOURS).removalListener(removalListener).
|
1, TimeUnit.DAYS).removalListener(removalListener).
|
||||||
build(loader);
|
build(loader);
|
||||||
|
|
||||||
|
logger.info(GeoExplorerApplicationURLGuavaCache.class.getSimpleName() +" instancied");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,13 +10,14 @@ import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter;
|
||||||
import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.GeonetworkLoginLevel;
|
import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.GeonetworkLoginLevel;
|
||||||
import org.gcube.datatransfer.resolver.gis.GeonetworkInstance;
|
import org.gcube.datatransfer.resolver.gis.GeonetworkInstance;
|
||||||
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
|
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
|
||||||
import org.gcube.datatransfer.resolver.listeners.UriResolverStartupListener;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.cache.RemovalListener;
|
||||||
|
import com.google.common.cache.RemovalNotification;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,26 +26,36 @@ import com.google.common.cache.LoadingCache;
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
* Nov 2, 2018
|
* Nov 2, 2018
|
||||||
*/
|
*/
|
||||||
public class GeoentworkInstanceGuavaCache {
|
public class GeonetworkInstanceGuavaCache {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(UriResolverStartupListener.class);
|
private static Logger logger = LoggerFactory.getLogger(GeonetworkInstanceGuavaCache.class);
|
||||||
|
|
||||||
|
//A cache (Scope, GeonetworkInstance)
|
||||||
private static LoadingCache<String, GeonetworkInstance> geonetworkInstancesCache;
|
private static LoadingCache<String, GeonetworkInstance> geonetworkInstancesCache;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
||||||
|
CacheLoader<String, GeonetworkInstance> loader = new CacheLoader<String, GeonetworkInstance> () {
|
||||||
|
@Override
|
||||||
|
public GeonetworkInstance load(String scope)
|
||||||
|
throws Exception {
|
||||||
|
logger.info(GeonetworkInstanceGuavaCache.class.getSimpleName() +" loaded");
|
||||||
|
return loadGeonetworkInstance(scope);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RemovalListener<String, GeonetworkInstance> removalListener = new RemovalListener<String, GeonetworkInstance>() {
|
||||||
|
public void onRemoval(RemovalNotification<String, GeonetworkInstance> removal) {
|
||||||
|
logger.info(GeonetworkInstanceGuavaCache.class.getSimpleName() +" cache expired");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
geonetworkInstancesCache =
|
geonetworkInstancesCache =
|
||||||
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
||||||
10, TimeUnit.MINUTES).build(
|
1, TimeUnit.DAYS).removalListener(removalListener).
|
||||||
new CacheLoader<String, GeonetworkInstance>() {
|
build(loader);
|
||||||
|
|
||||||
@Override
|
logger.info(GeonetworkInstanceGuavaCache.class.getSimpleName() +" instancied");
|
||||||
public GeonetworkInstance load(String scope)
|
|
||||||
throws Exception {
|
|
||||||
|
|
||||||
return loadGeonetworkInstance(scope);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.info(GeoentworkInstanceGuavaCache.class.getSimpleName() +" instancied");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ import org.slf4j.LoggerFactory;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.cache.RemovalListener;
|
||||||
|
import com.google.common.cache.RemovalNotification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class GisViewerApplicationHostnameGuavaCache.
|
* The Class GisViewerApplicationHostnameGuavaCache.
|
||||||
|
@ -24,21 +26,31 @@ import com.google.common.cache.LoadingCache;
|
||||||
public class GisViewerApplicationURLGuavaCache {
|
public class GisViewerApplicationURLGuavaCache {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(GisViewerApplicationURLGuavaCache.class);
|
private static Logger logger = LoggerFactory.getLogger(GisViewerApplicationURLGuavaCache.class);
|
||||||
|
|
||||||
|
//A cache (Scope, GisViewerApplication-URL)
|
||||||
private static LoadingCache<String, String> gisViewerApplicationURLCache;
|
private static LoadingCache<String, String> gisViewerApplicationURLCache;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
||||||
|
CacheLoader<String, String> loader = new CacheLoader<String, String> () {
|
||||||
|
@Override
|
||||||
|
public String load(String scope)
|
||||||
|
throws Exception {
|
||||||
|
logger.info(GisViewerApplicationURLGuavaCache.class.getSimpleName() +" loaded");
|
||||||
|
return loadGisViewerApplicationURL(scope);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RemovalListener<String, String> removalListener = new RemovalListener<String, String>() {
|
||||||
|
public void onRemoval(RemovalNotification<String, String> removal) {
|
||||||
|
logger.info(GisViewerApplicationURLGuavaCache.class.getSimpleName() +" cache expired");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
gisViewerApplicationURLCache =
|
gisViewerApplicationURLCache =
|
||||||
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
||||||
1, TimeUnit.HOURS).build(
|
1, TimeUnit.DAYS).removalListener(removalListener).
|
||||||
new CacheLoader<String, String>() {
|
build(loader);
|
||||||
|
|
||||||
@Override
|
|
||||||
public String load(String scope)
|
|
||||||
throws Exception {
|
|
||||||
|
|
||||||
return loadGisViewerApplicationURL(scope);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.info(GisViewerApplicationURLGuavaCache.class.getSimpleName() +" instancied");
|
logger.info(GisViewerApplicationURLGuavaCache.class.getSimpleName() +" instancied");
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.ServletContextListener;
|
import javax.servlet.ServletContextListener;
|
||||||
import javax.servlet.annotation.WebListener;
|
import javax.servlet.annotation.WebListener;
|
||||||
|
|
||||||
import org.gcube.datatransfer.resolver.caches.GeoentworkInstanceGuavaCache;
|
import org.gcube.datatransfer.resolver.caches.GeonetworkInstanceGuavaCache;
|
||||||
import org.gcube.datatransfer.resolver.caches.GisViewerApplicationURLGuavaCache;
|
import org.gcube.datatransfer.resolver.caches.GisViewerApplicationURLGuavaCache;
|
||||||
import org.gcube.datatransfer.resolver.gis.property.ApplicationProfileGenericResourceReader;
|
import org.gcube.datatransfer.resolver.gis.property.ApplicationProfileGenericResourceReader;
|
||||||
import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException;
|
import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException;
|
||||||
|
@ -56,7 +56,7 @@ public class UriResolverStartupListener implements ServletContextListener {
|
||||||
logger.info("Context initialized!");
|
logger.info("Context initialized!");
|
||||||
gisViewerProfile = loadApplicationProfile(event.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
|
gisViewerProfile = loadApplicationProfile(event.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
|
||||||
geoExplorerProfile = loadApplicationProfile(event.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
|
geoExplorerProfile = loadApplicationProfile(event.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
|
||||||
new GeoentworkInstanceGuavaCache();
|
new GeonetworkInstanceGuavaCache();
|
||||||
new GisViewerApplicationURLGuavaCache();
|
new GisViewerApplicationURLGuavaCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.datatransfer.resolver.caches.GeoExplorerApplicationURLGuavaCache;
|
import org.gcube.datatransfer.resolver.caches.GeoExplorerApplicationURLGuavaCache;
|
||||||
import org.gcube.datatransfer.resolver.caches.GeoentworkInstanceGuavaCache;
|
import org.gcube.datatransfer.resolver.caches.GeonetworkInstanceGuavaCache;
|
||||||
import org.gcube.datatransfer.resolver.caches.GisViewerApplicationURLGuavaCache;
|
import org.gcube.datatransfer.resolver.caches.GisViewerApplicationURLGuavaCache;
|
||||||
import org.gcube.datatransfer.resolver.gis.GeonetworkInstance;
|
import org.gcube.datatransfer.resolver.gis.GeonetworkInstance;
|
||||||
import org.gcube.datatransfer.resolver.gis.MetadataConverter;
|
import org.gcube.datatransfer.resolver.gis.MetadataConverter;
|
||||||
|
@ -203,13 +203,13 @@ public class GisResolver {
|
||||||
protected GeonetworkInstance getCachedGeonetworkInstance(String scope) throws Exception{
|
protected GeonetworkInstance getCachedGeonetworkInstance(String scope) throws Exception{
|
||||||
|
|
||||||
logger.info("Attempt to get the GeonetworkInstance from cache by scope: "+scope);
|
logger.info("Attempt to get the GeonetworkInstance from cache by scope: "+scope);
|
||||||
GeonetworkInstance geonInstance = GeoentworkInstanceGuavaCache.getCache().get(scope);
|
GeonetworkInstance geonInstance = GeonetworkInstanceGuavaCache.getCache().get(scope);
|
||||||
|
|
||||||
if(geonInstance==null){
|
if(geonInstance==null){
|
||||||
logger.info("GeonetworkInstance is null in cache, reading from library...");
|
logger.info("GeonetworkInstance is null in cache, reading from library...");
|
||||||
try {
|
try {
|
||||||
geonInstance = GeoentworkInstanceGuavaCache.loadGeonetworkInstance(scope);
|
geonInstance = GeonetworkInstanceGuavaCache.loadGeonetworkInstance(scope);
|
||||||
GeoentworkInstanceGuavaCache.getCache().put(scope, geonInstance);
|
GeonetworkInstanceGuavaCache.getCache().put(scope, geonInstance);
|
||||||
logger.info("Updated GeonetworkInstance cache! Scope "+scope+" linking "+geonInstance);
|
logger.info("Updated GeonetworkInstance cache! Scope "+scope+" linking "+geonInstance);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("An error occurred on getting GeonetworkInstance for scope: "+scope, e);
|
logger.error("An error occurred on getting GeonetworkInstance for scope: "+scope, e);
|
||||||
|
|
Loading…
Reference in New Issue