summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/utils/ActDefCache.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2013-11-18 09:48:03 +0100
committerAndrew Branson <andrew.branson@cern.ch>2013-11-18 17:25:00 +0100
commitd43164830403245353080f5d6f838ed9f56d9a35 (patch)
treed880c9103fb61f5ef39f1723c4dbd634d5d83b67 /src/main/java/com/c2kernel/utils/ActDefCache.java
parent37a3c3867cb4c7705065ed1d079bdac4f3f52f50 (diff)
3.0-SNAPSHOT (Will be first open source version)
New StateMachine desc IssueID #28
Diffstat (limited to 'src/main/java/com/c2kernel/utils/ActDefCache.java')
-rw-r--r--src/main/java/com/c2kernel/utils/ActDefCache.java105
1 files changed, 26 insertions, 79 deletions
diff --git a/src/main/java/com/c2kernel/utils/ActDefCache.java b/src/main/java/com/c2kernel/utils/ActDefCache.java
index 2ee5c7c..ab2bd90 100644
--- a/src/main/java/com/c2kernel/utils/ActDefCache.java
+++ b/src/main/java/com/c2kernel/utils/ActDefCache.java
@@ -5,95 +5,42 @@ package com.c2kernel.utils;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.proxy.EntityProxyObserver;
import com.c2kernel.entity.proxy.ItemProxy;
-import com.c2kernel.entity.proxy.MemberSubscription;
import com.c2kernel.lifecycle.ActivityDef;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
-public class ActDefCache {
+public class ActDefCache extends DescriptionObjectCache<ActivityDef> {
- SoftCache<String, ActCacheEntry> actCache = new SoftCache<String, ActCacheEntry>();
-
- public ActivityDef get(String actName, String actVersion) throws ObjectNotFoundException, InvalidDataException {
+
+ @Override
+ public String getDefRoot() {
+ return "/desc/ActivityDesc";
+ }
+
+ @Override
+ public ActivityDef loadObject(String name, int version, ItemProxy proxy) throws ObjectNotFoundException, InvalidDataException {
ActivityDef thisActDef;
- synchronized(actCache) {
- ActCacheEntry thisActDefEntry = actCache.get(actName+"_"+actVersion);
- if (thisActDefEntry == null) {
- Logger.msg(6, actName+" v"+actVersion+" not found in cache. Retrieving.");
- ItemProxy actDefItem = LocalObjectLoader.loadLocalObjectDef("/desc/ActivityDesc/", actName);
- String actType = actDefItem.getProperty("Complexity");
- Viewpoint actView = (Viewpoint)actDefItem.getObject(ClusterStorage.VIEWPOINT + "/" + actType + "ActivityDef/" + actVersion);
- String marshalledAct;
- try {
- marshalledAct = actView.getOutcome().getData();
- } catch (ClusterStorageException ex) {
- Logger.error(ex);
- throw new ObjectNotFoundException("Problem loading "+actName+" v"+actVersion+": "+ex.getMessage(), "");
- }
- try {
- thisActDef = (ActivityDef)Gateway.getMarshaller().unmarshall(marshalledAct);
- } catch (Exception ex) {
- Logger.error(ex);
- throw new InvalidDataException("Could not unmarshall '"+actName+"' v"+actVersion+": "+ex.getMessage(), "");
- }
- thisActDef.setName(actName);
- thisActDef.setVersion(actVersion);
- actCache.put(actName+"_"+actVersion, new ActCacheEntry(thisActDef, actDefItem, this));
- }
- else {
- Logger.msg(6, actName+" v"+actVersion+" found in cache.");
- thisActDef = thisActDefEntry.actDef;
- }
- }
+ String actType = proxy.getProperty("Complexity");
+ Viewpoint actView = (Viewpoint)proxy.getObject(ClusterStorage.VIEWPOINT + "/" + actType + "ActivityDef/" + version);
+ String marshalledAct;
+ try {
+ marshalledAct = actView.getOutcome().getData();
+ } catch (ClusterStorageException ex) {
+ Logger.error(ex);
+ throw new ObjectNotFoundException("Problem loading "+name+" v"+version+": "+ex.getMessage(), "");
+ }
+ try {
+ thisActDef = (ActivityDef)Gateway.getMarshaller().unmarshall(marshalledAct);
+ } catch (Exception ex) {
+ Logger.error(ex);
+ throw new InvalidDataException("Could not unmarshall '"+name+"' v"+version+": "+ex.getMessage(), "");
+ }
+ thisActDef.setName(name);
+ thisActDef.setVersion(version);
return thisActDef;
}
- public void removeAct(String id) {
- synchronized(actCache) {
- if (actCache.keySet().contains(id)) {
- Logger.msg(7, "ActDefCache: Removing activity def "+id+" from cache");
- actCache.remove(id);
- }
- }
- }
-
- public class ActCacheEntry implements EntityProxyObserver<Viewpoint> {
- public String id;
- public ItemProxy actProxy;
- public ActivityDef actDef;
- public ActDefCache parent;
- public ActCacheEntry(ActivityDef actDef, ItemProxy actProxy, ActDefCache parent) {
- this.id = actDef.getName()+"_"+actDef.getVersion();
- this.actDef = actDef;
- this.parent = parent;
- this.actProxy = actProxy;
- actProxy.subscribe(new MemberSubscription<Viewpoint>(this, ClusterStorage.VIEWPOINT, false));
- }
- @Override
- public void finalize() {
- parent.removeAct(id);
- actProxy.unsubscribe(this);
- }
- @Override
- public void add(Viewpoint contents) {
- parent.removeAct(id);
- }
-
- @Override
- public void remove(String oldId) {
- parent.removeAct(oldId);
- }
-
- @Override
- public String toString() {
- return "ActDef cache entry: "+id;
- }
- @Override
- public void control(String control, String msg) {
- }
- }
} \ No newline at end of file