summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2013-07-08 13:46:38 +0200
committerAndrew Branson <andrew.branson@cern.ch>2013-09-16 12:39:07 +0200
commit2890f3e948fd88183371ff19cd5e265a3daaf6e7 (patch)
treeaa5aa215e085aca44375e2a2f821075685e9a93e
parente85767c28a4a113e69c1ef0cac8ab64903a742f1 (diff)
Start
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/stateMachine/OldStateMachine.java137
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java44
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java168
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java67
4 files changed, 298 insertions, 118 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/OldStateMachine.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/OldStateMachine.java
new file mode 100644
index 0000000..76c8282
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/OldStateMachine.java
@@ -0,0 +1,137 @@
+
+package com.c2kernel.lifecycle.instance.stateMachine;
+
+import java.io.Serializable;
+
+import com.c2kernel.lifecycle.instance.Activity;
+import com.c2kernel.utils.Logger;
+
+/**
+ * @version $Revision: 1.30 $ $Date: 2004/06/04 09:39:19 $
+ * @author $Author: sgaspard $
+ */
+/** this class represents the link between 2 successive activities */
+public class OldStateMachine implements Serializable
+{
+ public int state = 0;
+ private Activity activity;
+
+ public static final String SKIPPABLE = "Skippable";
+ public static final String REPEATABLE = "Repeatable";
+ public static final String IGNORABLE = "Ignorable";
+
+
+ /**
+ * Method StateMachine.
+ * @param act
+ */
+ public OldStateMachine(Activity act)
+ {
+ activity = act;
+ }
+
+ /** row : States from (WAITING,RESERVED,STARTED,SUSPENDED,FINISHED,RWAITING,RRESERVED,RSTARTED,RSUSPENDED)
+ * collumn : transition (RESERVE,START,SKIP,DONE,COMPLETE,SUSPEND,REASIGN,RESUME,REPEAT,IGNORE,PROCEED)
+ * cell : State that is reached (-1 if transition not allowed)
+ */
+ private int[][] getCurrentMachine()
+ {
+ int [][] returnArray =
+ { /*RESERVE, START, SKIP, DONE,COMPLETE,SUSPEND,REASSIGN,RESUME, REPEAT, IGNORE, PROCEED*/
+ /*0 WAITING*/ { 1,getActive()?2:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*0 WAITING*/
+ /*1 RESERVED*/ { -1,getActive()?2:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, 0, -1},/*1 RESERVED*/
+ /*2 STARTED*/ { -1, -1, -1, -1, 4, 3, -1, -1, -1,getIgnorable()?0:-1, -1},/*2 STARTED*/
+ /*3 SUSPENDED*/ { -1, -1, -1, -1, -1, -1, 2, 2, -1,getIgnorable()?0:-1, -1},/*3 SUSPENDED*/
+ /*4 FINISHED*/ { -1, -1, -1, -1, -1, -1, -1, -1,getRepeatable()?5:-1, -1,getActive()?4:-1},/*4 FINISHED*/
+ /*5 RWAITING*/ { 6,getActive()?7:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*5 RWAITING*/
+ /*6 RRESERVED*/ { -1,getActive()?7:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*6 RRESERVED*/
+ /*7 RSTARTED*/ { -1, -1, -1, -1, 4, 8, -1, -1, -1,getIgnorable()?5:-1, -1},/*7 RSTARTED*/
+ /*8 RSUSPENDED*/ { -1, -1, -1, -1, -1, -1, 8, 7, -1, -1, -1} /*8 RSUSPENDED*/
+ };
+ return returnArray;
+ }
+
+ /**
+ * @see java.lang.Object#Object()
+ */
+ public OldStateMachine()
+ {
+ }
+
+ /**
+ * Method getCurrentState.
+ * @return String
+ */
+ public int getCurrentState()
+ {
+ return state;
+ }
+
+ /**
+ * Method possibleTransition.
+ * @return String[]
+ */
+ public int[] possibleTransition()
+ {
+ int[] trans = new int[9];
+ int cmpt = 0;
+ for (int i=0; i< getCurrentMachine()[state].length;i++)
+ if (getCurrentMachine()[state][i]!=-1) trans[cmpt++]=i;
+
+ int [] result = new int[cmpt];
+ for (int i=0;i<cmpt;i++) result[i] = trans[i];
+ return result;
+ }
+
+ /**
+ * Method traverse.
+ * @param transition
+ * @return boolean
+ */
+ public boolean traverse(int transition)
+ {
+ int newState = getCurrentMachine()[state][transition];
+ if (newState > -1) {
+ state=newState;
+ return true;
+ }
+ Logger.msg("StateMachine.traverse() - Illegal transition "+Transitions.getTransitionName(transition)+" from "+States.getStateName(state));
+ return false;
+ }
+ public int simulate(int transition)
+ {
+ return getCurrentMachine()[state][transition];
+ }
+ /**
+ * Returns the ignorable.
+ * @return boolean
+ */
+ public boolean getIgnorable()
+ {
+ return ((Boolean)activity.getProperties().get(IGNORABLE)).booleanValue();
+ }
+
+ /**
+ * Returns the repeatable.
+ * @return boolean
+ */
+ public boolean getRepeatable()
+ {
+ return ((Boolean)activity.getProperties().get(REPEATABLE)).booleanValue();
+ }
+
+ /**
+ * Returns the skippable.
+ * @return boolean
+ */
+ public boolean getSkippable()
+ {
+ return ((Boolean)activity.getProperties().get(SKIPPABLE)).booleanValue();
+ }
+
+ public boolean getActive()
+ {
+ return activity.getActive();
+ }
+
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java
new file mode 100644
index 0000000..d67b129
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/State.java
@@ -0,0 +1,44 @@
+package com.c2kernel.lifecycle.instance.stateMachine;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class State implements Serializable {
+
+ int code;
+ String name;
+ boolean proceeds;
+ ArrayList<String> possibleTransitionNames;
+ ArrayList<Transition> possibleTransitions;
+
+ public State() {
+ possibleTransitions = new ArrayList<Transition>();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setPossibleTransitionNames(ArrayList<String> newNames) {
+ possibleTransitionNames = newNames;
+ possibleTransitions.clear();
+ }
+
+ protected boolean resolveTransitions(HashMap<String, Transition> transitions) {
+ possibleTransitions.clear();
+ boolean allFound = true;
+ for (String name : possibleTransitionNames) {
+ if (transitions.keySet().contains(name))
+ possibleTransitions.add(transitions.get(name));
+ else {
+ allFound = false;
+ }
+ }
+ return allFound;
+ }
+}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java
index ddfc838..fea9c3f 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/StateMachine.java
@@ -2,9 +2,8 @@
package com.c2kernel.lifecycle.instance.stateMachine;
import java.io.Serializable;
-
-import com.c2kernel.lifecycle.instance.Activity;
-import com.c2kernel.utils.Logger;
+import java.util.ArrayList;
+import java.util.HashMap;
/**
* @version $Revision: 1.30 $ $Date: 2004/06/04 09:39:19 $
@@ -13,125 +12,58 @@ import com.c2kernel.utils.Logger;
/** this class represents the link between 2 successive activities */
public class StateMachine implements Serializable
{
- public int state = 0;
- private Activity activity;
-
- public static final String SKIPPABLE = "Skippable";
- public static final String REPEATABLE = "Repeatable";
- public static final String IGNORABLE = "Ignorable";
-
-
- /**
- * Method StateMachine.
- * @param act
- */
- public StateMachine(Activity act)
- {
- activity = act;
+ public String machineName;
+ public int machineVersion;
+
+ private ArrayList<State> states;
+ private ArrayList<Transition> transitions;
+ private final HashMap<String, State> stateNames;
+ private final HashMap<Integer, State> stateCodes;
+ private final HashMap<Integer, Transition> transitionCodes;
+
+ State initialState;
+ boolean isCoherent = false;
+
+ public StateMachine() {
+ states = new ArrayList<State>();
+ transitions = new ArrayList<Transition>();
+ stateNames = new HashMap<String, State>();
+ stateCodes = new HashMap<Integer, State>();
+ transitionCodes = new HashMap<Integer, Transition>();
}
+
+ public void setStates(ArrayList<State> newStates) {
+
+ isCoherent = true;
+ this.states = newStates;
+ stateNames.clear();
+
+ for (State state : states)
+ stateNames.put(state.getName(), state);
+
+ for (Transition trans : transitions)
+ isCoherent &= trans.resolveStates(stateNames);
- /** row : States from (WAITING,RESERVED,STARTED,SUSPENDED,FINISHED,RWAITING,RRESERVED,RSTARTED,RSUSPENDED)
- * collumn : transition (RESERVE,START,SKIP,DONE,COMPLETE,SUSPEND,REASIGN,RESUME,REPEAT,IGNORE,PROCEED)
- * cell : State that is reached (-1 if transition not allowed)
- */
- private int[][] getCurrentMachine()
- {
- int [][] returnArray =
- { /*RESERVE, START, SKIP, DONE,COMPLETE,SUSPEND,REASSIGN,RESUME, REPEAT, IGNORE, PROCEED*/
- /*0 WAITING*/ { 1,getActive()?2:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*0 WAITING*/
- /*1 RESERVED*/ { -1,getActive()?2:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, 0, -1},/*1 RESERVED*/
- /*2 STARTED*/ { -1, -1, -1, -1, 4, 3, -1, -1, -1,getIgnorable()?0:-1, -1},/*2 STARTED*/
- /*3 SUSPENDED*/ { -1, -1, -1, -1, -1, -1, 2, 2, -1,getIgnorable()?0:-1, -1},/*3 SUSPENDED*/
- /*4 FINISHED*/ { -1, -1, -1, -1, -1, -1, -1, -1,getRepeatable()?5:-1, -1,getActive()?4:-1},/*4 FINISHED*/
- /*5 RWAITING*/ { 6,getActive()?7:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*5 RWAITING*/
- /*6 RRESERVED*/ { -1,getActive()?7:-1,getSkippable()?4:-1,getActive()?4:-1, -1, -1, -1, -1, -1, -1, -1},/*6 RRESERVED*/
- /*7 RSTARTED*/ { -1, -1, -1, -1, 4, 8, -1, -1, -1,getIgnorable()?5:-1, -1},/*7 RSTARTED*/
- /*8 RSUSPENDED*/ { -1, -1, -1, -1, -1, -1, 8, 7, -1, -1, -1} /*8 RSUSPENDED*/
- };
- return returnArray;
}
-
- /**
- * @see java.lang.Object#Object()
- */
- public StateMachine()
- {
+
+ public void setTransitions(ArrayList<Transition> newTransitions) {
+ this.transitions = newTransitions;
+ transitionCodes.clear();
+
+ for (Transition trans : transitions) {
+ transitionCodes.put(trans.getCode(), trans);
+ }
}
-
- /**
- * Method getCurrentState.
- * @return String
- */
- public int getCurrentState()
- {
- return state;
+
+ public ArrayList<State> getStates() {
+ return states;
}
-
- /**
- * Method possibleTransition.
- * @return String[]
- */
- public int[] possibleTransition()
- {
- int[] trans = new int[9];
- int cmpt = 0;
- for (int i=0; i< getCurrentMachine()[state].length;i++)
- if (getCurrentMachine()[state][i]!=-1) trans[cmpt++]=i;
-
- int [] result = new int[cmpt];
- for (int i=0;i<cmpt;i++) result[i] = trans[i];
- return result;
+
+ public ArrayList<Transition> getTransitions() {
+ return transitions;
}
-
- /**
- * Method traverse.
- * @param transition
- * @return boolean
- */
- public boolean traverse(int transition)
- {
- int newState = getCurrentMachine()[state][transition];
- if (newState > -1) {
- state=newState;
- return true;
- }
- Logger.msg("StateMachine.traverse() - Illegal transition "+Transitions.getTransitionName(transition)+" from "+States.getStateName(state));
- return false;
+
+ public State getInitialState() {
+ return initialState;
}
- public int simulate(int transition)
- {
- return getCurrentMachine()[state][transition];
- }
- /**
- * Returns the ignorable.
- * @return boolean
- */
- public boolean getIgnorable()
- {
- return ((Boolean)activity.getProperties().get(IGNORABLE)).booleanValue();
- }
-
- /**
- * Returns the repeatable.
- * @return boolean
- */
- public boolean getRepeatable()
- {
- return ((Boolean)activity.getProperties().get(REPEATABLE)).booleanValue();
- }
-
- /**
- * Returns the skippable.
- * @return boolean
- */
- public boolean getSkippable()
- {
- return ((Boolean)activity.getProperties().get(SKIPPABLE)).booleanValue();
- }
-
- public boolean getActive()
- {
- return activity.getActive();
- }
-
-}
+} \ No newline at end of file
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java
new file mode 100644
index 0000000..cd851d7
--- /dev/null
+++ b/src/main/java/com/c2kernel/lifecycle/instance/stateMachine/Transition.java
@@ -0,0 +1,67 @@
+package com.c2kernel.lifecycle.instance.stateMachine;
+
+import java.io.Serializable;
+import java.util.HashMap;
+
+import com.c2kernel.utils.CastorHashMap;
+
+public class Transition implements Serializable {
+
+ int code;
+ String name;
+
+ String originStateCode;
+ String terminalStateCode;
+ State originState;
+ State terminalState;
+
+ String enabledProp = null;
+
+ boolean activating;
+ boolean deactivating;
+
+ boolean outcome;
+ boolean outcomeRequired;
+
+ String outcomeSchema;
+ String schemaNameProperty;
+ String schemaVersionProperty;
+
+ public Transition() {
+ }
+
+ public boolean resolveStates(HashMap<String, State> states) {
+ boolean allFound = true;
+ if (states.keySet().contains(originStateCode))
+ originState = states.get(originStateCode);
+ else
+ allFound = false;
+ if (states.keySet().contains(terminalStateCode))
+ terminalState = states.get(terminalStateCode);
+ else
+ allFound = false;
+ return allFound;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public void setCode(int code) {
+ this.code = code;
+ }
+
+ public String getTerminalStateCode() {
+ return terminalStateCode;
+ }
+
+ public void setTerminalStateCode(String terminalStateCode) {
+ this.terminalStateCode = terminalStateCode;
+ }
+
+ public boolean isEnabled(CastorHashMap props) {
+ if (enabledProp == null)
+ return true;
+ return (Boolean)props.get(enabledProp);
+ }
+}