Author: thomas.diesler(a)jboss.com
Date: 2008-07-24 13:18:10 -0400 (Thu, 24 Jul 2008)
New Revision: 1717
Modified:
jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/client/ProcessManager.java
jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/model/Process.java
jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/runtime/Handler.java
jbossbpm/spec/trunk/modules/ri/src/main/java/org/jboss/bpm/client/internal/ProcessManagerImpl.java
jbossbpm/spec/trunk/modules/ri/src/main/java/org/jboss/bpm/model/internal/ProcessImpl.java
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/airticket/AirticketTest.java
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/parallelsplit/ParallelSplitTest.java
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/sequence/BasicSequenceTest.java
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/task/BasicTaskTest.java
Log:
startProcess() registers copy. All good.
Modified:
jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/client/ProcessManager.java
===================================================================
---
jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/client/ProcessManager.java 2008-07-24
15:06:58 UTC (rev 1716)
+++
jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/client/ProcessManager.java 2008-07-24
17:18:10 UTC (rev 1717)
@@ -129,22 +129,24 @@
}
/**
- * Find a Process for a given name
+ * Find the set of Processes for a given name
*
- * @return null if the process definition is not defined
+ * @param name The process name
+ * @param status The optional process status
+ * @return An empty set if the process cannot be found
*/
- public Process findProcess(String name)
+ public Set<Process> findProcessByName(String name, Process.Status status)
{
- Process proc = null;
+ Set<Process> procSet = new HashSet<Process>();
for (Process aux : procs)
{
if (aux.getName().equals(name))
{
- proc = aux;
- break;
+ if (status == null || aux.getStatus() == status)
+ procSet.add(aux);
}
}
- return proc;
+ return procSet;
}
/**
@@ -181,10 +183,10 @@
}
/**
- * Start a Process with a given process ID
+ * Start a Process with a given name
*/
- public abstract ObjectName startProcess(ObjectName id, Attachments att);
-
+ public abstract void startProcess(String name, Attachments att);
+
/**
* Wait for the Process to end. All Tokens that are generated at the Start Event for
that Process must eventually
* arrive at an End Event. The Process will be in a running state until all Tokens are
consumed.
@@ -196,10 +198,11 @@
{
Process proc = getProcessByID(id);
Status status = proc.getStatus();
-
- if (status != Status.Active)
+
+ if (status == Status.None || status == Status.Ready)
throw new IllegalStateException("Cannot wait for process in state: " +
status);
+ // Wait a little for the process to end
boolean forever = (timeout < 1);
long now = System.currentTimeMillis();
long until = now + timeout;
@@ -221,6 +224,7 @@
log.warn(ex);
}
+ // Throw timeout exception if it took too long
throw new ProcessTimeoutException("Process timeout for: " + id);
}
Modified: jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/model/Process.java
===================================================================
---
jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/model/Process.java 2008-07-24
15:06:58 UTC (rev 1716)
+++
jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/model/Process.java 2008-07-24
17:18:10 UTC (rev 1717)
@@ -25,7 +25,6 @@
import java.util.List;
-import javax.management.ObjectName;
import org.jboss.bpm.runtime.Attachments;
@@ -124,15 +123,13 @@
/**
* Start the process
- * @return the process instance identifier
*/
- ObjectName startProcess();
+ void startProcess();
/**
* Start the process, with a given execution context
- * @return the process instance identifier
*/
- ObjectName startProcess(Attachments att);
+ void startProcess(Attachments att);
/**
* Find a flow object by name
Modified:
jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/runtime/Handler.java
===================================================================
---
jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/runtime/Handler.java 2008-07-24
15:06:58 UTC (rev 1716)
+++
jbossbpm/spec/trunk/modules/api/src/main/java/org/jboss/bpm/runtime/Handler.java 2008-07-24
17:18:10 UTC (rev 1717)
@@ -21,6 +21,8 @@
*/
package org.jboss.bpm.runtime;
+import java.io.Serializable;
+
import org.jboss.bpm.model.FlowObject;
//$Id$
@@ -31,7 +33,7 @@
* @author thomas.diesler(a)jboss.com
* @since 08-Jul-2008
*/
-public interface Handler
+public interface Handler extends Serializable
{
}
\ No newline at end of file
Modified:
jbossbpm/spec/trunk/modules/ri/src/main/java/org/jboss/bpm/client/internal/ProcessManagerImpl.java
===================================================================
---
jbossbpm/spec/trunk/modules/ri/src/main/java/org/jboss/bpm/client/internal/ProcessManagerImpl.java 2008-07-24
15:06:58 UTC (rev 1716)
+++
jbossbpm/spec/trunk/modules/ri/src/main/java/org/jboss/bpm/client/internal/ProcessManagerImpl.java 2008-07-24
17:18:10 UTC (rev 1717)
@@ -24,9 +24,8 @@
// $Id$
import java.util.Map;
+import java.util.Set;
-import javax.management.ObjectName;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.bpm.client.DialectHandler;
@@ -34,6 +33,7 @@
import org.jboss.bpm.client.ExecutionManager;
import org.jboss.bpm.client.ProcessEngine;
import org.jboss.bpm.client.ProcessManager;
+import org.jboss.bpm.model.Process;
import org.jboss.bpm.model.Process.Status;
import org.jboss.bpm.model.internal.ProcessImpl;
import org.jboss.bpm.model.internal.RuntimeProcessImpl;
@@ -65,20 +65,23 @@
this.dialectRegistry = dialectRegistry;
}
- public ObjectName startProcess(ObjectName id, Attachments att)
+ public void startProcess(String name, Attachments att)
{
- ProcessImpl proc = (ProcessImpl)getProcessByID(id);
- if (proc.getStatus() != Status.Ready)
- throw new IllegalStateException("Cannot start process in state: " +
proc.getStatus());
-
- // Copy and register the process instance
- proc = (ProcessImpl)proc.copyProcess();
- registerProcess(proc);
+ Set<Process> procSet = findProcessByName(name, Status.Ready);
+ if (procSet.size() == 0)
+ throw new IllegalStateException("Cannot obtain process with name: " +
name);
+ if (procSet.size() > 1)
+ throw new IllegalStateException("Multiple processes with name: " +
name);
+ ProcessImpl proc = (ProcessImpl)procSet.iterator().next();
+
+ // Copy and register a copy of the process instance
+ Process procCopy = (ProcessImpl)proc.copyProcess();
+ registerProcess(procCopy);
+
// Start the process in a thread
+ proc.setStatus(Status.Active);
new Thread(new ProcessRunner(proc, att)).start();
-
- return proc.getID();
}
class ProcessRunner implements Runnable
@@ -94,7 +97,6 @@
public void run()
{
- proc.setStatus(Status.Active);
try
{
ExecutionManager exm = ExecutionManager.locateExecutionManager();
Modified:
jbossbpm/spec/trunk/modules/ri/src/main/java/org/jboss/bpm/model/internal/ProcessImpl.java
===================================================================
---
jbossbpm/spec/trunk/modules/ri/src/main/java/org/jboss/bpm/model/internal/ProcessImpl.java 2008-07-24
15:06:58 UTC (rev 1716)
+++
jbossbpm/spec/trunk/modules/ri/src/main/java/org/jboss/bpm/model/internal/ProcessImpl.java 2008-07-24
17:18:10 UTC (rev 1717)
@@ -31,8 +31,6 @@
import java.util.Collections;
import java.util.List;
-import javax.management.ObjectName;
-
import org.jboss.bpm.InvalidProcessException;
import org.jboss.bpm.NotImplementedException;
import org.jboss.bpm.client.ProcessManager;
@@ -158,19 +156,19 @@
}
catch (Exception ex)
{
- throw new InvalidProcessException("Cannot create a copy of: " + this);
+ throw new InvalidProcessException("Cannot create a copy of: " + this,
ex);
}
}
- public ObjectName startProcess()
+ public void startProcess()
{
- return startProcess(null);
+ startProcess(null);
}
- public ObjectName startProcess(Attachments att)
+ public void startProcess(Attachments att)
{
ProcessManager pm = ProcessManager.locateProcessManager();
- return pm.startProcess(getID(), att);
+ pm.startProcess(getName(), att);
}
public void waitForEnd()
Modified:
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/airticket/AirticketTest.java
===================================================================
---
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/airticket/AirticketTest.java 2008-07-24
15:06:58 UTC (rev 1716)
+++
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/airticket/AirticketTest.java 2008-07-24
17:18:10 UTC (rev 1717)
@@ -47,6 +47,6 @@
assertNotNull(proc);
proc.startProcess();
-
+ proc.waitForEnd();
}
}
Modified:
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/parallelsplit/ParallelSplitTest.java
===================================================================
---
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/parallelsplit/ParallelSplitTest.java 2008-07-24
15:06:58 UTC (rev 1716)
+++
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/parallelsplit/ParallelSplitTest.java 2008-07-24
17:18:10 UTC (rev 1717)
@@ -26,14 +26,12 @@
import java.net.URL;
import java.util.List;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
import org.jboss.bpm.client.ProcessManager;
import org.jboss.bpm.client.SignalManager;
import org.jboss.bpm.model.Process;
import org.jboss.bpm.model.ProcessBuilder;
import org.jboss.bpm.model.ProcessBuilderFactory;
-import org.jboss.bpm.model.Result;
import org.jboss.bpm.model.Signal;
import org.jboss.bpm.test.DefaultEngineTestCase;
@@ -76,6 +74,10 @@
Process proc =
procBuilder.addStartEvent().addSequenceFlow("gateway").addParallelGateway("gateway").
addSequenceFlow("endA").addSequenceFlow("endB").addEndEvent("endA").addEndEvent("endB").getProcess();
+ // Register the Process with the ProcessManager
+ ProcessManager pm = ProcessManager.locateProcessManager();
+ pm.registerProcess(proc);
+
runProcess(proc);
}
Modified:
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/sequence/BasicSequenceTest.java
===================================================================
---
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/sequence/BasicSequenceTest.java 2008-07-24
15:06:58 UTC (rev 1716)
+++
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/sequence/BasicSequenceTest.java 2008-07-24
17:18:10 UTC (rev 1717)
@@ -75,6 +75,10 @@
Process proc =
procBuilder.addStartEvent().addSequenceFlow("stateA").addTask("stateA").
addSequenceFlow("end").addEndEvent("end").getProcess();
+ // Register the Process with the ProcessManager
+ ProcessManager pm = ProcessManager.locateProcessManager();
+ pm.registerProcess(proc);
+
runProcess(proc);
}
Modified:
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/task/BasicTaskTest.java
===================================================================
---
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/task/BasicTaskTest.java 2008-07-24
15:06:58 UTC (rev 1716)
+++
jbossbpm/spec/trunk/modules/testsuite/src/test/java/org/jboss/bpm/samples/task/BasicTaskTest.java 2008-07-24
17:18:10 UTC (rev 1717)
@@ -72,9 +72,13 @@
{
// Create a Process through the ProcessBuilder
ProcessBuilder procBuilder =
ProcessBuilderFactory.newInstance().newProcessBuilder(getName());
- Process proc =
procBuilder.addStartEvent().addSequenceFlow("stateA").addTask("stateA").addExecutionHandler(
-
TaskA.class).addSequenceFlow("end").addEndEvent("end").getProcess();
+ Process proc =
procBuilder.addStartEvent().addSequenceFlow("stateA").addTask("stateA").
+
addExecutionHandler(TaskA.class).addSequenceFlow("end").addEndEvent("end").getProcess();
+ // Register the Process with the ProcessManager
+ ProcessManager pm = ProcessManager.locateProcessManager();
+ pm.registerProcess(proc);
+
runProcess(proc);
}