aslcore/src/org/gcube/application/framework/core/cache/RIsManager.java

78 lines
1.7 KiB
Java

package org.gcube.application.framework.core.cache;
import java.util.HashMap;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.cache.ISCache;
import org.gcube.informationsystem.cache.ISCacheManager;
/**
* This class manages the running harvester threads.
*
* @author Valia Tsagkalidou (KNUA)
*
*/
public class RIsManager {
/**
* Defines the manager's instance
*/
private static RIsManager instance = null;
/**
* keeps the ISCache per scope
*/
protected HashMap<GCUBEScope, ISCache> isCaches;
/** Object logger. */
protected final GCUBELog logger = new GCUBELog(this);
/**
* Initializes RIsManager
*/
private RIsManager() {
isCaches = new HashMap<GCUBEScope, ISCache>();
}
/**
* Retrieves the singleton
* @return the only instance of RIsManager
*/
synchronized public static RIsManager getInstance() {
if (instance == null)
instance = new RIsManager();
return instance;
}
/**
* @param scope the GGUBEScope for which the RIs are requested
* @return the ISCache for this specific scope
*/
public synchronized ISCache getISCache(GCUBEScope scope)
{
ISCache isInfo = isCaches.get(scope);
if(isInfo == null)
{
// If the ISCache in not already created, then it creates a new instance and adds it to the HashMap
try {
ISCacheManager.addManager(scope);
isInfo = ISCacheManager.getManager(scope).getCache();
isCaches.put(scope, isInfo);
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
logger.error("", e1);
}
} catch (Exception e) {
logger.error("", e);
}
}
return isInfo;
}
}