git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerCore@82220 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e4fc536d0a
commit
702ea6bfbb
12
pom.xml
12
pom.xml
|
@ -32,13 +32,11 @@
|
|||
<artifactId>accesslogger</artifactId>
|
||||
<version>[1.2.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.gcube.informationsystem</groupId>
|
||||
<artifactId>iscache</artifactId>
|
||||
<version>[1.2.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.gcube.dvos</groupId>
|
||||
<artifactId>voms-admin-stubs</artifactId>
|
||||
|
@ -64,6 +62,16 @@
|
|||
<artifactId>ghn-core-runtime</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.personalisation</groupId>
|
||||
<artifactId>profileadministration-client-library</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.personalisation</groupId>
|
||||
<artifactId>userprofileaccess-client-library</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.gcube.application.framework.core.cache;
|
|||
import java.util.HashMap;
|
||||
|
||||
import org.gcube.application.framework.core.cache.factories.GenericResourceCacheEntryFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.Ehcache;
|
||||
|
@ -29,11 +31,16 @@ public class CachesManager {
|
|||
|
||||
protected HashMap<String, Ehcache> caches;
|
||||
|
||||
/** The logger. */
|
||||
private static final Logger logger = LoggerFactory.getLogger(CachesManager.class);
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
protected CachesManager() {
|
||||
|
||||
|
||||
|
||||
manager = CacheManager.create(CachesManager.class.getResource("/ehcache.xml"));
|
||||
|
||||
caches = new HashMap<String, Ehcache>();
|
||||
|
@ -67,11 +74,11 @@ public class CachesManager {
|
|||
|
||||
public Ehcache getEhcache (String cacheName, CacheEntryFactory cacheFactory) {
|
||||
if (caches.get(cacheName) == null) {
|
||||
logger.debug("Didn't find any previous cache for "+cacheName+". Creating a new and returning that.");
|
||||
Ehcache newCache = manager.getEhcache(cacheName);
|
||||
newCache = new SelfPopulatingCache(newCache, cacheFactory);
|
||||
caches.put(cacheName, newCache);
|
||||
}
|
||||
|
||||
return caches.get(cacheName);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,75 +1,79 @@
|
|||
//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;
|
||||
//import net.sf.ehcache.Cache;
|
||||
//import net.sf.ehcache.CacheManager;
|
||||
//
|
||||
//import org.gcube.resources.discovery.icclient.ICClient;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * 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<String, ISCache> isCaches;
|
||||
//
|
||||
// protected HashMap<String, Cache> caches; //(scope,iccache) pairs
|
||||
//
|
||||
// /** Object logger. */
|
||||
//
|
||||
// protected static final Logger logger = LoggerFactory.getLogger(RIsManager.class);
|
||||
//
|
||||
// /**
|
||||
// * Initializes RIsManager
|
||||
// */
|
||||
// private RIsManager() {
|
||||
// caches = new HashMap<String, Cache>();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 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
|
||||
// */
|
||||
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;
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
|
||||
import org.gcube.informationsystem.cache.ISCache;
|
||||
import org.gcube.informationsystem.cache.ISCacheManager;
|
||||
import org.gcube.resources.discovery.icclient.ICClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* 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<String, ISCache> isCaches;
|
||||
|
||||
protected HashMap<String, Cache> caches; //(scope,iccache) pairs
|
||||
|
||||
/** Object logger. */
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(RIsManager.class);
|
||||
|
||||
/**
|
||||
* Initializes RIsManager
|
||||
*/
|
||||
private RIsManager() {
|
||||
caches = new HashMap<String, Cache>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the singleton
|
||||
* @return the only instance of RIsManager
|
||||
*/
|
||||
synchronized public static RIsManager getInstance() {
|
||||
if (instance == null)
|
||||
instance = new RIsManager();
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
// TODO: UNCOMMENT AND FIX THIS FUNCTION TO COMPLY WITH THE FeatherWeight Stack
|
||||
/**
|
||||
* @param scope the GGUBEScope for which the RIs are requested
|
||||
* @return the ISCache for this specific scope
|
||||
*/
|
||||
// public synchronized Cache getISCache(String scope)
|
||||
// {
|
||||
// Cache info = caches.get(scope);
|
||||
// ISCache info = caches.get(scope);
|
||||
// if(info == null)
|
||||
// {
|
||||
// // If the ISCache in not already created, then it creates a new instance and adds it to the HashMap
|
||||
// try {
|
||||
// CacheManager. //addManager(scope);
|
||||
// info = CacheManager.getCacheManager(scope). .getManager(scope).getCache();
|
||||
// CacheManager.addManager(scope);
|
||||
// info = ISCacheManager.getCacheManager(scope).getManager(scope).getCache();
|
||||
// caches.put(scope, info);
|
||||
// try {
|
||||
// Thread.sleep(5000);
|
||||
|
@ -82,5 +86,5 @@
|
|||
// }
|
||||
// return info;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
}
|
||||
|
|
|
@ -75,7 +75,6 @@ public class GenericResourceCacheEntryFactory implements CacheEntryFactory {
|
|||
{ //Retrieving generic resources based on their ID
|
||||
query.addCondition("$resource/ID eq '"+querySt.get(CacheEntryConstants.id)+"'");
|
||||
// query.addAtomicConditions(new AtomicCondition("/ID", querySt.get(CacheEntryConstants.id)));
|
||||
|
||||
}
|
||||
// else if(querySt.containsKey(CacheEntryConstants.name) && querySt.get(CacheEntryConstants.name).equals(SessionConstants.ScenarioSchemaInfo))
|
||||
// { //Retrieving the generic resource that represents the static search configuration
|
||||
|
@ -85,7 +84,7 @@ public class GenericResourceCacheEntryFactory implements CacheEntryFactory {
|
|||
else if(querySt.containsKey(CacheEntryConstants.name))
|
||||
{ //Retrieving generic resources based on their name
|
||||
query.addCondition("$resource/Profile/Name eq '"+querySt.get(CacheEntryConstants.name)+"'");
|
||||
// query.addAtomicConditions(new AtomicCondition("/Profile/Name", querySt.get(CacheEntryConstants.name)));
|
||||
// query.addCondition("$resource/Profile/Body/VRE eq '"+querySt.get(CacheEntryConstants.vre)+"'");
|
||||
}
|
||||
else if(querySt.containsKey(CacheEntryConstants.vreResource))
|
||||
{
|
||||
|
@ -120,8 +119,6 @@ public class GenericResourceCacheEntryFactory implements CacheEntryFactory {
|
|||
for (GenericResource resource : results) {
|
||||
ScopeGroup<String> scopes = resource.scopes();
|
||||
logger.info("Number of scopes for ScenarioSchemaInfo: " + scopes.size());
|
||||
String [] sc = (String[]) scopes.toArray();
|
||||
logger.info(sc.toString());
|
||||
if(scopes.contains(scope))
|
||||
newResult.add(resource);
|
||||
}
|
||||
|
@ -141,12 +138,36 @@ public class GenericResourceCacheEntryFactory implements CacheEntryFactory {
|
|||
results = newResult;
|
||||
}
|
||||
logger.debug("size of results: " + results.size());
|
||||
|
||||
logger.debug("Printing filtered results contents: ");
|
||||
for(GenericResource genRes : results){
|
||||
logger.debug("genRes.id():"+genRes.id());
|
||||
logger.debug("genRes.profile().body():"+genRes.profile().body());
|
||||
for(String s : genRes.scopes())
|
||||
logger.debug("scope:"+s);
|
||||
logger.debug("genRes.profile().bodyAsString():"+genRes.profile().bodyAsString());
|
||||
logger.debug("genRes.profile().description():"+genRes.profile().description());
|
||||
logger.debug("genRes.profile().name():"+genRes.profile().name());
|
||||
logger.debug("genRes.profile().type():"+genRes.profile().type());
|
||||
}
|
||||
|
||||
List<ISGenericResource> res = new ArrayList<ISGenericResource>();
|
||||
for(GenericResource resource : results)
|
||||
{
|
||||
ISGenericResource genResource = new ISGenericResource(resource.id(), resource.profile().name(),resource.profile().description(),resource.profile().body().toString(),resource.profile().type());
|
||||
ISGenericResource genResource = new ISGenericResource(resource.id(), resource.profile().name(),resource.profile().description(),resource.profile().bodyAsString(),resource.profile().type());
|
||||
res.add(genResource);
|
||||
}
|
||||
|
||||
logger.debug("Printing res contents: ");
|
||||
for(ISGenericResource gr : res){
|
||||
logger.debug("gr.getBody():"+gr.getBody());
|
||||
logger.debug("gr.getDescription():"+gr.getDescription());
|
||||
logger.debug("gr.getId():"+gr.getId());
|
||||
logger.debug("gr.getName():"+gr.getName());
|
||||
logger.debug("gr.getSecondaryType():"+gr.getSecondaryType());
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}catch (Exception e) {
|
||||
logger.error("",e);
|
||||
|
|
|
@ -167,7 +167,18 @@ public class GenericResource implements GenericResourceInfoI {
|
|||
List<String> scopes=new ArrayList<String>();
|
||||
scopes.add(session.getScope());
|
||||
Resource res = scopedPublisher.create(gCubeRes, scopes);
|
||||
logger.trace("Created Generic Resource with id: "+res.id()+" on scope: "+scopes.toString());
|
||||
logger.info("Created Generic Resource with id: "+res.id()+" on scope: "+scopes.toString());
|
||||
|
||||
//NIK-- 1/oct/2013 -- adding generic resource to cache
|
||||
logger.info("Adding it also in cache...");
|
||||
List<ISGenericResource> genRes = new ArrayList<ISGenericResource>();
|
||||
genRes.add(genericResource);
|
||||
QueryString query1 = new QueryString();
|
||||
query1.addParameter(CacheEntryConstants.id, genericResource.getId());
|
||||
query1.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
||||
CachesManager.getInstance().getGenericResourceCache().put(new net.sf.ehcache.Element(query1, genRes));
|
||||
logger.info("...added in cache");
|
||||
|
||||
return res.id();
|
||||
} catch (Exception e) {
|
||||
logger.error("Exception:", e);
|
||||
|
@ -209,29 +220,32 @@ public class GenericResource implements GenericResourceInfoI {
|
|||
scopes.add(scope);
|
||||
// Resource res = scopedPublisher.update(gCubeRes, scopes);
|
||||
Resource res = publisher.update(gCubeRes); //alternative of the above, if we don't want to define a scope -- better use scopedPublisher
|
||||
logger.info("Updated generic resource ! New ID: "+res.id());
|
||||
logger.info("Updated generic resource on IS ! New ID: "+res.id());
|
||||
}catch (Exception e) {
|
||||
logger.error("Exception during update of generic resource:", e);
|
||||
}
|
||||
|
||||
QueryString query1 = new QueryString();
|
||||
query1.addParameter(CacheEntryConstants.name, genericResource.getName().trim());
|
||||
query1.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
||||
if(CachesManager.getInstance().getGenericResourceCache().isElementInMemory(query1) || CachesManager.getInstance().getGenericResourceCache().isElementOnDisk(query1))
|
||||
{
|
||||
logger.info("Replacing generic resource in cache...");
|
||||
CachesManager.getInstance().getGenericResourceCache().get(query1).setTimeToLive(0);
|
||||
CachesManager.getInstance().getGenericResourceCache().remove(query1);
|
||||
}
|
||||
else {
|
||||
logger.info("The generic resource to replace in cache was not found");
|
||||
}
|
||||
|
||||
query1.clear();
|
||||
List<ISGenericResource> genRes = new ArrayList<ISGenericResource>();
|
||||
genRes.add(genericResource);
|
||||
QueryString query1 = new QueryString();
|
||||
query1.addParameter(CacheEntryConstants.id, genericResource.getId());
|
||||
query1.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
||||
CachesManager.getInstance().getGenericResourceCache().put(new net.sf.ehcache.Element(query1, genRes));
|
||||
|
||||
query1.clear();
|
||||
query1.put(CacheEntryConstants.name, genericResource.getName().trim());
|
||||
query1.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
||||
if(CachesManager.getInstance().getGenericResourceCache().isElementInMemory(query1) || CachesManager.getInstance().getGenericResourceCache().isElementOnDisk(query1))
|
||||
{
|
||||
//CachesManager.getInstance().getGenericResourceCache().get(query1).setTimeToLive(-1);
|
||||
CachesManager.getInstance().getGenericResourceCache().remove(query1);
|
||||
}
|
||||
else {
|
||||
logger.info("The generic resource was not found");
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Exception:", e);
|
||||
|
|
Loading…
Reference in New Issue