[jbpm-commits] JBoss JBPM SVN: r2899 - in projects/spec/trunk/modules: api/src/main/java/org/jbpm/api/service and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Nov 13 04:58:13 EST 2008


Author: thomas.diesler at jboss.com
Date: 2008-11-13 04:58:13 -0500 (Thu, 13 Nov 2008)
New Revision: 2899

Added:
   projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/WaitStateImpl.java
Removed:
   projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/WaitTaskImpl.java
Modified:
   projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/runtime/preview/TokenExecutor.java
   projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ExecutionService.java
   projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ProcessImpl.java
   projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ReceiveTaskImpl.java
   projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/UserTaskImpl.java
   projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/builder/ProcessBuilderImpl.java
   projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/DelegatingToken.java
   projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/InProcessTokenExecutor.java
   projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/ThreadingTokenExecutor.java
   projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/TokenImpl.java
   projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/service/ExecutionServiceImpl.java
   projects/spec/trunk/modules/ri/src/main/resources/jbpm-cfg-beans.xml
Log:
Token.signal() - ok

Modified: projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/runtime/preview/TokenExecutor.java
===================================================================
--- projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/runtime/preview/TokenExecutor.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/runtime/preview/TokenExecutor.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -58,12 +58,12 @@
   /**
    * Suspend a {@link Token}
    */
-  String suspend(Token token);
+  void suspend(Token token);
 
   /**
    * Activate a {@link Token}
    */
-  Token activate(String tokenID);
+  void activate(Token token);
 
   /**
    * Move a given {@link Token} along a given flow.

Modified: projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ExecutionService.java
===================================================================
--- projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ExecutionService.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/api/src/main/java/org/jbpm/api/service/ExecutionService.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -55,14 +55,6 @@
   }
 
   /**
-   * Start the Process
-   * 
-   * @param proc The Process to start
-   * @param att The Attachments in the ExecutionContext
-   */
-  public abstract void startProcess(Process proc, Attachments att);
-
-  /**
    * Start the Process from a given start event
    * 
    * @param start The StartEvent that triggers the process

Modified: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ProcessImpl.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ProcessImpl.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ProcessImpl.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -38,11 +38,15 @@
 import org.hibernate.Hibernate;
 import org.hibernate.Session;
 import org.jbpm.api.Constants;
+import org.jbpm.api.InvalidProcessException;
 import org.jbpm.api.client.Process;
 import org.jbpm.api.client.ProcessDefinition;
 import org.jbpm.api.client.ProcessEngine;
 import org.jbpm.api.client.Token;
+import org.jbpm.api.client.Token.TokenStatus;
 import org.jbpm.api.model.Node;
+import org.jbpm.api.model.StartEvent;
+import org.jbpm.api.model.Event.EventDetailType;
 import org.jbpm.api.model.builder.preview.ObjectNameFactory;
 import org.jbpm.api.model.preview.Assignment;
 import org.jbpm.api.model.preview.Group;
@@ -241,11 +245,25 @@
 
   private Token startProcessInternal(Attachments att)
   {
+    @SuppressWarnings("serial")
+    class InitialFlow extends SequenceFlowImpl
+    {
+      InitialFlow(StartEvent start)
+      {
+        super(start.getName());
+      }
+    }
+    
     // Prepare the process to start
-    startProcessPrepare();
+    StartEvent start = prepareProcessStart();
+    setProcessStatus(ProcessStatus.Active);
+
+    // Setup the initial token
+    TokenImpl token = new TokenImpl(this, att);
+    token.setLastFlow(new InitialFlow(start));
+    token.setTokenStatus(TokenStatus.Started);
     
-    TokenImpl token = new TokenImpl(this, att);
-    return token;
+    return token.signal();
   }
   
   public ObjectName startProcessAsync()
@@ -261,13 +279,13 @@
   private ObjectName startProcessAsyncInternal(Attachments att)
   {
     // Prepare the process to start
-    startProcessPrepare();
+	  StartEvent start = prepareProcessStart();
     
     ProcessEngine engine = getProcessEngine();
     ExecutionService exService = engine.getService(ExecutionService.class);
     try
     {
-      exService.startProcess(this, att);
+      exService.startProcess(this, start, att);
       return getKey();
     }
     catch (RuntimeException rte)
@@ -279,20 +297,40 @@
     }
   }
 
-  private void startProcessPrepare()
+  private StartEvent prepareProcessStart()
   {
     // Veriy the process state
     ProcessStatus procStatus = getProcessStatus();
     if (procStatus != ProcessStatus.None && procStatus != ProcessStatus.Ready)
       throw new IllegalStateException("Cannot start process in state: " + procStatus);
 
+    // Get the None Start Event if there is one and start the initial flow
+    StartEvent start = null;
+    for (StartEvent aux : getNodes(StartEvent.class))
+    {
+      if (aux.getTriggerType() == EventDetailType.None)
+      {
+        if (start != null)
+          throw new InvalidProcessException("Process cannot have multiple start events with no trigger");
+        start = aux;
+      }
+    }
+    if (start == null)
+    {
+      List<StartEvent> startEvents = getNodes(StartEvent.class);
+      throw new IllegalStateException("Cannot obtain StartEvent of type 'None' to start the process explicitly: " + startEvents);
+    }
+    
     // Register the process if needed
     ProcessEngine engine = getProcessEngine();
     ProcessInstanceService procService = engine.getService(ProcessInstanceService.class);
     if (procService.getProcess(getKey()) == null)
       procService.registerProcess(this);
+    
+    return start;
   }
 
+
   public ProcessStatus waitForEnd()
   {
     return waitForEndInternal(0);

Modified: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ReceiveTaskImpl.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ReceiveTaskImpl.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ReceiveTaskImpl.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -142,7 +142,7 @@
       // Activate the suspended token
       if (suspendedToken != null)
       {
-        tokenExecutor.activate(suspendedToken.getTokenID());
+        tokenExecutor.activate(suspendedToken);
         suspendedToken = null;
       }
     }

Modified: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/UserTaskImpl.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/UserTaskImpl.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/UserTaskImpl.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -176,7 +176,7 @@
       // Activate the suspended token
       if (suspendedToken != null)
       {
-        tokenExecutor.activate(suspendedToken.getTokenID());
+        tokenExecutor.activate(suspendedToken);
         suspendedToken = null;
       }
     }

Copied: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/WaitStateImpl.java (from rev 2897, projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/WaitTaskImpl.java)
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/WaitStateImpl.java	                        (rev 0)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/WaitStateImpl.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.ri.model;
+
+//$Id$
+
+import javax.persistence.Entity;
+
+import org.jbpm.api.client.Token;
+import org.jbpm.api.model.Node;
+import org.jbpm.api.model.ProcessStructure;
+import org.jbpm.api.model.WaitState;
+import org.jbpm.api.runtime.preview.FlowHandler;
+import org.jbpm.api.runtime.preview.TokenExecutor;
+import org.jbpm.ri.model.builder.SingleInFlowSupport;
+import org.jbpm.ri.model.builder.SingleOutFlowSupport;
+
+/**
+ * A WaitTask is an Atomic Activity that suspends the Token.
+ *
+ * If the Process is executed in the Thread of the calling client, this will return 
+ * control to the client. 
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 11-Nov-2008
+ */
+ at Entity(name = "BPMWaitState")
+public class WaitStateImpl extends TaskImpl implements WaitState, SingleOutFlowSupport, SingleInFlowSupport
+{
+  // provide serial version UID
+  private static final long serialVersionUID = 1L;
+
+  public WaitStateImpl(ProcessStructure procStruct, String name)
+  {
+    super(procStruct, TaskType.Wait, name);
+  }
+
+  // Persistence ctor
+  protected WaitStateImpl()
+  {
+  }
+
+  @Override
+  protected FlowHandler getDefaultFlowHandler()
+  {
+    final Node thisNode = this;
+    return new FlowHandler()
+    {
+      private static final long serialVersionUID = 1L;
+
+      public void execute(TokenExecutor tokenExecutor, Token token)
+      {
+        tokenExecutor.suspend(token);
+      }
+
+      @Override
+      public Node getNode()
+      {
+        return thisNode;
+      }
+
+      @Override
+      public void setNode(Node node)
+      {
+      }
+    };
+  }
+
+  public String toString()
+  {
+    return "Task[" + getTaskType() + "," + getName() + "]";
+  }
+}
\ No newline at end of file

Deleted: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/WaitTaskImpl.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/WaitTaskImpl.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/WaitTaskImpl.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -1,92 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.ri.model;
-
-//$Id$
-
-import javax.persistence.Entity;
-
-import org.jbpm.api.client.Token;
-import org.jbpm.api.model.Node;
-import org.jbpm.api.model.ProcessStructure;
-import org.jbpm.api.model.WaitState;
-import org.jbpm.api.runtime.preview.FlowHandler;
-import org.jbpm.api.runtime.preview.TokenExecutor;
-import org.jbpm.ri.model.builder.SingleInFlowSupport;
-import org.jbpm.ri.model.builder.SingleOutFlowSupport;
-
-/**
- * A WaitTask is an Atomic Activity that suspends the Token.
- *
- * If the Process is executed in the Thread of the calling client, this will return 
- * control to the client. 
- * 
- * @author thomas.diesler at jboss.com
- * @since 11-Nov-2008
- */
- at Entity(name = "BPMWaitTask")
-public class WaitTaskImpl extends TaskImpl implements WaitState, SingleOutFlowSupport, SingleInFlowSupport
-{
-  // provide serial version UID
-  private static final long serialVersionUID = 1L;
-
-  public WaitTaskImpl(ProcessStructure procStruct, String name)
-  {
-    super(procStruct, TaskType.Wait, name);
-  }
-
-  // Persistence ctor
-  protected WaitTaskImpl()
-  {
-  }
-
-  @Override
-  protected FlowHandler getDefaultFlowHandler()
-  {
-    final Node thisNode = this;
-    return new FlowHandler()
-    {
-      private static final long serialVersionUID = 1L;
-
-      public void execute(TokenExecutor tokenExecutor, Token token)
-      {
-        tokenExecutor.suspend(token);
-      }
-
-      @Override
-      public Node getNode()
-      {
-        return thisNode;
-      }
-
-      @Override
-      public void setNode(Node node)
-      {
-      }
-    };
-  }
-
-  public String toString()
-  {
-    return "Task[" + getTaskType() + "," + getName() + "]";
-  }
-}
\ No newline at end of file

Modified: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/builder/ProcessBuilderImpl.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/builder/ProcessBuilderImpl.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/builder/ProcessBuilderImpl.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -61,7 +61,7 @@
 import org.jbpm.ri.model.StartEventImpl;
 import org.jbpm.ri.model.TaskImpl;
 import org.jbpm.ri.model.UserTaskImpl;
-import org.jbpm.ri.model.WaitTaskImpl;
+import org.jbpm.ri.model.WaitStateImpl;
 
 /**
  * The ProcessBuilder can be used to dynamically build a {@link Process}.
@@ -182,7 +182,7 @@
     }
     else if (type == TaskType.Wait)
     {
-      node = new WaitTaskImpl(procStruct, name);
+      node = new WaitStateImpl(procStruct, name);
     }
     else if (type == TaskType.Script)
     {

Modified: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/DelegatingToken.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/DelegatingToken.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/DelegatingToken.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -123,9 +123,9 @@
   }
 
   @Override
-  public void signal()
+  public Token signal()
   {
-    delegateToken.signal();
+    return delegateToken.signal();
   }
   
   public String toString()

Modified: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/InProcessTokenExecutor.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/InProcessTokenExecutor.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/InProcessTokenExecutor.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -23,10 +23,8 @@
 
 //$Id$
 
-import org.jbpm.api.NotImplementedException;
 import org.jbpm.api.client.Process;
 import org.jbpm.api.client.Token;
-import org.jbpm.api.client.Process.ProcessStatus;
 import org.jbpm.api.client.Token.TokenStatus;
 import org.jbpm.api.model.SequenceFlow;
 import org.jbpm.api.runtime.preview.TokenExecutor;
@@ -44,6 +42,7 @@
   // provide logging
   final static Logger log = LoggerFactory.getLogger(InProcessTokenExecutor.class);
 
+  @SuppressWarnings("unused")
   private Process proc;
 
   public InProcessTokenExecutor(Process proc)
@@ -51,38 +50,35 @@
     this.proc = proc;
   }
 
+  @Override
   public void create(Token token, SequenceFlow initialFlow)
   {
     MutableToken mutableToken = (MutableToken)token;
     mutableToken.setTokenStatus(TokenStatus.Created);
     mutableToken.setLastFlow(initialFlow);
-
     log.debug("Create Token: " + token);
   }
 
+  @Override
   public void start(Token token)
   {
-    ProcessStatus procStatus = proc.getProcessStatus();
-    if (procStatus != ProcessStatus.Ready && procStatus != ProcessStatus.Active)
-      throw new IllegalStateException("Cannot start token to process in state: " + procStatus);
-
     log.debug("Start Token: " + token);
     MutableToken mutableToken = (MutableToken)token;
     mutableToken.setTokenStatus(TokenStatus.Started);
   }
 
+  @Override
   public void move(Token token, SequenceFlow flow)
   {
+    log.debug("Move Token: " + token);
     if (flow == null)
-      throw new IllegalArgumentException("Flow cannot be null");
-
-    if (token.getTokenStatus() != TokenStatus.Started)
-      throw new IllegalStateException("Cannot move token in state: " + token.getTokenStatus());
-
+      throw new IllegalArgumentException("SequenceFlow cannot be null");
+    
     MutableToken mutableToken = (MutableToken)token;
     mutableToken.setLastFlow(flow);
   }
 
+  @Override
   public void stop(Token token)
   {
     log.debug("Stop Token: " + token);
@@ -90,6 +86,7 @@
     mutableToken.setTokenStatus(TokenStatus.Stoped);
   }
 
+  @Override
   public void destroy(Token token)
   {
     log.debug("Destroy Token: " + token);
@@ -97,13 +94,19 @@
     mutableToken.setTokenStatus(TokenStatus.Destroyed);
   }
 
-  public String suspend(Token token)
+  @Override
+  public void suspend(Token token)
   {
-    throw new NotImplementedException();
+    log.debug("Suspend Token: " + token);
+    MutableToken mutableToken = (MutableToken)token;
+    mutableToken.setTokenStatus(TokenStatus.Suspended);
   }
 
-  public Token activate(String tokenID)
+  @Override
+  public void activate(Token token)
   {
-    throw new NotImplementedException();
+    log.debug("Activate Token: " + token);
+    MutableToken mutableToken = (MutableToken)token;
+    mutableToken.setTokenStatus(TokenStatus.Started);
   }
 }
\ No newline at end of file

Modified: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/ThreadingTokenExecutor.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/ThreadingTokenExecutor.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/ThreadingTokenExecutor.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -81,6 +81,7 @@
     }
   }
 
+  @Override
   public void create(Token token, SequenceFlow initialFlow)
   {
     synchronized (runnableTokens)
@@ -96,6 +97,7 @@
     }
   }
 
+  @Override
   public void start(Token token)
   {
     synchronized (runnableTokens)
@@ -113,6 +115,7 @@
     }
   }
 
+  @Override
   public void move(Token token, SequenceFlow flow)
   {
     synchronized (runnableTokens)
@@ -128,6 +131,7 @@
     }
   }
 
+  @Override
   public void stop(Token token)
   {
     synchronized (runnableTokens)
@@ -138,6 +142,7 @@
     }
   }
 
+  @Override
   public void destroy(Token token)
   {
     synchronized (runnableTokens)
@@ -149,7 +154,8 @@
     }
   }
 
-  public String suspend(Token token)
+  @Override
+  public void suspend(Token token)
   {
     synchronized (runnableTokens)
     {
@@ -163,20 +169,19 @@
 
       // Release the thread for a suspended token
       rtToken.releaseThread();
-
-      return token.getTokenID();
     }
   }
 
-  public Token activate(String tokenID)
+  @Override
+  public void activate(Token token)
   {
     synchronized (runnableTokens)
     {
+      String tokenID = token.getTokenID();
       RunnableToken rtToken = runnableTokens.get(tokenID);
       if (rtToken == null)
         throw new IllegalStateException("Not a runnable token: " + tokenID);
 
-      Token token = rtToken.getToken();
       if (token.getTokenStatus() != TokenStatus.Suspended)
         throw new IllegalStateException("Activate token in state: " + token.getTokenStatus());
 
@@ -187,8 +192,6 @@
       rtToken = new RunnableToken(this, rtProc, mutableToken);
       runnableTokens.put(token.getTokenID(), rtToken);
       executor.submit(rtToken);
-
-      return token;
     }
   }
 }
\ No newline at end of file

Modified: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/TokenImpl.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/TokenImpl.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/TokenImpl.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -25,26 +25,31 @@
 
 import org.hibernate.Session;
 import org.jboss.util.id.UID;
+import org.jbpm.api.client.Process;
 import org.jbpm.api.client.Token;
-import org.jbpm.api.client.Process;
+import org.jbpm.api.client.Process.ProcessStatus;
 import org.jbpm.api.model.Node;
 import org.jbpm.api.model.SequenceFlow;
+import org.jbpm.api.model.WaitState;
 import org.jbpm.api.runtime.Attachments;
 import org.jbpm.api.runtime.Attachments.Key;
 import org.jbpm.api.runtime.preview.BasicExecutionContext;
 import org.jbpm.api.runtime.preview.ExecutionContext;
+import org.jbpm.api.runtime.preview.TokenExecutor;
+import org.jbpm.api.service.ProcessInstanceService;
+import org.jbpm.ri.service.ProcessServiceImpl;
 
 /**
  * A Token is a descriptive construct used to describe how the flow of a Process will proceed at runtime.
  * 
- * By tracking how the Token traverses the Flow Objects, gets diverted through alternative paths, 
- * and gets split into parallel paths, the normal Sequence Flow should be completely definable.
+ * By tracking how the Token traverses the Flow Objects, gets diverted through alternative paths, and gets split into
+ * parallel paths, the normal Sequence Flow should be completely definable.
  * 
- * A Token will have a unique identity that can be used to separate multiple Tokens that may exist because of 
- * concurrent process instances or the splitting of the Token for parallel processing within a single process instance.
+ * A Token will have a unique identity that can be used to separate multiple Tokens that may exist because of concurrent
+ * process instances or the splitting of the Token for parallel processing within a single process instance.
  * 
  * @author Thomas.Diesler at jboss.com
- * @since 20-Apr-2007
+ * @since 29-Sep-2008
  */
 public class TokenImpl implements MutableToken
 {
@@ -52,7 +57,7 @@
   private SequenceFlow flow;
   private ExecutionContext context;
   private TokenStatus status;
-  private Process process;
+  private Process proc;
   private Session session;
 
   /**
@@ -63,7 +68,7 @@
     this.context = new BasicExecutionContext(att);
     this.id = new UID().toString();
     this.status = TokenStatus.Created;
-    this.process = process;
+    this.proc = process;
   }
 
   @Override
@@ -83,11 +88,11 @@
   {
     this.status = status;
   }
-  
+
   @Override
   public Process getProcess()
   {
-    return process;
+    return proc;
   }
 
   @Override
@@ -95,14 +100,14 @@
   {
     return context;
   }
-  
+
   @Override
   public Node getCurrentNode()
   {
     String targetRef = flow.getTargetRef();
     return getProcess().getNode(targetRef);
   }
-  
+
   @Override
   public SequenceFlow getLastFlow()
   {
@@ -114,13 +119,55 @@
   {
     this.flow = flow;
   }
-  
+
   @Override
   public Token signal()
   {
+    Node node = getCurrentNode();
+    if (node == null)
+      throw new IllegalStateException("Cannot obtain current node");
+
+    TokenExecutor tokenExecutor = new InProcessTokenExecutor(proc);
+    RuntimeContext rtContext = new RuntimeContext(tokenExecutor);
+
+    // Add the interceptors that are defined on the ProcessService
+    ProcessServiceImpl procService = (ProcessServiceImpl)node.getProcessEngine().getService(ProcessInstanceService.class);
+    for (NodeInterceptor itor : procService.getNodeInterceptors())
+      rtContext.addInterceptor(itor);
+
+    // Activate a suspened token
+    if (getTokenStatus() == TokenStatus.Suspended)
+    {
+      WaitState task = (WaitState)node;
+      SequenceFlow outFlow = task.getOutFlow();
+      tokenExecutor.activate(this);
+      tokenExecutor.move(this, outFlow);
+    }
+
+    // Travers the token along the nodes
+    while (continueTokenExecution())
+    {
+      // Get the target node
+      node = getCurrentNode();
+
+      // Create a Token that includes node properties
+      DelegatingToken tokCopy = new DelegatingToken(this);
+      rtContext.setToken(tokCopy);
+
+      // Call the interceptor chain
+      rtContext.next();
+    }
+
     return this;
   }
 
+  private boolean continueTokenExecution()
+  {
+    TokenStatus tokStatus = getTokenStatus();
+    ProcessStatus procStatus = getProcess().getProcessStatus();
+    return procStatus == ProcessStatus.Active && tokStatus == TokenStatus.Started;
+  }
+
   @Override
   public Session getSession()
   {
@@ -136,24 +183,24 @@
   @Override
   public MutableToken copyToken()
   {
-    return new TokenImpl(process, context);
+    return new TokenImpl(proc, context);
   }
-  
+
   @Override
   public void mergeToken(Token token)
   {
     ExecutionContext mergeContext = token.getExecutionContext();
-    for(Key key : mergeContext.getAttachmentKeys())
+    for (Key key : mergeContext.getAttachmentKeys())
     {
       Object mergeValue = mergeContext.getAttachment(key.getClassPart(), key.getNamePart());
       Object existValue = context.getAttachment(key.getClassPart(), key.getNamePart());
       if (existValue != null && existValue.equals(mergeValue) == false)
         throw new IllegalStateException("Cannot merge the same key with different values: " + key);
-      
+
       context.addAttachment(key.getClassPart(), key.getNamePart(), mergeValue);
     }
   }
-  
+
   public String toString()
   {
     return "[sf=" + getLastFlow() + ",status=" + getTokenStatus() + ",ctx=" + getExecutionContext() + ",id=" + id + "]";

Modified: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/service/ExecutionServiceImpl.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/service/ExecutionServiceImpl.java	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/service/ExecutionServiceImpl.java	2008-11-13 09:58:13 UTC (rev 2899)
@@ -24,21 +24,18 @@
 // $Id$
 
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import javax.management.ObjectName;
 
 import org.jbpm.api.BPMException;
-import org.jbpm.api.InvalidProcessException;
 import org.jbpm.api.ProcessTimeoutException;
-import org.jbpm.api.client.Token;
 import org.jbpm.api.client.Process;
 import org.jbpm.api.client.ProcessEngine;
+import org.jbpm.api.client.Token;
 import org.jbpm.api.client.Process.ProcessStatus;
 import org.jbpm.api.model.Expression;
 import org.jbpm.api.model.StartEvent;
-import org.jbpm.api.model.Event.EventDetailType;
 import org.jbpm.api.model.preview.Assignment;
 import org.jbpm.api.model.preview.Assignment.AssignTime;
 import org.jbpm.api.model.preview.Signal.SignalType;
@@ -82,23 +79,6 @@
   }
 
   @Override
-  public void startProcess(Process proc, Attachments att)
-  {
-    // Get the None Start Event if there is one and start the initial flow
-    StartEvent start = getNoneStartEvent(proc);
-    if (start == null)
-    {
-      List<StartEvent> startEvents = proc.getNodes(StartEvent.class);
-      throw new IllegalStateException("Cannot obtain StartEvent.None to start the process explicitly: " + startEvents);
-    }
-
-    if (proc.getProcessStatus() == ProcessStatus.Active)
-      throw new IllegalStateException("Cannot start an already active process");
-
-    startProcessInternal(proc, start, att);
-  }
-
-  @Override
   public void startProcess(Process proc, StartEvent start, Attachments att)
   {
     startProcessInternal(proc, start, att);
@@ -114,7 +94,7 @@
         super(start.getName());
       }
     }
-
+    
     RuntimeProcess rtProc = getRuntimeProcess(proc, false);
     boolean startProcessThread = (rtProc == null);
 
@@ -260,21 +240,6 @@
     return status == ProcessStatus.Cancelled || status == ProcessStatus.Completed || status == ProcessStatus.Aborted;
   }
 
-  private StartEvent getNoneStartEvent(Process proc)
-  {
-    StartEvent start = null;
-    for (StartEvent aux : proc.getNodes(StartEvent.class))
-    {
-      if (aux.getTriggerType() == EventDetailType.None)
-      {
-        if (start != null)
-          throw new InvalidProcessException("Process cannot have multiple start events with no trigger");
-        start = aux;
-      }
-    }
-    return start;
-  }
-
   private RuntimeProcess getRuntimeProcess(Process proc, boolean createNew)
   {
     RuntimeProcess rtProcess;

Modified: projects/spec/trunk/modules/ri/src/main/resources/jbpm-cfg-beans.xml
===================================================================
--- projects/spec/trunk/modules/ri/src/main/resources/jbpm-cfg-beans.xml	2008-11-13 08:55:02 UTC (rev 2898)
+++ projects/spec/trunk/modules/ri/src/main/resources/jbpm-cfg-beans.xml	2008-11-13 09:58:13 UTC (rev 2899)
@@ -53,6 +53,7 @@
           <value>org.jbpm.ri.model.StartEventImpl</value>
           <value>org.jbpm.ri.model.TaskImpl</value>
           <value>org.jbpm.ri.model.UserTaskImpl</value>
+          <value>org.jbpm.ri.model.WaitStateImpl</value>
         </set>
       </property>
     </bean>




More information about the jbpm-commits mailing list