From 20c81748688547c1b13686f15c65fbb1d60d81a0 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 12 Jul 2012 14:52:36 +0200 Subject: Suspend transition now can carry an optional 'Errors' outcome where client processes can record the reason for the suspension. Errors XML is marshalled ErrorInfo. UserCodeProcess automatically sends fatal ErrorInfos through suspend jobs. Job API added to to support all this. fixes #23 --- .../java/com/c2kernel/process/UserCodeProcess.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/c2kernel/process/UserCodeProcess.java') diff --git a/src/main/java/com/c2kernel/process/UserCodeProcess.java b/src/main/java/com/c2kernel/process/UserCodeProcess.java index 7779802..2f508bc 100644 --- a/src/main/java/com/c2kernel/process/UserCodeProcess.java +++ b/src/main/java/com/c2kernel/process/UserCodeProcess.java @@ -14,6 +14,8 @@ import com.c2kernel.entity.proxy.EntityProxyObserver; import com.c2kernel.entity.proxy.MemberSubscription; import com.c2kernel.lifecycle.instance.stateMachine.Transitions; import com.c2kernel.persistency.ClusterStorage; +import com.c2kernel.scripting.ErrorInfo; +import com.c2kernel.scripting.ScriptErrorException; import com.c2kernel.utils.Logger; /************************************************************************** @@ -28,6 +30,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv protected AgentProxy agent; static boolean active = true; ArrayList ignoredPaths = new ArrayList(); + HashMap errors = new HashMap(); HashMap jobs; public UserCodeProcess(String agentName, String agentPass) { @@ -96,18 +99,31 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv ignoredPaths.remove(jobKey); } else if (thisJob.getPossibleTransition()==Transitions.SUSPEND) { - if (ignoredPaths.contains(jobKey)) + if (ignoredPaths.contains(jobKey)) { + if (errors.containsKey(jobKey)) { + thisJob.setOutcome(Gateway.getMarshaller().marshall(errors.get(jobKey))); + errors.remove(jobKey); + } agent.execute(thisJob); + } } else if (thisJob.getPossibleTransition()==Transitions.RESUME) { if (!ignoredPaths.contains(jobKey)) agent.execute(thisJob); } + } catch (ScriptErrorException ex) { + errors.put(jobKey, ex.getErrors()); + ignoredPaths.add(jobKey); } catch (InvalidTransitionException ex) { // must have already been done by someone else - ignore } catch (Throwable ex) { Logger.error("Error executing "+Transitions.getTransitionName(thisJob.getPossibleTransition())+" job:"); Logger.error(ex); + ErrorInfo ei = new ErrorInfo(); + ei.setFatal(); + ei.addError(ex.getClass().getSimpleName()); + ei.addError(ex.getMessage()); + errors.put(jobKey, ei); ignoredPaths.add(jobKey); } } -- cgit v1.2.3