From d43164830403245353080f5d6f838ed9f56d9a35 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 18 Nov 2013 09:48:03 +0100 Subject: 3.0-SNAPSHOT (Will be first open source version) New StateMachine desc IssueID #28 --- .../java/com/c2kernel/process/UserCodeProcess.java | 35 +++++++++++++--------- 1 file changed, 21 insertions(+), 14 deletions(-) (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 0abd906..f7bbe74 100644 --- a/src/main/java/com/c2kernel/process/UserCodeProcess.java +++ b/src/main/java/com/c2kernel/process/UserCodeProcess.java @@ -11,7 +11,6 @@ import com.c2kernel.entity.agent.Job; import com.c2kernel.entity.proxy.AgentProxy; 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; @@ -26,7 +25,14 @@ import com.c2kernel.utils.Logger; * All rights reserved. **************************************************************************/ public class UserCodeProcess extends StandardClient implements EntityProxyObserver, Runnable { - protected AgentProxy agent; + + // Default state machine transitions + private static final int START = 1; + private static final int COMPLETE = 2; + private static final int SUSPEND = 3; + private static final int RESUME = 4; + + protected AgentProxy agent; static boolean active = true; ArrayList ignoredPaths = new ArrayList(); HashMap errors = new HashMap(); @@ -60,13 +66,13 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv Job thisJob = null; synchronized (jobs) { if (jobs.size() > 0) { - thisJob = getJob(jobs, Transitions.COMPLETE); + thisJob = getJob(jobs, COMPLETE); if (thisJob == null) - thisJob = getJob(jobs, Transitions.START); + thisJob = getJob(jobs, START); if (thisJob == null) - thisJob = getJob(jobs, Transitions.SUSPEND); + thisJob = getJob(jobs, SUSPEND); if (thisJob == null) - thisJob = getJob(jobs, Transitions.RESUME); + thisJob = getJob(jobs, RESUME); if (thisJob == null) { Logger.error("No supported jobs, but joblist is not empty! Discarding remaining jobs"); @@ -79,8 +85,9 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv if (thisJob != null) { String jobKey = thisJob.getItemSysKey()+":"+thisJob.getStepPath(); + int transitionId = thisJob.getTransition().getId(); try { - if (thisJob.getPossibleTransition()==Transitions.START) { + if (transitionId==START) { Logger.msg(5, "Testing start conditions"); boolean start = assessStartConditions(thisJob); if (start) { @@ -91,13 +98,13 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv Logger.msg(5, "Start conditions failed "+thisJob.getStepName()+" in "+thisJob.getItemSysKey()); } } - else if (thisJob.getPossibleTransition()==Transitions.COMPLETE) { + else if (transitionId==COMPLETE) { Logger.msg(5, "Executing logic"); runUCLogic(thisJob); if (ignoredPaths.contains(jobKey)) ignoredPaths.remove(jobKey); } - else if (thisJob.getPossibleTransition()==Transitions.SUSPEND) { + else if (transitionId==SUSPEND) { if (ignoredPaths.contains(jobKey)) { if (errors.containsKey(jobKey)) { thisJob.setOutcome(Gateway.getMarshaller().marshall(errors.get(jobKey))); @@ -106,7 +113,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv agent.execute(thisJob); } } - else if (thisJob.getPossibleTransition()==Transitions.RESUME) { + else if (transitionId==RESUME) { if (!ignoredPaths.contains(jobKey)) agent.execute(thisJob); } @@ -116,7 +123,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv } 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("Error executing "+thisJob.getTransition().getName()+" job:"); Logger.error(ex); ErrorInfo ei = new ErrorInfo(); ei.setFatal(); @@ -148,12 +155,12 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv } } - private static Job getJob(HashMap jobs, int transition) { + private static Job getJob(HashMap jobs, int transition) { for (C2KLocalObject c2kLocalObject : jobs.values()) { Job thisJob = (Job)c2kLocalObject; - if (thisJob.getPossibleTransition() == transition) { + if (thisJob.getTransition().getId() == transition) { Logger.msg(1,"================================================================="); - Logger.msg(1, "Got "+Transitions.getTransitionName(transition)+" job for "+thisJob.getStepName()+" in "+thisJob.getItemSysKey()); + Logger.msg(1, "Got "+thisJob.getTransition().getName()+" job for "+thisJob.getStepName()+" in "+thisJob.getItemSysKey()); return thisJob; } } -- cgit v1.2.3