[jBPM Users] - Re: sub process event propagation
by aapthorp
So my final (JBPM 3) solution for this requirement is as follows.
An actionhandler in the subprocess which propagates the event to the superprocess.
public void execute(ExecutionContext executionContext) throws Exception {
|
| if (eventType == null) {
| eventType = executionContext.getEvent().getEventType();
| }
| Token superToken = executionContext.getProcessInstance()
| .getSuperProcessToken();
| ExecutionContext superContext = new ExecutionContext(superToken);
| superToken.getProcessInstance().getProcessDefinition().fireEvent(eventType, superContext);
| }
and another action handler to handle the propogated event in the superprocess:
|
| String nodeName=null;
| String transitionName=null;
|
| public void execute(ExecutionContext executionContext) throws Exception {
|
| List tokenList = executionContext.getProcessInstance().findAllTokens();
| for (Iterator it = tokenList.iterator(); it.hasNext();) {
| Token token = (Token) it.next();
| if (token.getNode().getName().equals(nodeName)) {
| token.signal(transitionName);
| }
| }
| }
The propagated event can then be sent to a state that transitions to a join to control the main flow of the superprocess. I'm sure there are some other ways of getting the same effect but this seems to work quite well. I have also refined it further to consolidate events of the same type from multiple instances of the same subprocess.
Now need to see how this is achieved in JBPM4.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4260947#4260947
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4260947
16 years, 5 months
[jBPM Users] - Re: jBPM 4: how to transition via Java handler/listener?
by sebastian.s
Since I haven't been working with jbpm 3.x it's hard for me to get what exactly you are trying to achieve. I tried your unit test and I got the message that the execution was not found.
I can be wrong but doesn't this create a new process engine?
| ExecutionService executionService =
| new Configuration().buildProcessEngine().getExecutionService();
|
I am really not sure how to retrieve a reference on the process eninge already created in the context of an EventListener but I tried using the following:
| ExecutionService executionService =
| Configuration.getProcessEngine().getExecutionService();
|
The error that the execution was not found did not occur anymore but there was an assertion failure:
| 12:24:14,734 SEV | [BaseJbpmTestCase] ASSERTION FAILURE: expected:<TransitionedTo[ByListener]> but was:<TransitionedTo[Manually]>
| junit.framework.ComparisonFailure: expected:<TransitionedTo[ByListener]> but was:<TransitionedTo[Manually]>
|
Hope this helps at least bit. If this does not I'd be eager to know if it's possible and how.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4260928#4260928
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4260928
16 years, 5 months
[jBPM Users] - jBPM 4: how to transition via Java handler/listener?
by bwestrich
In jBPM 3.2.3, in a Java action handler you can do a transition by calling executionContext.leaveNode(String signalName).
How is this done in jBPM 4?
I've tried doing this using a Java event listener, but the transition doesn't execute. Here's the details:
I used the following model (capital names are the states, small case names in parentheses are the transition names):
Start ->
Initial --(manually)--> TransitionedToManually --(byListener)--> TransitionedToByListener
-> End
Then I created a process instance for the model, which was initially in the "Initial" state, e.g.
ProcessInstance processInstanceInitial = executionService.startProcessInstanceByKey("SimpleModel");
| assertEquals("Initial", processInstanceInitial.findActiveActivityNames().iterator().next());
Then I manually signaled a transition:
ProcessInstance processInstanceAtManualState =
| executionService.signalExecutionById(processInstanceInitial.getId(), "manually");
After this signal, I wanted to transition to the TransitionedToManually state, and then (via Java code in a listener) transition to the 'TransitionedToByListener' state. So I wrote a Java event listener for the transitionedToManually state that looks like this:
public class FirstEnterHandler implements EventListener {
| public void notify(EventListenerExecution execution) throws Exception {
| ExecutionService executionService =
| new Configuration().buildProcessEngine().getExecutionService();
| ProcessInstance processInstance =
| executionService.signalExecutionById(execution.getId(), "byListener");
| }
| }
...and attached it to the state like so...
<state name="TransitionedToManually">
| <on event="start">
| <event-listener class="jbpm4.spike.FirstEnterHandler">
| </event-listener>
| </on>
| <transition to="TransitionedToByListener" name="byListener" />
| </state>
But though the handler code executed, the second transition (byListener) did not happen (the execution ended in the state TransitionedToManually.
One curious thing I noticed is that although the execution passed into the event listener's notice() method is in the state of TransitionedToManually, the process instance returned by signalExecutionById in that method is in the state Initial. I would have expected the process instance to be in the same state as the passed in execution.
Any ideas on how to request a transition in jBPM 4 using Java?
P.S. the full code of my example is shown below.
First, the unit test that drives the rest of the code:
package jbpm4.spike;
|
| import org.jbpm.api.ProcessInstance;
| import org.jbpm.test.JbpmTestCase;
|
| public class SimpleModelTest extends JbpmTestCase {
|
| String deploymentId;
|
| protected void setUp() throws Exception {
| super.setUp();
|
| deploymentId =
| repositoryService.createDeployment().addResourceFromClasspath("jbpm4/spike/process.jpdl.xml")
| .deploy();
| }
|
| public void test() {
|
| ProcessInstance processInstanceInitial = executionService.startProcessInstanceByKey("SimpleModel");
| assertEquals("Initial", processInstanceInitial.findActiveActivityNames().iterator().next());
|
| ProcessInstance processInstanceAtManualState =
| executionService.signalExecutionById(processInstanceInitial.getId(), "manually");
|
| ProcessInstance processInstanceAtListenerState;
| if (!FirstEnterHandler.TRANSITION_USING_HANDLER) {
| assertEquals("TransitionedToManually", processInstanceAtManualState.findActiveActivityNames()
| .iterator().next());
| processInstanceAtListenerState =
| executionService.signalExecutionById(processInstanceAtManualState.getId(), "byListener");
| } else {
| processInstanceAtListenerState =
| executionService.findProcessInstanceById(processInstanceAtManualState.getId());
| }
| assertEquals("TransitionedToByListener", processInstanceAtListenerState.findActiveActivityNames()
| .iterator().next());
| assertFalse(processInstanceAtListenerState.isEnded());
| ProcessInstance processInstanceAtEnd =
| executionService.signalExecutionById(processInstanceAtListenerState.getId(), "end");
| assertTrue(processInstanceAtEnd.isEnded());
| }
| }
Next, the event listener:
package jbpm4.spike;
|
| import org.jbpm.api.Configuration;
| import org.jbpm.api.ExecutionService;
| import org.jbpm.api.ProcessInstance;
| import org.jbpm.api.listener.EventListener;
| import org.jbpm.api.listener.EventListenerExecution;
| import org.jbpm.api.model.OpenExecution;
|
| public class FirstEnterHandler implements EventListener {
|
| public static boolean TRANSITION_USING_HANDLER = true;
|
| public void notify(EventListenerExecution execution) throws Exception {
| OpenExecution openExecution = execution;
| if (TRANSITION_USING_HANDLER) {
| ExecutionService executionService =
| new Configuration().buildProcessEngine().getExecutionService();
|
| ProcessInstance processInstance =
| executionService.signalExecutionById(execution.getId(), "byListener");
| }
| }
| }
Finally, the process definition file (process.jpdl.xml):
<?xml version="1.0" encoding="UTF-8"?>
|
| <process name="SimpleModel" xmlns="http://jbpm.org/4.0/jpdl">
|
| <start g="29,24,48,48">
| <transition to="Initial"/>
| </start>
|
| <state g="40,124,92,52" name="Initial">
| <transition g="-5,-18" name="manually" to="TransitionedToManually"/>
| </state>
|
| <state g="88,239,149,49" name="TransitionedToManually">
| <on event="start"> <!-- event used to be "node-enter" -->
| <event-listener class="jbpm4.spike.FirstEnterHandler">
| </event-listener>
| </on>
| <transition g="-5,-18" name="byListener" to="TransitionedToByListener"/>
| </state>
|
| <state g="191,338,154,52" name="TransitionedToByListener">
| <transition g="-5,-18" name="end" to="end1"/>
| </state>
|
| <end g="413,424,48,48" name="end1"/>
|
| </process>
Thanks in advance for your help.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4260852#4260852
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4260852
16 years, 5 months
[jBPM Users] - Re: Problem configuring jBPM4 with Spring
by apollo11
what is the reason to set the hibernate-session current="true" in the jbmp.cfg.xml file?
<!-- Need to set explicitly that we don't want jbpm to create sessions-->
<hibernate-session current="true"
I got the following exception when running either in Tomcat or JUnit tests. I was trying to retrieve the subtasks of a task.
Oct 16, 2009 1:49:37 PM org.hibernate.LazyInitializationException
SEVERE: could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:132)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:174)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at org.jbpm.pvm.internal.task.TaskImpl_$$_javassist_39.getSubTasks(TaskImpl_$$_javassist_39.java)
However, if I set the value to "false", then it works but occasinally the application hangs and I cannot find the causes.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4260821#4260821
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4260821
16 years, 5 months