summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/entity/proxy/AgentProxy.java
diff options
context:
space:
mode:
authorabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
committerabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
commit0ec8481c10cd8277d84c7c1a785483a0a739e5a0 (patch)
tree5f6e5d9ae75193e67e6f3b3dfa488960c5cde1d5 /source/com/c2kernel/entity/proxy/AgentProxy.java
parent036cbdba66f804743c4c838ed598d6972c4b3e17 (diff)
More code cleanup:
Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class
Diffstat (limited to 'source/com/c2kernel/entity/proxy/AgentProxy.java')
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/entity/proxy/AgentProxy.java91
1 files changed, 46 insertions, 45 deletions
diff --git a/source/com/c2kernel/entity/proxy/AgentProxy.java b/source/com/c2kernel/entity/proxy/AgentProxy.java
index af77031..f2e8283 100755..100644
--- a/source/com/c2kernel/entity/proxy/AgentProxy.java
+++ b/source/com/c2kernel/entity/proxy/AgentProxy.java
@@ -66,8 +66,9 @@ public class AgentProxy extends EntityProxy
throw new ObjectNotFoundException();
}
}
-
- public ManageableEntity narrow() throws ObjectNotFoundException
+
+ @Override
+ public ManageableEntity narrow() throws ObjectNotFoundException
{
try {
return AgentHelper.narrow(mIOR);
@@ -85,48 +86,48 @@ public class AgentProxy extends EntityProxy
ObjectNotFoundException
{
Logger.msg(7, "AgentProxy::initialise - started");
-
+
((Agent)getEntity()).initialise( agentProps );
}
-
+
public AgentPath getPath() {
return path;
}
-
+
/**
- * Executes a job on the given item using this agent.
- *
+ * Executes a job on the given item using this agent.
+ *
* @param item - item holding this job
* @param job - the job to execute
*/
- public void execute(ItemProxy item, Job job)
- throws AccessRightsException,
- InvalidTransitionException,
- ObjectNotFoundException,
- InvalidDataException,
+ public void execute(ItemProxy item, Job job)
+ throws AccessRightsException,
+ InvalidTransitionException,
+ ObjectNotFoundException,
+ InvalidDataException,
PersistencyException,
ObjectAlreadyExistsException
- {
+ {
OutcomeValidator validator = null;
String scriptName = job.getActPropString("ScriptName");
Date startTime = new Date();
Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+path.getAgentName());
// get the outcome validator if present
- if (job.isOutcomeUsed())
+ if (job.isOutcomeUsed())
{
-
+
// get schema info from act props
String schemaName = job.getActPropString("SchemaType");
int schemaVersion;
try {
schemaVersion = Integer.parseInt(job.getActPropString("SchemaVersion"));
- } catch (Exception e) {
+ } catch (Exception e) {
throw new InvalidDataException(e.getClass().getName()+" extracing schema version", "");
}
Logger.msg(5, "AgentProxy - fetching schema "+schemaName+"_"+schemaVersion+" for validation");
// retrieve schema
Schema schema = LocalObjectLoader.getSchema(schemaName, schemaVersion);
-
+
if (schema == null)
throw new InvalidDataException("Job references outcome type "+schemaName+" version "+schemaVersion+" that does not exist in this centre.", "");
@@ -136,12 +137,12 @@ public class AgentProxy extends EntityProxy
throw new InvalidDataException("Could not create validator: "+e.getMessage(), "");
}
}
-
- if(scriptName != null && scriptName.length() > 0 &&
+
+ if(scriptName != null && scriptName.length() > 0 &&
(job.getPossibleTransition() == Transitions.DONE || job.getPossibleTransition() == Transitions.COMPLETE)) {
Logger.msg(3, "AgentProxy - executing script "+scriptName);
try {
-
+
// pre-validate outcome from script if there is one
if (job.getOutcomeString()!= null && validator != null) {
Logger.msg(5, "AgentProxy - validating outcome before script execution");
@@ -151,10 +152,10 @@ public class AgentProxy extends EntityProxy
throw new InvalidDataException(error, "");
}
}
-
+
// load script
ErrorInfo scriptErrors = (ErrorInfo)callScript(item, job);
-
+
if (scriptErrors.getFatal()) {
Logger.msg(3, "AgentProxy - fatal script error");
Logger.error(scriptErrors.getErrors());
@@ -174,7 +175,7 @@ public class AgentProxy extends EntityProxy
if (error.length() > 0)
throw new InvalidDataException(error, "");
}
-
+
job.setAgentId(getSystemKey());
Logger.msg(3, "AgentProxy - submitting job to item proxy");
item.requestAction(job);
@@ -184,16 +185,16 @@ public class AgentProxy extends EntityProxy
Logger.msg(3, "Execution took "+secsNow+" seconds");
}
}
-
+
public Object callScript(ItemProxy item, Job job) throws ScriptingEngineException {
Script script = new Script(item, this, job);
return script.execute();
}
-
+
/**
- * Standard execution of jobs. Note that this method should always be the one used from clients - all execution
- * parameters are taken from the job where they're probably going to be correct.
- *
+ * Standard execution of jobs. Note that this method should always be the one used from clients - all execution
+ * parameters are taken from the job where they're probably going to be correct.
+ *
* @param job
* @throws AccessRightsException
* @throws InvalidDataException
@@ -202,7 +203,7 @@ public class AgentProxy extends EntityProxy
* @throws PersistencyException
* @throws ObjectAlreadyExistsException
*/
- public void execute(Job job)
+ public void execute(Job job)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -217,8 +218,8 @@ public class AgentProxy extends EntityProxy
throw new ObjectNotFoundException("Job contained invalid item sysKey: "+job.getItemSysKey(), "");
}
}
-
- public void execute(ItemProxy item, String predefStep, C2KLocalObject obj)
+
+ public void execute(ItemProxy item, String predefStep, C2KLocalObject obj)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -235,8 +236,8 @@ public class AgentProxy extends EntityProxy
}
execute(item, predefStep, param);
}
-
- public void execute(ItemProxy item, String predefStep, String param)
+
+ public void execute(ItemProxy item, String predefStep, String param)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -248,8 +249,8 @@ public class AgentProxy extends EntityProxy
params[0] = param;
execute(item, predefStep, params);
}
-
- public void execute(ItemProxy item, String predefStep, String[] params)
+
+ public void execute(ItemProxy item, String predefStep, String[] params)
throws AccessRightsException,
InvalidDataException,
InvalidTransitionException,
@@ -259,42 +260,42 @@ public class AgentProxy extends EntityProxy
{
item.requestAction(getSystemKey(), "workflow/predefined/"+predefStep, Transitions.DONE, PredefinedStep.bundleData(params));
}
-
+
/** Wrappers for scripts */
public String marshall(Object obj) throws Exception {
return CastorXMLUtility.marshall(obj);
}
-
+
public Object unmarshall(String obj) throws Exception {
return CastorXMLUtility.unmarshall(obj);
}
-
+
/** Let scripts resolve items */
public ItemProxy searchItem(String name) throws ObjectNotFoundException {
- Enumeration results = Gateway.getLDAPLookup().search(new DomainPath(""),name);
-
+ Enumeration<?> results = Gateway.getLDAPLookup().search(new DomainPath(""),name);
+
Path returnPath = null;
if (!results.hasMoreElements())
throw new ObjectNotFoundException(name, "");
-
+
while(results.hasMoreElements()) {
Path nextMatch = (Path)results.nextElement();
if (returnPath != null && nextMatch.getSysKey() != -1 && returnPath.getSysKey() != nextMatch.getSysKey())
throw new ObjectNotFoundException("Too many items with that name");
returnPath = nextMatch;
}
-
+
return (ItemProxy)Gateway.getProxyManager().getProxy(returnPath);
}
-
+
public ItemProxy getItem(String path) throws ObjectNotFoundException {
return (getItem(new DomainPath(path)));
}
-
+
public ItemProxy getItem(DomainPath path) throws ObjectNotFoundException {
return (ItemProxy)Gateway.getProxyManager().getProxy(path);
}
-
+
public ItemProxy getItemBySysKey(int sysKey) throws ObjectNotFoundException, InvalidEntityPathException {
return (ItemProxy)Gateway.getProxyManager().getProxy(new EntityPath(sysKey));
}