summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/entity/agent/Job.java
diff options
context:
space:
mode:
authorogattaz <olivier@gattaz.com>2014-06-05 16:51:07 +0200
committerogattaz <olivier@gattaz.com>2014-06-05 16:51:07 +0200
commit2fd193d7936084de91eae46e8c2763914d87ab71 (patch)
treeb136ed97e535f11d4b3433d16c26570c89430ce4 /src/main/java/com/c2kernel/entity/agent/Job.java
parent1225792532f77e6e8f4a9addfc0c0a6cf56e89b8 (diff)
parente73468fd08cc27aa31f76a27c916e45d5987c628 (diff)
Merge branch 'master' of ssh://dev.cccs.uwe.ac.uk:22/var/git/cristal-kernel
Diffstat (limited to 'src/main/java/com/c2kernel/entity/agent/Job.java')
-rw-r--r--src/main/java/com/c2kernel/entity/agent/Job.java103
1 files changed, 79 insertions, 24 deletions
diff --git a/src/main/java/com/c2kernel/entity/agent/Job.java b/src/main/java/com/c2kernel/entity/agent/Job.java
index 02dd541..cef35ef 100644
--- a/src/main/java/com/c2kernel/entity/agent/Job.java
+++ b/src/main/java/com/c2kernel/entity/agent/Job.java
@@ -1,5 +1,7 @@
package com.c2kernel.entity.agent;
+import java.util.HashMap;
+
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
@@ -7,10 +9,12 @@ import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lifecycle.instance.Activity;
import com.c2kernel.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.EntityPath;
-import com.c2kernel.lookup.InvalidEntityPathException;
+import com.c2kernel.lookup.InvalidItemPathException;
+import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.outcome.Outcome;
+import com.c2kernel.persistency.outcome.OutcomeInitiator;
import com.c2kernel.persistency.outcome.Schema;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
@@ -63,6 +67,10 @@ public class Job implements C2KLocalObject
private ItemProxy item = null;
private boolean outcomeSet;
+
+ // outcome initiator cache
+
+ static private HashMap<String, OutcomeInitiator> ocInitCache = new HashMap<String, OutcomeInitiator>();
/***************************************************************************
* Empty constructor for Castor
@@ -156,7 +164,7 @@ public class Job implements C2KLocalObject
public int getAgentId() throws ObjectNotFoundException {
if (agentId == -1)
- agentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath(getAgentName()).getSysKey();
+ agentId = Gateway.getLookup().getAgentPath(getAgentName()).getSysKey();
return agentId;
}
@@ -244,9 +252,9 @@ public class Job implements C2KLocalObject
}
}
- public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidEntityPathException {
+ public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidItemPathException {
if (item == null)
- item = (ItemProxy) Gateway.getProxyManager().getProxy(new EntityPath(itemSysKey));
+ item = Gateway.getProxyManager().getProxy(new ItemPath(itemSysKey));
return item;
}
@@ -273,26 +281,72 @@ public class Job implements C2KLocalObject
Logger.error(e);
}
}
+
+ public String getLastView() throws InvalidDataException {
+ String viewName = (String) getActProp("Viewpoint");
+ if (viewName.length() > 0) {
+ // find schema
+ String schemaName;
+ try {
+ schemaName = getSchemaName();
+ } catch (ObjectNotFoundException e1) {
+ throw new InvalidDataException("Schema "+getActProp("SchemaType")+" v"+getActProp("SchemaVersion")+" not found");
+ }
+
+ try {
+ Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(),
+ ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName, null);
+ return view.getOutcome().getData();
+ } catch (ObjectNotFoundException ex) { // viewpoint doesn't exist yet
+ return null;
+ } catch (ClusterStorageException e) {
+ Logger.error(e);
+ throw new InvalidDataException("ViewpointOutcomeInitiator: ClusterStorageException loading viewpoint "
+ + ClusterStorage.VIEWPOINT + "/" + schemaName + "/" + viewName+" in syskey "+getItemSysKey());
+ }
+ }
+ else
+ return null;
+ }
+
+ public OutcomeInitiator getOutcomeInitiator() throws InvalidDataException {
+ String ocInitName = (String) getActProp("OutcomeInit");
+ OutcomeInitiator ocInit;
+ if (ocInitName.length() > 0) {
+ String ocPropName = "OutcomeInit."+ocInitName;
+ synchronized (ocInitCache) {
+ ocInit = ocInitCache.get(ocPropName);
+ if (ocInit == null) {
+ Object ocInitObj = Gateway.getProperties().get(ocPropName);
+ if (ocInitObj instanceof String) {
+ try {
+ ocInitObj = Class.forName((String)ocInitObj).newInstance();
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidDataException("Could not instantiate OutcomeInstantiator "+ocInitObj+" for "+ocPropName);
+ }
+ }
+ ocInit = (OutcomeInitiator)ocInitObj; // throw runtime class cast if it isn't one
+ ocInitCache.put(ocPropName, ocInit);
+ }
+ }
+ return ocInit;
+ }
+ else
+ return null;
+ }
- public String getOutcomeString()
+ public String getOutcomeString() throws InvalidDataException
{
- if (outcomeData == null && isOutcomeRequired())
- {
- String viewName = (String) getActProp("Viewpoint");
- outcomeData = null;
- if (viewName.length() > 0)
- try
- {
- Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), ClusterStorage.VIEWPOINT + "/" + getSchemaName() + "/" + viewName, null);
- outcomeData = view.getOutcome().getData();
- outcomeSet = true;
- } catch (Exception ex)
- {
- outcomeData = null;
- outcomeSet = false;
- }
-
- }
+ if (outcomeData == null && transition.hasOutcome(actProps)) {
+ outcomeData = getLastView();
+ if (outcomeData == null) {
+ OutcomeInitiator ocInit = getOutcomeInitiator();
+ if (ocInit != null)
+ outcomeData = ocInit.initOutcome(this);
+ }
+ if (outcomeData != null) outcomeSet = true;
+ }
return outcomeData;
}
@@ -335,6 +389,7 @@ public class Job implements C2KLocalObject
public String getActPropString(String name)
{
- return String.valueOf(actProps.get(name));
+ Object obj = getActProp(name);
+ return obj==null?null:String.valueOf(obj);
}
} \ No newline at end of file