just performed a refactor
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@173951 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0cbd1b0bd3
commit
31f5762545
|
@ -14,6 +14,8 @@ 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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -22,28 +24,33 @@ import com.google.common.cache.LoadingCache;
|
|||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Nov 2, 2018
|
||||
*/
|
||||
public class GeoExplorerApplicationHostnameGuavaCache {
|
||||
public class GeoExplorerApplicationURLGuavaCache {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(GeoExplorerApplicationHostnameGuavaCache.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(GeoExplorerApplicationURLGuavaCache.class);
|
||||
private static LoadingCache<String, String> geoExplorerApplicationURLCache;
|
||||
|
||||
static {
|
||||
geoExplorerApplicationURLCache =
|
||||
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
||||
1, TimeUnit.HOURS).build(
|
||||
new CacheLoader<String, String>() {
|
||||
|
||||
CacheLoader<String, String> loader = new CacheLoader<String, String> () {
|
||||
@Override
|
||||
public String load(String scope)
|
||||
throws Exception {
|
||||
|
||||
logger.info(GeoExplorerApplicationURLGuavaCache.class.getSimpleName() +" instancied");
|
||||
return loadGeoExplorerApplicationURL(scope);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
logger.info(GeoExplorerApplicationHostnameGuavaCache.class.getSimpleName() +" instancied");
|
||||
RemovalListener<String, String> removalListener = new RemovalListener<String, String>() {
|
||||
public void onRemoval(RemovalNotification<String, String> removal) {
|
||||
logger.info(GeoExplorerApplicationURLGuavaCache.class.getSimpleName() +" cache expired");
|
||||
}
|
||||
};
|
||||
|
||||
geoExplorerApplicationURLCache =
|
||||
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
||||
1, TimeUnit.HOURS).removalListener(removalListener).
|
||||
build(loader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cache.
|
|
@ -21,9 +21,9 @@ import com.google.common.cache.LoadingCache;
|
|||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Nov 2, 2018
|
||||
*/
|
||||
public class GisViewerApplicationHostnameGuavaCache {
|
||||
public class GisViewerApplicationURLGuavaCache {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(GisViewerApplicationHostnameGuavaCache.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(GisViewerApplicationURLGuavaCache.class);
|
||||
private static LoadingCache<String, String> gisViewerApplicationURLCache;
|
||||
|
||||
static {
|
||||
|
@ -40,7 +40,7 @@ public class GisViewerApplicationHostnameGuavaCache {
|
|||
}
|
||||
});
|
||||
|
||||
logger.info(GisViewerApplicationHostnameGuavaCache.class.getSimpleName() +" instancied");
|
||||
logger.info(GisViewerApplicationURLGuavaCache.class.getSimpleName() +" instancied");
|
||||
}
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ import javax.servlet.ServletContextListener;
|
|||
import javax.servlet.annotation.WebListener;
|
||||
|
||||
import org.gcube.datatransfer.resolver.caches.GeoentworkInstanceGuavaCache;
|
||||
import org.gcube.datatransfer.resolver.caches.GisViewerApplicationHostnameGuavaCache;
|
||||
import org.gcube.datatransfer.resolver.caches.GisViewerApplicationURLGuavaCache;
|
||||
import org.gcube.datatransfer.resolver.gis.property.ApplicationProfileGenericResourceReader;
|
||||
import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -57,7 +57,7 @@ public class UriResolverStartupListener implements ServletContextListener {
|
|||
gisViewerProfile = loadApplicationProfile(event.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
|
||||
geoExplorerProfile = loadApplicationProfile(event.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
|
||||
new GeoentworkInstanceGuavaCache();
|
||||
new GisViewerApplicationHostnameGuavaCache();
|
||||
new GisViewerApplicationURLGuavaCache();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -15,9 +15,9 @@ import javax.ws.rs.core.Context;
|
|||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datatransfer.resolver.caches.GeoExplorerApplicationHostnameGuavaCache;
|
||||
import org.gcube.datatransfer.resolver.caches.GeoExplorerApplicationURLGuavaCache;
|
||||
import org.gcube.datatransfer.resolver.caches.GeoentworkInstanceGuavaCache;
|
||||
import org.gcube.datatransfer.resolver.caches.GisViewerApplicationHostnameGuavaCache;
|
||||
import org.gcube.datatransfer.resolver.caches.GisViewerApplicationURLGuavaCache;
|
||||
import org.gcube.datatransfer.resolver.gis.GeonetworkInstance;
|
||||
import org.gcube.datatransfer.resolver.gis.MetadataConverter;
|
||||
import org.gcube.datatransfer.resolver.gis.entity.GisLayerItem;
|
||||
|
@ -155,11 +155,11 @@ public class GisResolver {
|
|||
protected String getGisViewerApplicationURL(String scope) throws Exception{
|
||||
|
||||
logger.info("Tentative of recovering gis viewer application hostname from cache for scope: "+scope);
|
||||
String gisViewerAppHostname = GisViewerApplicationHostnameGuavaCache.getCache().get(scope);
|
||||
String gisViewerAppHostname = GisViewerApplicationURLGuavaCache.getCache().get(scope);
|
||||
if(gisViewerAppHostname==null){
|
||||
logger.info("Gis viewer application hostname is null, reading from application profile..");
|
||||
String url = GisViewerApplicationHostnameGuavaCache.loadGisViewerApplicationURL(scope);
|
||||
GisViewerApplicationHostnameGuavaCache.getCache().put(scope, url);
|
||||
String url = GisViewerApplicationURLGuavaCache.loadGisViewerApplicationURL(scope);
|
||||
GisViewerApplicationURLGuavaCache.getCache().put(scope, url);
|
||||
logger.info("Updated GisViewerApplication cache! Scope "+scope+" linking "+url);
|
||||
return url;
|
||||
}else
|
||||
|
@ -234,11 +234,11 @@ public class GisResolver {
|
|||
protected String getGeoExplorerApplicationURL(String scope) throws Exception{
|
||||
|
||||
logger.info("Tentative of recovering geo explorer application hostname from cache for scope: "+scope);
|
||||
String geoExplorerApplicationHostname = GeoExplorerApplicationHostnameGuavaCache.getCache().get(scope);
|
||||
String geoExplorerApplicationHostname = GeoExplorerApplicationURLGuavaCache.getCache().get(scope);
|
||||
if(geoExplorerApplicationHostname==null){
|
||||
logger.info("GeoExplorer application hostname is null, reading from application profile..");
|
||||
String url = GeoExplorerApplicationHostnameGuavaCache.loadGeoExplorerApplicationURL(scope);
|
||||
GeoExplorerApplicationHostnameGuavaCache.getCache().put(scope, url);
|
||||
String url = GeoExplorerApplicationURLGuavaCache.loadGeoExplorerApplicationURL(scope);
|
||||
GeoExplorerApplicationURLGuavaCache.getCache().put(scope, url);
|
||||
logger.info("Updated GeoExplorerApplication cache! Scope "+scope+" linking "+url);
|
||||
return url;
|
||||
}else
|
||||
|
|
Loading…
Reference in New Issue