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

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jun 24 15:31:56 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-06-24 15:31:56 -0400 (Thu, 24 Jun 2010)
New Revision: 6436

Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/Token.java
   jbpm3/branches/jbpm-3.2-soa/pom.xml
Log:
improve process instance termination logic
access jboss public repositories non-securely for faster transfers

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java	2010-06-24 06:06:27 UTC (rev 6435)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java	2010-06-24 19:31:56 UTC (rev 6436)
@@ -47,14 +47,14 @@
 import org.jbpm.module.exe.ModuleInstance;
 import org.jbpm.msg.MessageService;
 import org.jbpm.persistence.PersistenceService;
+import org.jbpm.scheduler.SchedulerService;
 import org.jbpm.svc.Services;
 import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
 import org.jbpm.util.Clock;
 
 /**
- * is one execution of a {@link org.jbpm.graph.def.ProcessDefinition}. To create
- * a new process execution of a process definition, just use the
- * {@link #ProcessInstance(ProcessDefinition)}.
+ * is one execution of a {@link org.jbpm.graph.def.ProcessDefinition}. To create a new process
+ * execution of a process definition, just use the {@link #ProcessInstance(ProcessDefinition)}.
  */
 public class ProcessInstance implements Identifiable, Serializable {
 
@@ -81,12 +81,11 @@
   }
 
   /**
-   * creates a new process instance for the given process definition, puts the
-   * root-token (=main path of execution) in the start state and executes the
-   * initial node. In case the initial node is a start-state, it will behave as
-   * a wait state. For each of the optional module definitions contained in the
-   * {@link ProcessDefinition}, the corresponding module instance will be
-   * created.
+   * creates a new process instance for the given process definition, puts the root-token (=main
+   * path of execution) in the start state and executes the initial node. In case the initial
+   * node is a start-state, it will behave as a wait state. For each of the optional module
+   * definitions contained in the {@link ProcessDefinition}, the corresponding module instance
+   * will be created.
    * 
    * @throws JbpmException if processDefinition is null.
    */
@@ -95,16 +94,15 @@
   }
 
   /**
-   * creates a new process instance for the given process definition, puts the
-   * root-token (=main path of execution) in the start state and executes the
-   * initial node. In case the initial node is a start-state, it will behave as
-   * a wait state. For each of the optional module definitions contained in the
-   * {@link ProcessDefinition}, the corresponding module instance will be
-   * created.
+   * creates a new process instance for the given process definition, puts the root-token (=main
+   * path of execution) in the start state and executes the initial node. In case the initial
+   * node is a start-state, it will behave as a wait state. For each of the optional module
+   * definitions contained in the {@link ProcessDefinition}, the corresponding module instance
+   * will be created.
    * 
-   * @param variables will be inserted into the context variables after the
-   * context submodule has been created and before the process-start event is
-   * fired, which is also before the execution of the initial node.
+   * @param variables will be inserted into the context variables after the context submodule
+   * has been created and before the process-start event is fired, which is also before the
+   * execution of the initial node.
    * @throws JbpmException if processDefinition is null.
    */
   public ProcessInstance(ProcessDefinition processDefinition, Map variables) {
@@ -112,16 +110,15 @@
   }
 
   /**
-   * creates a new process instance for the given process definition, puts the
-   * root-token (=main path of execution) in the start state and executes the
-   * initial node. In case the initial node is a start-state, it will behave as
-   * a wait state. For each of the optional module definitions contained in the
-   * {@link ProcessDefinition}, the corresponding module instance will be
-   * created.
+   * creates a new process instance for the given process definition, puts the root-token (=main
+   * path of execution) in the start state and executes the initial node. In case the initial
+   * node is a start-state, it will behave as a wait state. For each of the optional module
+   * definitions contained in the {@link ProcessDefinition}, the corresponding module instance
+   * will be created.
    * 
-   * @param variables will be inserted into the context variables after the
-   * context submodule has been created and before the process-start event is
-   * fired, which is also before the execution of the initial node.
+   * @param variables will be inserted into the context variables after the context submodule
+   * has been created and before the process-start event is fired, which is also before the
+   * execution of the initial node.
    * @throws JbpmException if processDefinition is null.
    */
   public ProcessInstance(ProcessDefinition processDefinition, Map variables, String key) {
@@ -196,7 +193,8 @@
       throw new IllegalArgumentException("module instance is null");
     }
 
-    if (instances == null) instances = new HashMap();
+    if (instances == null)
+      instances = new HashMap();
     instances.put(moduleInstance.getClass().getName(), moduleInstance);
     moduleInstance.setProcessInstance(this);
     return moduleInstance;
@@ -232,7 +230,8 @@
     }
 
     if (moduleInstance == null) {
-      if (transientInstances == null) transientInstances = new HashMap();
+      if (transientInstances == null)
+        transientInstances = new HashMap();
 
       // client requested an instance that is not in the map of instances.
       // so we can safely assume that the client wants a transient instance
@@ -270,9 +269,9 @@
   }
 
   /**
-   * process instance extension for logging. Probably you don't need to access
-   * the logging instance directly. Mostly, {@link Token#addLog(ProcessLog)} is
-   * sufficient and more convenient.
+   * process instance extension for logging. Probably you don't need to access the logging
+   * instance directly. Mostly, {@link Token#addLog(ProcessLog)} is sufficient and more
+   * convenient.
    */
   public LoggingInstance getLoggingInstance() {
     return (LoggingInstance) getInstance(LoggingInstance.class);
@@ -281,8 +280,8 @@
   // operations ///////////////////////////////////////////////////////////////
 
   /**
-   * instructs the main path of execution to continue by taking the default
-   * transition on the current node.
+   * instructs the main path of execution to continue by taking the default transition on the
+   * current node.
    * 
    * @throws IllegalStateException if the token is not active.
    */
@@ -294,8 +293,8 @@
   }
 
   /**
-   * instructs the main path of execution to continue by taking the specified
-   * transition on the current node.
+   * instructs the main path of execution to continue by taking the specified transition on the
+   * current node.
    * 
    * @throws IllegalStateException if the token is not active.
    */
@@ -307,8 +306,8 @@
   }
 
   /**
-   * instructs the main path of execution to continue by taking the specified
-   * transition on the current node.
+   * instructs the main path of execution to continue by taking the specified transition on the
+   * current node.
    * 
    * @throws IllegalStateException if the token is not active.
    */
@@ -323,50 +322,60 @@
    * ends (=cancels) this process instance and all the tokens in it.
    */
   public void end() {
+    // if already ended, do nothing
+    if (end != null)
+      return;
+
+    // record the end time
+    // the end time also indicates that this process instance has ended
+    end = Clock.getCurrentTime();
+
     // end the main path of execution
     rootToken.end();
 
-    if (end == null) {
-      // mark this process instance as ended
-      end = Clock.getCurrentTime();
+    // fire the process-end event
+    ExecutionContext executionContext = new ExecutionContext(rootToken);
+    processDefinition.fireEvent(Event.EVENTTYPE_PROCESS_END, executionContext);
 
-      // fire the process-end event
-      ExecutionContext executionContext = new ExecutionContext(rootToken);
-      processDefinition.fireEvent(Event.EVENTTYPE_PROCESS_END, executionContext);
+    // add the process instance end log
+    rootToken.addLog(new ProcessInstanceEndLog());
 
-      // add the process instance end log
-      rootToken.addLog(new ProcessInstanceEndLog());
+    // check if this process was started as a subprocess of a super process
+    if (superProcessToken != null && !superProcessToken.hasEnded()) {
+      addCascadeProcessInstance(superProcessToken.getProcessInstance());
 
-      // check if this process was started as a subprocess of a super process
-      if (superProcessToken != null && !superProcessToken.hasEnded()) {
-        addCascadeProcessInstance(superProcessToken.getProcessInstance());
+      ExecutionContext superExecutionContext = new ExecutionContext(superProcessToken);
+      superExecutionContext.setSubProcessInstance(this);
+      superProcessToken.signal(superExecutionContext);
+    }
 
-        ExecutionContext superExecutionContext = new ExecutionContext(superProcessToken);
-        superExecutionContext.setSubProcessInstance(this);
-        superProcessToken.signal(superExecutionContext);
-      }
-
-      // make sure jobs for this process instance are canceled
-      // after the process end updates are posted to the database
-      JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
-      if (jbpmContext != null) {
-        Services services = jbpmContext.getServices();
+    // make sure jobs for this process instance are canceled
+    // after the process end updates are posted to the database
+    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
+    if (jbpmContext != null) {
+      Services services = jbpmContext.getServices();
+      PersistenceService persistenceService = services.getPersistenceService();
+      if (persistenceService != null
+        && persistenceService.getJobSession().countDeletableJobsForProcessInstance(this) > 0) {
         MessageService messageService = services.getMessageService();
-        PersistenceService persistenceService = services.getPersistenceService();
-        if (messageService != null && persistenceService != null
-          && persistenceService.getJobSession().countDeletableJobsForProcessInstance(this) > 0) {
+        if (messageService != null) {
           CleanUpProcessJob job = new CleanUpProcessJob(rootToken);
           job.setDueDate(new Date());
           messageService.send(job);
         }
+        else {
+          SchedulerService schedulerService = services.getSchedulerService();
+          if (schedulerService != null) {
+            schedulerService.deleteTimersByProcessInstance(this);
+          }
+        }
       }
     }
   }
 
   /**
-   * suspends this execution. This will make sure that tasks, timers and
-   * messages related to this process instance will not show up in database
-   * queries.
+   * suspends this execution. This will make sure that tasks, timers and messages related to
+   * this process instance will not show up in database queries.
    * 
    * @see #resume()
    */
@@ -376,10 +385,10 @@
   }
 
   /**
-   * resumes a suspended execution. All timers that have been suspended might
-   * fire if the duedate has been passed. If an admin resumes a process
-   * instance, the option should be offered to update, remove and create the
-   * timers and messages related to this process instance.
+   * resumes a suspended execution. All timers that have been suspended might fire if the
+   * duedate has been passed. If an admin resumes a process instance, the option should be
+   * offered to update, remove and create the timers and messages related to this process
+   * instance.
    * 
    * @see #suspend()
    */
@@ -397,7 +406,8 @@
     if (runtimeAction == null) {
       throw new IllegalArgumentException("runtime action is null");
     }
-    if (runtimeActions == null) runtimeActions = new ArrayList();
+    if (runtimeActions == null)
+      runtimeActions = new ArrayList();
     runtimeActions.add(runtimeAction);
     runtimeAction.processInstance = this;
     return runtimeAction;
@@ -448,11 +458,9 @@
   }
 
   /**
-   * looks up the token in the tree, specified by the slash-separated token
-   * path.
+   * looks up the token in the tree, specified by the slash-separated token path.
    * 
-   * @param tokenPath is a slash-separated name that specifies a token in the
-   * tree.
+   * @param tokenPath is a slash-separated name that specifies a token in the tree.
    * @return the specified token or null if the token is not found.
    */
   public Token findToken(String tokenPath) {
@@ -485,18 +493,22 @@
   // equals ///////////////////////////////////////////////////////////////////
 
   public boolean equals(Object o) {
-    if (o == this) return true;
-    if (!(o instanceof ProcessInstance)) return false;
+    if (o == this)
+      return true;
+    if (!(o instanceof ProcessInstance))
+      return false;
 
     ProcessInstance other = (ProcessInstance) o;
-    if (id != 0 && id == other.getId()) return true;
+    if (id != 0 && id == other.getId())
+      return true;
 
     return key != null && key.equals(other.getKey())
       && processDefinition.equals(other.getProcessDefinition());
   }
 
   public int hashCode() {
-    if (key == null) return super.hashCode();
+    if (key == null)
+      return super.hashCode();
 
     int result = 295436291 + key.hashCode();
     result = 1367411281 * result + processDefinition.hashCode();

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-06-24 06:06:27 UTC (rev 6435)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/exe/Token.java	2010-06-24 19:31:56 UTC (rev 6436)
@@ -224,7 +224,8 @@
    * resolves to true.
    */
   public Set getAvailableTransitions() {
-    if (node == null) return Collections.EMPTY_SET;
+    if (node == null)
+      return Collections.EMPTY_SET;
 
     Set availableTransitions = new HashSet();
     addAvailableTransitionsOfNode(node, availableTransitions);
@@ -244,7 +245,8 @@
         if (conditionExpression != null) {
           Boolean result = (Boolean) JbpmExpressionEvaluator.evaluate(conditionExpression,
             new ExecutionContext(this), Boolean.class);
-          if (Boolean.TRUE.equals(result)) availableTransitions.add(transition);
+          if (Boolean.TRUE.equals(result))
+            availableTransitions.add(transition);
         }
         else {
           availableTransitions.add(transition);
@@ -276,22 +278,24 @@
   public void end(boolean verifyParentTermination) {
     // if already ended, do nothing
     if (end != null) {
-      if (parent != null) log.warn(this + " has ended already");
+      if (parent != null)
+        log.warn(this + " has ended already");
       return;
     }
 
+    // record the end date
+    // the end date also indicates that this token has ended
+    end = Clock.getCurrentTime();
+
     // ended tokens cannot reactivate parents
     isAbleToReactivateParent = false;
 
-    // set the end date
-    // the end date also indicates that this token has ended
-    end = Clock.getCurrentTime();
-
     // end all this token's children
     if (children != null) {
       for (Iterator iter = children.values().iterator(); iter.hasNext();) {
         Token child = (Token) iter.next();
-        if (!child.hasEnded()) child.end();
+        if (!child.hasEnded())
+          child.end();
       }
     }
 
@@ -309,7 +313,8 @@
     // if there are tasks associated to this token,
     // remove signaling capabilities
     TaskMgmtInstance taskMgmtInstance = processInstance.getTaskMgmtInstance();
-    if (taskMgmtInstance != null) taskMgmtInstance.removeSignalling(this);
+    if (taskMgmtInstance != null)
+      taskMgmtInstance.removeSignalling(this);
 
     if (verifyParentTermination) {
       // if this is the last active token of the parent,
@@ -325,7 +330,8 @@
   }
 
   public void addComment(Comment comment) {
-    if (comments == null) comments = new ArrayList();
+    if (comments == null)
+      comments = new ArrayList();
     comments.add(comment);
     comment.setToken(this);
   }
@@ -356,7 +362,8 @@
     if (children != null) {
       for (Iterator iter = children.values().iterator(); iter.hasNext();) {
         Token child = (Token) iter.next();
-        if (!child.hasEnded()) return true;
+        if (!child.hasEnded())
+          return true;
       }
     }
     return false;
@@ -392,7 +399,8 @@
    */
   public void endCompositeLog() {
     LoggingInstance loggingInstance = processInstance.getLoggingInstance();
-    if (loggingInstance != null) loggingInstance.endCompositeLog();
+    if (loggingInstance != null)
+      loggingInstance.endCompositeLog();
   }
 
   // various information extraction methods ///////////////////////////////////
@@ -418,8 +426,10 @@
   }
 
   public String getFullName() {
-    if (parent == null) return "/";
-    if (parent.getParent() == null) return "/" + name;
+    if (parent == null)
+      return "/";
+    if (parent.getParent() == null)
+      return "/" + name;
     return parent.getFullName() + "/" + name;
   }
 
@@ -452,7 +462,8 @@
   }
 
   public Token findToken(String relativeTokenPath) {
-    if (relativeTokenPath == null) return null;
+    if (relativeTokenPath == null)
+      return null;
     String path = relativeTokenPath.trim();
     if (("".equals(path)) || (".".equals(path))) {
       return this;
@@ -504,12 +515,14 @@
   public void checkImplicitTermination() {
     if (isTerminationImplicit && node.hasNoLeavingTransitions()) {
       end();
-      if (processInstance.isTerminatedImplicitly()) processInstance.end();
+      if (processInstance.isTerminatedImplicitly())
+        processInstance.end();
     }
   }
 
   public boolean isTerminatedImplicitly() {
-    if (end != null) return true;
+    if (end != null)
+      return true;
 
     Map leavingTransitions = node.getLeavingTransitionsMap();
     if (leavingTransitions != null && !leavingTransitions.isEmpty()) {
@@ -520,7 +533,8 @@
     // loop over all active child tokens
     for (Iterator iter = getActiveChildren().values().iterator(); iter.hasNext();) {
       Token child = (Token) iter.next();
-      if (!child.isTerminatedImplicitly()) return false;
+      if (!child.isTerminatedImplicitly())
+        return false;
     }
     // if none of the above, this token is terminated implicitly
     return true;
@@ -552,13 +566,15 @@
     JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
     if (jbpmContext != null) {
       JobSession jobSession = jbpmContext.getJobSession();
-      if (jobSession != null) jobSession.suspendJobs(this);
+      if (jobSession != null)
+        jobSession.suspendJobs(this);
     }
   }
 
   void suspendTaskInstances() {
     TaskMgmtInstance taskMgmtInstance = processInstance.getTaskMgmtInstance();
-    if (taskMgmtInstance != null) taskMgmtInstance.suspend(this);
+    if (taskMgmtInstance != null)
+      taskMgmtInstance.suspend(this);
   }
 
   /**
@@ -583,23 +599,28 @@
     JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
     if (jbpmContext != null) {
       JobSession jobSession = jbpmContext.getJobSession();
-      if (jobSession != null) jobSession.resumeJobs(this);
+      if (jobSession != null)
+        jobSession.resumeJobs(this);
     }
   }
 
   void resumeTaskInstances() {
     TaskMgmtInstance taskMgmtInstance = processInstance.getTaskMgmtInstance();
-    if (taskMgmtInstance != null) taskMgmtInstance.resume(this);
+    if (taskMgmtInstance != null)
+      taskMgmtInstance.resume(this);
   }
 
   // equals ///////////////////////////////////////////////////////////////////
 
   public boolean equals(Object o) {
-    if (o == this) return true;
-    if (!(o instanceof Token)) return false;
+    if (o == this)
+      return true;
+    if (!(o instanceof Token))
+      return false;
 
     Token other = (Token) o;
-    if (id != 0 && id == other.getId()) return true;
+    if (id != 0 && id == other.getId())
+      return true;
 
     return (name != null ? name.equals(other.getName()) : other.getName() == null)
       && (parent != null ? parent.equals(other.getParent())
@@ -636,11 +657,13 @@
    * @see #unlock(String)
    */
   public void lock(String lockOwner) {
-    if (lockOwner == null) throw new JbpmException("lock owner is null");
+    if (lockOwner == null)
+      throw new JbpmException("lock owner is null");
 
     if (lock == null) {
       lock = lockOwner;
-      if (log.isDebugEnabled()) log.debug('\'' + lockOwner + "' locked " + this);
+      if (log.isDebugEnabled())
+        log.debug('\'' + lockOwner + "' locked " + this);
     }
     else if (!lock.equals(lockOwner)) {
       throw new JbpmException('\'' + lockOwner + "' cannot lock " + this + " because '" + lock
@@ -659,7 +682,8 @@
       }
 
       lock = null;
-      if (log.isDebugEnabled()) log.debug('\'' + lockOwner + "' unlocked " + this);
+      if (log.isDebugEnabled())
+        log.debug('\'' + lockOwner + "' unlocked " + this);
     }
     else {
       log.warn(this + " was already unlocked");
@@ -688,7 +712,8 @@
   public void forceUnlock() {
     if (lock != null) {
       lock = null;
-      if (log.isDebugEnabled()) log.debug("forcefully unlocked " + this);
+      if (log.isDebugEnabled())
+        log.debug("forcefully unlocked " + this);
     }
     else {
       log.warn(this + " was unlocked already");

Modified: jbpm3/branches/jbpm-3.2-soa/pom.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/pom.xml	2010-06-24 06:06:27 UTC (rev 6435)
+++ jbpm3/branches/jbpm-3.2-soa/pom.xml	2010-06-24 19:31:56 UTC (rev 6436)
@@ -415,7 +415,7 @@
     <repository>
       <id>jboss-public-repository-group</id>
       <name>JBoss Public Maven Repository Group</name>
-      <url>https://repository.jboss.org/nexus/content/groups/public/</url>
+      <url>http://repository.jboss.org/nexus/content/groups/public/</url>
       <releases>
         <enabled>true</enabled>
         <updatePolicy>never</updatePolicy>
@@ -430,7 +430,7 @@
     <pluginRepository>
       <id>jboss-public-repository-group</id>
       <name>JBoss Public Maven Repository Group</name>
-      <url>https://repository.jboss.org/nexus/content/groups/public/</url>
+      <url>http://repository.jboss.org/nexus/content/groups/public/</url>
       <releases>
         <enabled>true</enabled>
         <updatePolicy>never</updatePolicy>



More information about the jbpm-commits mailing list