78 lines
2.1 KiB
Java
78 lines
2.1 KiB
Java
|
/**
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
package org.gcube.datatransfer.resolver.caches;
|
||
|
|
||
|
import java.util.concurrent.TimeUnit;
|
||
|
|
||
|
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
|
||
|
import org.gcube.datatransfer.resolver.listeners.UriResolverStartupListener;
|
||
|
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;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* The Class GeoExplorerApplicationHostnameGuavaCache.
|
||
|
*
|
||
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||
|
* Nov 2, 2018
|
||
|
*/
|
||
|
public class GeoExplorerApplicationHostnameGuavaCache {
|
||
|
|
||
|
private static Logger logger = LoggerFactory.getLogger(GeoExplorerApplicationHostnameGuavaCache.class);
|
||
|
private static LoadingCache<String, String> geoExplorerApplicationURLCache;
|
||
|
|
||
|
static {
|
||
|
geoExplorerApplicationURLCache =
|
||
|
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
||
|
1, TimeUnit.HOURS).build(
|
||
|
new CacheLoader<String, String>() {
|
||
|
|
||
|
@Override
|
||
|
public String load(String scope)
|
||
|
throws Exception {
|
||
|
|
||
|
return loadGeoExplorerApplicationURL(scope);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
logger.info(GeoExplorerApplicationHostnameGuavaCache.class.getSimpleName() +" instancied");
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Gets the cache.
|
||
|
*
|
||
|
* @return the cache
|
||
|
*/
|
||
|
public static LoadingCache<String, String> getCache() {
|
||
|
|
||
|
return geoExplorerApplicationURLCache;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Load geo explorer application url.
|
||
|
*
|
||
|
* @param scope the scope
|
||
|
* @return the string
|
||
|
*/
|
||
|
public static String loadGeoExplorerApplicationURL(String scope){
|
||
|
|
||
|
if (scope == null || scope.isEmpty())
|
||
|
logger.warn("Scope is null or ermpty, skipping loadGisViewerApplicationURL");
|
||
|
|
||
|
ApplicationProfileReader reader = new ApplicationProfileReader(scope, UriResolverStartupListener.getGeoExplorerProfile().getGenericResource(), UriResolverStartupListener.getGeoExplorerProfile().getAppId(), false);
|
||
|
String url = reader.getApplicationProfile().getUrl();
|
||
|
logger.info("With scope "+scope+" loaded the GeoExplorer Application URL "+url);
|
||
|
return url;
|
||
|
|
||
|
}
|
||
|
}
|