You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by at...@apache.org on 2014/04/18 14:00:54 UTC
svn commit: r1588451 - in
/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2:
SCInstance.java SCXMLExecutionContext.java
Author: ate
Date: Fri Apr 18 12:00:54 2014
New Revision: 1588451
URL: http://svn.apache.org/r1588451
Log:
SCXML-202: move state machine running status management into SCInstance itself, thereby retaining this status after serializing/de-serializing
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCInstance.java
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutionContext.java
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCInstance.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCInstance.java?rev=1588451&r1=1588450&r2=1588451&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCInstance.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCInstance.java Fri Apr 18 12:00:54 2014
@@ -77,6 +77,11 @@ public class SCInstance implements Seria
private final Status currentStatus;
/**
+ * Running status for this state machine
+ */
+ private boolean running;
+
+ /**
* The SCXML I/O Processor for the internal event queue
*/
private transient SCXMLIOProcessor internalIOProcessor;
@@ -136,6 +141,7 @@ public class SCInstance implements Seria
* @throws ModelException if the state machine hasn't been setup for this instance
*/
protected void initialize() throws ModelException {
+ running = false;
if (stateMachine == null) {
throw new ModelException(ERR_NO_STATE_MACHINE);
}
@@ -293,6 +299,26 @@ public class SCInstance implements Seria
return currentStatus;
}
+
+ /**
+ * @return Returns if the state machine is running
+ */
+ public boolean isRunning() {
+ return running;
+ }
+
+ /**
+ * Sets the running status of the state machine
+ * @param running flag indicating the running status of the state machine
+ * @throws IllegalStateException Exception thrown if trying to set the state machine running when in a Final state
+ */
+ protected void setRunning(final boolean running) throws IllegalStateException {
+ if (!this.running && running && currentStatus.isFinal()) {
+ throw new IllegalStateException("The state machine is in a Final state and cannot be set running again");
+ }
+ this.running = running;
+ }
+
/**
* Get the root context.
*
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutionContext.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutionContext.java?rev=1588451&r1=1588450&r2=1588451&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutionContext.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/SCXMLExecutionContext.java Fri Apr 18 12:00:54 2014
@@ -100,11 +100,6 @@ public class SCXMLExecutionContext imple
private final Map<String, Invoker> invokers = new HashMap<String, Invoker>();
/**
- * Running status for this state machine
- */
- private boolean running;
-
- /**
* Constructor
*
* @param externalIOProcessor The external IO Processor
@@ -143,14 +138,14 @@ public class SCXMLExecutionContext imple
* @return Returns true if this state machine is running
*/
public boolean isRunning() {
- return running;
+ return scInstance.isRunning();
}
/**
* Stop a running state machine
*/
public void stopRunning() {
- this.running = false;
+ scInstance.setRunning(false);
}
/**
@@ -160,7 +155,6 @@ public class SCXMLExecutionContext imple
* @throws ModelException if the state machine instance failed to initialize.
*/
public void initialize() throws ModelException {
- running = false;
if (!invokeIds.isEmpty()) {
for (Invoke invoke : new ArrayList<Invoke>(invokeIds.keySet())) {
cancelInvoker(invoke);
@@ -168,7 +162,7 @@ public class SCXMLExecutionContext imple
}
internalEventQueue.clear();
scInstance.initialize();
- running = true;
+ scInstance.setRunning(true);
}
/**
@@ -245,7 +239,6 @@ public class SCXMLExecutionContext imple
}
catch (ModelException me) {
// won't happen
- return;
}
}
@@ -306,7 +299,6 @@ public class SCXMLExecutionContext imple
}
catch (ModelException me) {
// should not happen
- return;
}
}
}