76 lines
2.0 KiB
Java
76 lines
2.0 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 GisViewerApplicationHostnameGuavaCache.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
* Nov 2, 2018
|
|
*/
|
|
public class GisViewerApplicationHostnameGuavaCache {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(GisViewerApplicationHostnameGuavaCache.class);
|
|
private static LoadingCache<String, String> gisViewerApplicationURLCache;
|
|
|
|
static {
|
|
gisViewerApplicationURLCache =
|
|
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
|
1, TimeUnit.HOURS).build(
|
|
new CacheLoader<String, String>() {
|
|
|
|
@Override
|
|
public String load(String scope)
|
|
throws Exception {
|
|
|
|
return loadGisViewerApplicationURL(scope);
|
|
}
|
|
});
|
|
|
|
logger.info(GisViewerApplicationHostnameGuavaCache.class.getSimpleName() +" instancied");
|
|
}
|
|
|
|
|
|
/**
|
|
* Gets the cache.
|
|
*
|
|
* @return the cache
|
|
*/
|
|
public static LoadingCache<String, String> getCache() {
|
|
|
|
return gisViewerApplicationURLCache;
|
|
}
|
|
|
|
|
|
/**
|
|
* Load gis viewer application url.
|
|
*
|
|
* @param scope the scope
|
|
* @return the string
|
|
*/
|
|
public static String loadGisViewerApplicationURL(String scope){
|
|
|
|
if (scope == null || scope.isEmpty())
|
|
logger.warn("Scope is null or ermpty, skipping loadGisViewerApplicationURL");
|
|
|
|
ApplicationProfileReader reader = new ApplicationProfileReader(scope, UriResolverStartupListener.getGisViewerProfile().getGenericResource(), UriResolverStartupListener.getGisViewerProfile().getAppId(), false);
|
|
String url = reader.getApplicationProfile().getUrl();
|
|
logger.info("With scope "+scope+" loaded the GisViewer Application URL "+url);
|
|
return url;
|
|
|
|
}
|
|
}
|