2018-11-02 15:58:38 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.gcube.datatransfer.resolver.caches;
|
|
|
|
|
2018-12-17 11:48:18 +01:00
|
|
|
import java.util.concurrent.ExecutionException;
|
2018-11-02 15:58:38 +01:00
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
|
2018-11-15 15:35:54 +01:00
|
|
|
import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
|
2018-11-02 15:58:38 +01:00
|
|
|
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;
|
2018-11-02 17:37:02 +01:00
|
|
|
import com.google.common.cache.RemovalListener;
|
|
|
|
import com.google.common.cache.RemovalNotification;
|
2018-11-02 15:58:38 +01:00
|
|
|
|
|
|
|
|
2018-11-05 15:45:31 +01:00
|
|
|
|
2018-11-02 15:58:38 +01:00
|
|
|
/**
|
2018-11-05 15:58:49 +01:00
|
|
|
* The Class LoadingGeoExplorerApplicationURLCache.
|
2018-11-02 15:58:38 +01:00
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
2018-11-05 15:45:31 +01:00
|
|
|
* Nov 5, 2018
|
2018-11-02 15:58:38 +01:00
|
|
|
*/
|
2018-11-05 15:58:49 +01:00
|
|
|
public class LoadingGeoExplorerApplicationURLCache {
|
2018-11-02 15:58:38 +01:00
|
|
|
|
2018-11-05 15:58:49 +01:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(LoadingGeoExplorerApplicationURLCache.class);
|
2018-11-05 12:55:05 +01:00
|
|
|
|
|
|
|
//A cache (Scope, GeoExplorer-URL)
|
2018-11-02 15:58:38 +01:00
|
|
|
private static LoadingCache<String, String> geoExplorerApplicationURLCache;
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
2018-11-02 17:37:02 +01:00
|
|
|
CacheLoader<String, String> loader = new CacheLoader<String, String> () {
|
|
|
|
@Override
|
|
|
|
public String load(String scope)
|
|
|
|
throws Exception {
|
2018-11-06 14:24:33 +01:00
|
|
|
logger.info("Loading the cache for scope: "+scope);
|
2018-11-02 17:37:02 +01:00
|
|
|
return loadGeoExplorerApplicationURL(scope);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
RemovalListener<String, String> removalListener = new RemovalListener<String, String>() {
|
|
|
|
public void onRemoval(RemovalNotification<String, String> removal) {
|
2020-06-18 15:48:47 +02:00
|
|
|
logger.debug("cache expired");
|
2018-11-02 17:37:02 +01:00
|
|
|
}
|
|
|
|
};
|
2018-11-02 15:58:38 +01:00
|
|
|
|
2018-11-02 17:37:02 +01:00
|
|
|
geoExplorerApplicationURLCache =
|
|
|
|
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(
|
2018-11-05 12:55:05 +01:00
|
|
|
1, TimeUnit.DAYS).removalListener(removalListener).
|
2018-11-02 17:37:02 +01:00
|
|
|
build(loader);
|
2018-11-05 12:55:05 +01:00
|
|
|
|
2018-11-06 15:20:05 +01:00
|
|
|
logger.info("cache instancied");
|
2018-11-02 15:58:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-12-17 11:48:18 +01:00
|
|
|
* Gets the.
|
2018-11-02 15:58:38 +01:00
|
|
|
*
|
2018-12-17 11:48:18 +01:00
|
|
|
* @param scope the scope
|
|
|
|
* @return the string
|
|
|
|
* @throws ExecutionException the execution exception
|
2018-11-02 15:58:38 +01:00
|
|
|
*/
|
2018-12-17 11:48:18 +01:00
|
|
|
public static String get(String scope) throws ExecutionException{
|
2018-11-02 15:58:38 +01:00
|
|
|
|
2018-12-17 11:48:18 +01:00
|
|
|
return geoExplorerApplicationURLCache.get(scope);
|
2018-11-02 15:58:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load geo explorer application url.
|
|
|
|
*
|
|
|
|
* @param scope the scope
|
|
|
|
* @return the string
|
|
|
|
*/
|
2018-12-17 11:48:18 +01:00
|
|
|
protected static String loadGeoExplorerApplicationURL(String scope){
|
2018-11-02 15:58:38 +01:00
|
|
|
|
|
|
|
if (scope == null || scope.isEmpty())
|
|
|
|
logger.warn("Scope is null or ermpty, skipping loadGisViewerApplicationURL");
|
|
|
|
|
2018-11-15 15:35:54 +01:00
|
|
|
ApplicationProfileReader reader = new ApplicationProfileReader(scope, UriResolverSmartGearManagerInit.getGeoExplorerProfile().getGenericResource(), UriResolverSmartGearManagerInit.getGeoExplorerProfile().getAppId(), false);
|
2018-11-02 15:58:38 +01:00
|
|
|
String url = reader.getApplicationProfile().getUrl();
|
|
|
|
logger.info("With scope "+scope+" loaded the GeoExplorer Application URL "+url);
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
}
|