diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/GeoExplorerApplicationHostnameGuavaCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/GeoExplorerApplicationURLGuavaCache.java similarity index 64% rename from src/main/java/org/gcube/datatransfer/resolver/caches/GeoExplorerApplicationHostnameGuavaCache.java rename to src/main/java/org/gcube/datatransfer/resolver/caches/GeoExplorerApplicationURLGuavaCache.java index b4b47e7..eb87d6d 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/GeoExplorerApplicationHostnameGuavaCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/GeoExplorerApplicationURLGuavaCache.java @@ -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,29 +24,34 @@ 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 geoExplorerApplicationURLCache; static { + + CacheLoader loader = new CacheLoader () { + @Override + public String load(String scope) + throws Exception { + logger.info(GeoExplorerApplicationURLGuavaCache.class.getSimpleName() +" instancied"); + return loadGeoExplorerApplicationURL(scope); + } + }; + + RemovalListener removalListener = new RemovalListener() { + public void onRemoval(RemovalNotification removal) { + logger.info(GeoExplorerApplicationURLGuavaCache.class.getSimpleName() +" cache expired"); + } + }; + geoExplorerApplicationURLCache = - CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite( - 1, TimeUnit.HOURS).build( - new CacheLoader() { - - @Override - public String load(String scope) - throws Exception { - - return loadGeoExplorerApplicationURL(scope); - } - }); - - logger.info(GeoExplorerApplicationHostnameGuavaCache.class.getSimpleName() +" instancied"); + CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite( + 1, TimeUnit.HOURS).removalListener(removalListener). + build(loader); } - /** * Gets the cache. * diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/GisViewerApplicationHostnameGuavaCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/GisViewerApplicationURLGuavaCache.java similarity index 91% rename from src/main/java/org/gcube/datatransfer/resolver/caches/GisViewerApplicationHostnameGuavaCache.java rename to src/main/java/org/gcube/datatransfer/resolver/caches/GisViewerApplicationURLGuavaCache.java index 23a0f9b..158b5ec 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/GisViewerApplicationHostnameGuavaCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/GisViewerApplicationURLGuavaCache.java @@ -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 gisViewerApplicationURLCache; static { @@ -40,7 +40,7 @@ public class GisViewerApplicationHostnameGuavaCache { } }); - logger.info(GisViewerApplicationHostnameGuavaCache.class.getSimpleName() +" instancied"); + logger.info(GisViewerApplicationURLGuavaCache.class.getSimpleName() +" instancied"); } diff --git a/src/main/java/org/gcube/datatransfer/resolver/listeners/UriResolverStartupListener.java b/src/main/java/org/gcube/datatransfer/resolver/listeners/UriResolverStartupListener.java index 36c753d..3f3dd4b 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/listeners/UriResolverStartupListener.java +++ b/src/main/java/org/gcube/datatransfer/resolver/listeners/UriResolverStartupListener.java @@ -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) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java index 4e0a1bb..44cea79 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java @@ -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