[jbpm-commits] JBoss JBPM SVN: r6190 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm: graph/exe and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Feb 22 16:49:10 EST 2010


Author: alex.guizar at jboss.com
Date: 2010-02-22 16:49:10 -0500 (Mon, 22 Feb 2010)
New Revision: 6190

Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/command/AbstractCancelCommand.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/Token.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskInstance.java
Log:
prevent spurious 'token has ended' warnings

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/command/AbstractCancelCommand.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/command/AbstractCancelCommand.java	2010-02-22 11:30:48 UTC (rev 6189)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/command/AbstractCancelCommand.java	2010-02-22 21:49:10 UTC (rev 6190)
@@ -6,20 +6,18 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.hibernate.Query;
 import org.jbpm.JbpmContext;
 import org.jbpm.graph.exe.Token;
 import org.jbpm.taskmgmt.exe.TaskInstance;
 
-public abstract class AbstractCancelCommand extends AbstractBaseCommand
-{
+public abstract class AbstractCancelCommand extends AbstractBaseCommand {
 
   private static final long serialVersionUID = 1L;
 
   /**
-   * Name of a standardized process variable which is written during cancellation
-   * in order to indicate that this process has been 'canceled' and not just ended.
-   * Value of the variable is the timestamp of cancellation.
+   * Name of a standardized process variable written during cancellation in
+   * order to indicate that this process has been 'canceled' and not just ended.
+   * The variable value is the cancellation timestamp.
    */
   public static String CANCELLATION_INDICATOR_VARIABLE_NAME = "canceled";
 
@@ -27,60 +25,46 @@
 
   protected static final Log log = LogFactory.getLog(AbstractCancelCommand.class);
 
-  protected void cancelTokens(Collection tokens)
-  {
-    if (tokens != null && tokens.size() > 0)
-    {
-      log.info("cancel " + tokens.size() + " tokens");
-      for (Iterator itr = tokens.iterator(); itr.hasNext();)
-      {
-        cancelToken((Token)itr.next());
+  protected void cancelTokens(Collection tokens) {
+    if (tokens != null && !tokens.isEmpty()) {
+      log.debug("canceling " + tokens.size() + " tokens");
+      for (Iterator itr = tokens.iterator(); itr.hasNext();) {
+        cancelToken((Token) itr.next());
       }
     }
   }
 
-  protected void cancelToken(Token token)
-  {
-    token.end(false); // end the token but dont verify
-    // ParentTermination
-    // if set to token.end() == token.end(true) the parent token is
-    // terminated if there are no children
-    // If we then use that in a "SignalingJoin" the main path of execution
-    // is triggered, but we dont want that!
-
-    // Recursively cancel children
+  protected void cancelToken(Token token) {
+    // recursively cancel children
     cancelTokens(token.getChildren().values());
-    
+
     // cancel tasks
     cancelTasks(getTasksForToken(token));
 
-    log.info("token " + token.getId() + " canceled");
+    if (!token.hasEnded()) {
+      // end token but do not propagate to parent
+      // to prevent inadvertent termination 
+      token.end(false);
+    }
+    log.debug("canceled " + token);
   }
 
-  protected List getTasksForToken(Token token)
-  {
-    Query hqlQuery = jbpmContext.getSession().getNamedQuery("TaskMgmtSession.findTaskInstancesByTokenId");
-    hqlQuery.setLong("tokenId", token.getId());
-    return hqlQuery.list();
+  protected List getTasksForToken(Token token) {
+    return jbpmContext.getSession()
+      .getNamedQuery("TaskMgmtSession.findTaskInstancesByTokenId")
+      .setLong("tokenId", token.getId())
+      .list();
   }
 
-  protected void cancelTasks(List tasks)
-  {
-    if (tasks != null && tasks.size() > 0)
-    {
-      log.info("cancel " + tasks.size() + " tasks");
-      for (Iterator it = tasks.iterator(); it.hasNext();)
-      {
-        TaskInstance ti = (TaskInstance)it.next();
+  protected void cancelTasks(List tasks) {
+    if (tasks != null && !tasks.isEmpty()) {
+      log.debug("cancelling " + tasks.size() + " tasks");
 
-        // if the process def doesn't set signal="never", we have to
-        // manually turn off signaling for all tasks;
-        // otherwise, the token will be triggered instead of being
-        // ended.
-        // Do this until http://jira.jboss.com/jira/browse/JBPM-392 is
-        // resolved
-
-        log.info("cancel task " + ti.getId());
+      for (Iterator it = tasks.iterator(); it.hasNext();) {
+        TaskInstance ti = (TaskInstance) it.next();
+        log.debug("cancelling " + ti);
+        // manually turn off signaling for task instance,
+        // otherwise it may signal its associated token
         ti.setSignalling(false);
         ti.cancel();
       }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/Token.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/Token.java	2010-02-22 11:30:48 UTC (rev 6189)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/Token.java	2010-02-22 21:49:10 UTC (rev 6190)
@@ -284,7 +284,7 @@
   public void end(boolean verifyParentTermination) {
     // if already ended, do nothing
     if (end != null) {
-      log.warn(this + " has ended already");
+      if (parent != null) log.warn(this + " has ended already");
       return;
     }
 

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskInstance.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskInstance.java	2010-02-22 11:30:48 UTC (rev 6189)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskInstance.java	2010-02-22 21:49:10 UTC (rev 6190)
@@ -43,10 +43,12 @@
 import org.jbpm.graph.exe.ExecutionContext;
 import org.jbpm.graph.exe.ProcessInstance;
 import org.jbpm.graph.exe.Token;
+import org.jbpm.graph.node.TaskNode;
 import org.jbpm.security.SecurityHelper;
 import org.jbpm.taskmgmt.def.Swimlane;
 import org.jbpm.taskmgmt.def.Task;
 import org.jbpm.taskmgmt.def.TaskController;
+import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
 import org.jbpm.taskmgmt.log.TaskAssignLog;
 import org.jbpm.taskmgmt.log.TaskEndLog;
 import org.jbpm.util.Clock;
@@ -56,8 +58,7 @@
  * task list) and that can trigger the continuation of execution of the token
  * upon completion.
  */
-public class TaskInstance extends VariableContainer implements Identifiable,
-    Assignable {
+public class TaskInstance extends VariableContainer implements Identifiable, Assignable {
 
   private static final long serialVersionUID = 1L;
 
@@ -109,8 +110,7 @@
   }
 
   void submitVariables() {
-    TaskController taskController = task != null ? task.getTaskController()
-        : null;
+    TaskController taskController = task != null ? task.getTaskController() : null;
     // if a task controller is present,
     if (taskController != null) {
       // the task controller copies variables back into the process
@@ -120,25 +120,23 @@
     else if (token != null && token.getProcessInstance() != null) {
       // all task-local variables are flushed to the process
       if (variableInstances != null) {
-        ContextInstance contextInstance = token.getProcessInstance()
-            .getContextInstance();
+        ContextInstance contextInstance = token.getProcessInstance().getContextInstance();
         for (Iterator iter = variableInstances.values().iterator(); iter.hasNext();) {
           VariableInstance variableInstance = (VariableInstance) iter.next();
-          log.debug("flushing variable '" + variableInstance.getName()
-            + "' from task '" + name + "' to process variables");
+          String variableName = variableInstance.getName();
+          log.debug("submitting variable '" + variableName + "' from task '" + name
+            + "' to process variables");
           // simple way to clone the variable instance; might be optimized
-          contextInstance.setVariable(variableInstance.getName(),
-              variableInstance.getValue(), token);
+          contextInstance.setVariable(variableName, variableInstance.getValue(), token);
         }
       }
     }
   }
 
   void initializeVariables() {
-    TaskController taskController = task != null ? task.getTaskController()
-        : null;
-    if (taskController != null) {
-      taskController.initializeVariables(this);
+    if (task != null) {
+      TaskController taskController = task.getTaskController();
+      if (taskController != null) taskController.initializeVariables(this);
     }
   }
 
@@ -181,8 +179,8 @@
       }
       else { // lazily initialize the swimlane...
         // get the swimlane instance (if there is any)
-        swimlaneInstance = taskMgmtInstance.getInitializedSwimlaneInstance(
-            executionContext, swimlane);
+        swimlaneInstance = taskMgmtInstance.getInitializedSwimlaneInstance(executionContext,
+          swimlane);
 
         // copy the swimlaneInstance assignment into the taskInstance assignment
         copySwimlaneInstanceAssignment(swimlaneInstance);
@@ -198,13 +196,14 @@
   }
 
   public boolean isStartTaskInstance() {
-    boolean isStartTaskInstance = false;
-    if (taskMgmtInstance != null
-      && taskMgmtInstance.getTaskMgmtDefinition() != null) {
-      isStartTaskInstance = task != null
-        && task.equals(taskMgmtInstance.getTaskMgmtDefinition().getStartTask());
+    if (taskMgmtInstance != null) {
+      TaskMgmtDefinition taskMgmtDefinition = taskMgmtInstance.getTaskMgmtDefinition();
+      if (taskMgmtDefinition != null) {
+        return task != null
+          && task.equals(taskMgmtInstance.getTaskMgmtDefinition().getStartTask());
+      }
     }
-    return isStartTaskInstance;
+    return false;
   }
 
   void updatePooledActorsReferences(SwimlaneInstance swimlaneInstance) {
@@ -233,8 +232,7 @@
    * instance are returned.
    */
   public Set getPooledActors() {
-    if (swimlaneInstance != null
-      && (pooledActors == null || pooledActors.isEmpty())) {
+    if (swimlaneInstance != null && (pooledActors == null || pooledActors.isEmpty())) {
       return swimlaneInstance.getPooledActors();
     }
     return pooledActors;
@@ -397,8 +395,7 @@
 
     Transition leavingTransition = node.getLeavingTransition(transitionName);
     if (leavingTransition == null) {
-      throw new JbpmException(node + " has no leaving transition named "
-        + transitionName);
+      throw new JbpmException(node + " has no leaving transition named " + transitionName);
     }
     end(leavingTransition);
   }
@@ -411,10 +408,10 @@
    * not trigger execution to move on, the transition is ignored.
    */
   public void end(Transition transition) {
-    if (this.end != null) {
+    if (end != null) {
       throw new IllegalStateException(this + " has ended");
     }
-    if (this.isSuspended) {
+    if (isSuspended) {
       throw new JbpmException(this + " is suspended");
     }
 
@@ -423,7 +420,7 @@
     this.isOpen = false;
 
     // fire the task instance end event
-    if ((task != null) && (token != null)) {
+    if (task != null && token != null) {
       ExecutionContext executionContext = new ExecutionContext(token);
       executionContext.setTask(task);
       executionContext.setTaskInstance(this);
@@ -440,20 +437,18 @@
 
     // check whether completing this task causes execution to proceed
     if (isSignalling) {
-      this.isSignalling = false;
+      isSignalling = false;
 
-      if (this.isStartTaskInstance() // ending start task leads to signal
-        || (task != null && token != null && task.getTaskNode() != null && task.getTaskNode()
-            .completionTriggersSignal(this))) {
+      TaskNode taskNode;
+      if (isStartTaskInstance() // ending start task leads to signal
+        || (task != null && token != null && (taskNode = task.getTaskNode()) != null && taskNode.completionTriggersSignal(this))) {
 
         if (transition == null) {
-          log.debug("completion of " + task
-            + " results in taking the default transition");
+          log.debug("taking default transition after completing " + task);
           token.signal();
         }
         else {
-          log.debug("completion of " + task.getName() + " results in taking "
-            + transition);
+          log.debug("taking" + transition + " after completing " + task);
           token.signal(transition);
         }
       }
@@ -509,7 +504,8 @@
   // task form ////////////////////////////////////////////////////////////////
 
   public boolean isLast() {
-    return ((token != null) && (taskMgmtInstance != null) && (!taskMgmtInstance.hasUnfinishedTasks(token)));
+    return token != null && taskMgmtInstance != null
+      && !taskMgmtInstance.hasUnfinishedTasks(token);
   }
 
   /**
@@ -539,7 +535,7 @@
   public String toString() {
     return "TaskInstance"
       + (name != null ? '(' + name + ')' : id != 0 ? "(" + id + ')'
-          : '@' + Integer.toHexString(hashCode()));
+        : '@' + Integer.toHexString(hashCode()));
   }
 
   // private //////////////////////////////////////////////////////////////////
@@ -562,8 +558,7 @@
 
   protected VariableContainer getParentVariableContainer() {
     ContextInstance contextInstance = getContextInstance();
-    return contextInstance != null ? contextInstance.getOrCreateTokenVariableMap(token)
-        : null;
+    return contextInstance != null ? contextInstance.getOrCreateTokenVariableMap(token) : null;
   }
 
   // getters and setters //////////////////////////////////////////////////////



More information about the jbpm-commits mailing list