[jBPM] - Concurrency problem with persistent JBPM + Drools
by Tim Vercruysse
Tim Vercruysse [https://community.jboss.org/people/vercruysse_tim] created the discussion
"Concurrency problem with persistent JBPM + Drools"
To view the discussion, visit: https://community.jboss.org/message/797940#797940
--------------------------------------------------------------
Hi all,
We have a problem that when multiple threads try to fetch process variables an exception is thrown:
java.lang.NullPointerException
org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:67)
org.jbpm.persistence.processinstance.ProcessInstanceInfo.update(ProcessInstanceInfo.java:189)
the code in our EJB is:
public Object getProcessVar(long processInstanceId, String varName) {
try{
WorkflowProcessInstance p = (WorkflowProcessInstance) ksession.getProcessInstance(processInstanceId);
var = p.getVariable(varName);
} catch(Throwable x) {x.printStackTrace()}
return var;
}
This exception is thrown when we do multiple calls (around 40) from our Spring context to this EJB method.
We found that most of the time that when we do a context switch from Spring to EJB drools automatically tries to update a ProcessInstanceInfo entity with procesInstanceInfo.update() or invokes jPAProcessInstanceManager.clearProcessInstances() to disconnect all the processInstances. It happens now that drools tries to update a processInstanceInfo that points to a processInstance that previously has been disconnected, hence the error.
My guess is that the multiple threads mess up the order of the transactions so that some processInstanceInfo entities are in invalid states.
Does anyone know how to solve this issue?
We use JBPM 5.2, Spring 3 and Hibernate 4.
KnowledgeSession: statefullKnowledgeSession, with a commandBasedWSHumanTaskHandler.
Persistence transactions: JTA and JBossTransactionManagerLookup
Thanks!
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/797940#797940]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
13 years, 2 months
[jBPM] - How to pass process variables to a process using REST API.
by snowstorm tech
snowstorm tech [https://community.jboss.org/people/snowstormuser] created the discussion
"How to pass process variables to a process using REST API."
To view the discussion, visit: https://community.jboss.org/message/797890#797890
--------------------------------------------------------------
Hi,
I am using *" http://localhost:8080//gwt-console-server/rs/process/definition/defaultPa... http://localhost:8080//gwt-console-server/rs/process/definition/defaultPa..."* this REST API to run the process, I am able to run the process but not able to pass the variables througth this REST API.Following is code which I used to call this REST API.
Java Code:
> import org.apache.commons.httpclient.*;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.methods.PostMethod;
> import org.jboss.bpm.console.client.model.*;
>
>
> import java.io.IOException;
> import java.net.URLDecoder;
> import java.net.URLEncoder;
>
>
> import org.jboss.soa.bpel.console.ModelAdaptor;
>
>
> import com.google.gson.*;
>
>
>
>
>
>
> public class ManagementClient {
>
>
>
> private static final String process_start_url = " http://localhost:8080/gwt-console-server/rs/process/definition/defaultPac... http://localhost:8080/gwt-console-server/rs/process/definition/defaultPac...";
>
> private String username;
> private String password;
>
>
> public ManagementClient(String u, String p)
> {
> username = u;
> password = p;
> }
>
> public void startProcess() throws Exception
> {
>
> getDataFromService( process_start_url, "POST");
>
> }
> private String getDataFromService(String urlpath, String method) throws Exception{
> HttpClient httpclient = new HttpClient();
>
>
> HttpMethod theMethod = null;
> StringBuffer sb = new StringBuffer();
>
>
> if ("GET".equalsIgnoreCase(method)) {
> theMethod = new GetMethod(urlpath);
> } else if ("POST".equalsIgnoreCase(method)) {
>
> theMethod = new PostMethod(urlpath);
>
> }
>
>
> if (username != null && password != null) {
>
>
> try {
> httpclient.executeMethod(theMethod);
> NameValuePair[] data2 = {new NameValuePair("Name", "shahid"), new NameValuePair("Age", "28")};
> theMethod.setQueryString(data2);
> } catch (IOException e) {
> e.printStackTrace();
> } finally {
> theMethod.releaseConnection();
> }
> PostMethod authMethod = new PostMethod(authentication_url);
> NameValuePair[] data = {new NameValuePair("j_username", username), new NameValuePair("j_password", password)};
> authMethod.setRequestBody(data);
>
> try {
> httpclient.executeMethod(authMethod);
> } catch (IOException e) {
> e.printStackTrace();
> } finally {
> authMethod.releaseConnection();
> }
> }
>
>
> try {
>
> NameValuePair[] data2 = {new NameValuePair("Name", "shahid"), new NameValuePair("Age", "28")};
>
> theMethod.setQueryString(data2);
>
> httpclient.executeMethod(theMethod);
> sb.append(theMethod.getResponseBodyAsString());
> System.out.println("JSon Result: => " + sb.toString());
> return sb.toString();
>
>
> }catch (Exception e) {
> throw e;
> }finally {
> theMethod.releaseConnection();
> }
>
>
> }
> public static void main(String[] args) throws Exception {
>
>
> ManagementClient client = new ManagementClient("admin","admin");
> client.startProcess();
> client.processFormRender();
> }
>
>
>
>
> }
>
Process BPMN:
> <?xml version="1.0" encoding="UTF-8"?>
> <bpmn2:definitions xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance" xmlns=" http://www.omg.org/bpmn20 http://www.omg.org/bpmn20" xmlns:bpmn2=" http://www.omg.org/spec/BPMN/20100524/MODEL http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi=" http://www.omg.org/spec/BPMN/20100524/DI http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc=" http://www.omg.org/spec/DD/20100524/DC http://www.omg.org/spec/DD/20100524/DC" xmlns:di=" http://www.omg.org/spec/DD/20100524/DI http://www.omg.org/spec/DD/20100524/DI" xmlns:drools=" http://www.jboss.org/drools http://www.jboss.org/drools" id="_6Jb3MHdrEeK6ToI0TrDnHQ" xsi:schemaLocation=" http://www.omg.org/spec/BPMN/20100524/MODEL http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" targetNamespace=" http://www.omg.org/bpmn20 http://www.omg.org/bpmn20">
> <bpmn2:itemDefinition id="_NameItem" structureRef="String"/>
> <bpmn2:itemDefinition id="_AgeItem" structureRef="Integer"/>
> <bpmn2:process id="defaultPackage.ProcessWV" drools:packageName="defaultPackage" name="ProcessWV" isExecutable="true">
> <bpmn2:property id="Name" itemSubjectRef="_NameItem"/>
> <bpmn2:property id="Age" itemSubjectRef="_AgeItem"/>
> <bpmn2:startEvent id="_B3399BEE-F15A-4DE7-A302-A10D0CCB2A14" drools:bgcolor="#9acd32" drools:selectable="true" name="">
> <bpmn2:outgoing>_3B1EC4FB-1459-4589-B014-203374D36A64</bpmn2:outgoing>
> </bpmn2:startEvent>
> <bpmn2:scriptTask id="_D306BBB0-A427-4DB6-A524-025AFB76D020" drools:selectable="true" name="Name/Age" scriptFormat=" http://www.java.com/java http://www.java.com/java">
> <bpmn2:incoming>_3B1EC4FB-1459-4589-B014-203374D36A64</bpmn2:incoming>
> <bpmn2:outgoing>_6841C8EE-C23C-4116-959B-2AD64BDEE50F</bpmn2:outgoing>
> <bpmn2:script><![CDATA[System.out.println("Name="+Name);]]></bpmn2:script>
> </bpmn2:scriptTask>
> <bpmn2:endEvent id="_8A6FF5AA-01EC-44B3-836B-0723F1372791" drools:bgcolor="#ff6347" drools:selectable="true" name="">
> <bpmn2:incoming>_6841C8EE-C23C-4116-959B-2AD64BDEE50F</bpmn2:incoming>
> </bpmn2:endEvent>
> <bpmn2:sequenceFlow id="_3B1EC4FB-1459-4589-B014-203374D36A64" drools:bgcolor="#000000" drools:selectable="true" sourceRef="_B3399BEE-F15A-4DE7-A302-A10D0CCB2A14" targetRef="_D306BBB0-A427-4DB6-A524-025AFB76D020"/>
> <bpmn2:sequenceFlow id="_6841C8EE-C23C-4116-959B-2AD64BDEE50F" drools:bgcolor="#000000" drools:selectable="true" sourceRef="_D306BBB0-A427-4DB6-A524-025AFB76D020" targetRef="_8A6FF5AA-01EC-44B3-836B-0723F1372791"/>
> </bpmn2:process>
> <bpmndi:BPMNDiagram id="_6Jb3MXdrEeK6ToI0TrDnHQ">
> <bpmndi:BPMNPlane id="_6Jb3MndrEeK6ToI0TrDnHQ" bpmnElement="defaultPackage.ProcessWV">
> <bpmndi:BPMNShape id="_6Jb3M3drEeK6ToI0TrDnHQ" bpmnElement="_B3399BEE-F15A-4DE7-A302-A10D0CCB2A14">
> <dc:Bounds height="30.0" width="30.0" x="165.0" y="135.0"/>
> </bpmndi:BPMNShape>
> <bpmndi:BPMNShape id="_6Jb3NHdrEeK6ToI0TrDnHQ" bpmnElement="_D306BBB0-A427-4DB6-A524-025AFB76D020">
> <dc:Bounds height="80.0" width="100.0" x="285.0" y="90.0"/>
> </bpmndi:BPMNShape>
> <bpmndi:BPMNShape id="_6JceQHdrEeK6ToI0TrDnHQ" bpmnElement="_8A6FF5AA-01EC-44B3-836B-0723F1372791">
> <dc:Bounds height="28.0" width="28.0" x="384.0" y="205.0"/>
> </bpmndi:BPMNShape>
> <bpmndi:BPMNEdge id="_6JceQXdrEeK6ToI0TrDnHQ" bpmnElement="_3B1EC4FB-1459-4589-B014-203374D36A64">
> <di:waypoint xsi:type="dc:Point" x="180.0" y="150.0"/>
> <di:waypoint xsi:type="dc:Point" x="244.0" y="150.0"/>
> <di:waypoint xsi:type="dc:Point" x="244.0" y="130.0"/>
> <di:waypoint xsi:type="dc:Point" x="335.0" y="130.0"/>
> </bpmndi:BPMNEdge>
> <bpmndi:BPMNEdge id="_6JceQndrEeK6ToI0TrDnHQ" bpmnElement="_6841C8EE-C23C-4116-959B-2AD64BDEE50F">
> <di:waypoint xsi:type="dc:Point" x="335.0" y="130.0"/>
> <di:waypoint xsi:type="dc:Point" x="400.0" y="130.0"/>
> <di:waypoint xsi:type="dc:Point" x="398.0" y="219.0"/>
> </bpmndi:BPMNEdge>
> </bpmndi:BPMNPlane>
> </bpmndi:BPMNDiagram>
> <bpmn2:relationship id="_6JceQ3drEeK6ToI0TrDnHQ">
> <bpmn2:extensionElements>
> <drools:ProcessAnalysisData>
> <drools:Scenario xsi:type="drools:Scenario" id="default" name="Simulationscenario">
> <drools:ScenarioParameters xsi:type="drools:ScenarioParameters_._type" baseTimeUnit="s"/>
> <drools:ElementParameters xsi:type="drools:ElementParameters_._type" elementId="_B3399BEE-F15A-4DE7-A302-A10D0CCB2A14" id="_6JceRHdrEeK6ToI0TrDnHQ">
> <drools:TimeParameters xsi:type="drools:TimeParameters">
> <drools:WaitTime xsi:type="drools:Parameter">
> <drools:FloatingParameter value="0.0"/>
> </drools:WaitTime>
> <drools:TimeUnit>ms</drools:TimeUnit>
> </drools:TimeParameters>
> </drools:ElementParameters>
> <drools:ElementParameters xsi:type="drools:ElementParameters_._type" elementId="_D306BBB0-A427-4DB6-A524-025AFB76D020" id="_6JceRXdrEeK6ToI0TrDnHQ">
> <drools:TimeParameters xsi:type="drools:TimeParameters">
> <drools:ProcessingTime xsi:type="drools:Parameter">
> <drools:RandomDistribution max="0.0" min="0.0"/>
> </drools:ProcessingTime>
> <drools:TimeUnit>ms</drools:TimeUnit>
> </drools:TimeParameters>
> <drools:CostParameters xsi:type="drools:CostParameters">
> <drools:UnitCost xsi:type="drools:Parameter">
> <drools:DecimalParameter value="0"/>
> </drools:UnitCost>
> </drools:CostParameters>
> </drools:ElementParameters>
> <drools:ElementParameters xsi:type="drools:ElementParameters_._type" elementId="_8A6FF5AA-01EC-44B3-836B-0723F1372791" id="_6JceRndrEeK6ToI0TrDnHQ">
> <drools:TimeParameters xsi:type="drools:TimeParameters">
> <drools:ProcessingTime xsi:type="drools:Parameter">
> <drools:RandomDistribution max="0.0" min="0.0"/>
> </drools:ProcessingTime>
> <drools:TimeUnit>ms</drools:TimeUnit>
> </drools:TimeParameters>
> </drools:ElementParameters>
> <drools:ElementParameters xsi:type="drools:ElementParameters_._type" elementId="_6841C8EE-C23C-4116-959B-2AD64BDEE50F" id="_6JceR3drEeK6ToI0TrDnHQ">
> <drools:ControlParameters xsi:type="drools:ControlParameters">
> <drools:Probability xsi:type="drools:Parameter">
> <drools:FloatingParameter value="100.0"/>
> </drools:Probability>
> </drools:ControlParameters>
> </drools:ElementParameters>
> <drools:ElementParameters xsi:type="drools:ElementParameters_._type" elementId="_3B1EC4FB-1459-4589-B014-203374D36A64" id="_6JceSHdrEeK6ToI0TrDnHQ">
> <drools:ControlParameters xsi:type="drools:ControlParameters">
> <drools:Probability xsi:type="drools:Parameter">
> <drools:FloatingParameter value="100.0"/>
> </drools:Probability>
> </drools:ControlParameters>
> </drools:ElementParameters>
> </drools:Scenario>
> </drools:ProcessAnalysisData>
> </bpmn2:extensionElements>
> <bpmn2:source>_6Jb3MHdrEeK6ToI0TrDnHQ</bpmn2:source>
> <bpmn2:target>_6Jb3MHdrEeK6ToI0TrDnHQ</bpmn2:target>
> </bpmn2:relationship>
> </bpmn2:definitions>
>
Process Image:
https://community.jboss.org/servlet/JiveServlet/downloadImage/2-797890-20... (https://community.jboss.org/servlet/JiveServlet/showImage/2-797890-20313/...)
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/797890#797890]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
13 years, 2 months
[jBPM] - jBPM 5.4 - setNode ?
by wishmaster7
wishmaster7 [https://community.jboss.org/people/wishmaster7] created the discussion
"jBPM 5.4 - setNode ?"
To view the discussion, visit: https://community.jboss.org/message/797845#797845
--------------------------------------------------------------
Hi all,
I am quite new with jBPM and in my project the customer wants to be able to change manually the current state of the process. I've red some threads about setNode() but I'm unable to reach this method. Someone could please help me?
I have a small jUnit test class which extends JbpmJUnitTestCase, and my method looks like :
// start context
KnowledgeBase kbase = createKnowledgeBase("bpmn/TestSetNode.bpmn");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler testHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
// start process
ProcessInstance processInstance = ksession.startProcess("ch.orange.mnp.test.SetNode", null);
assertNodeTriggered(processInstance.getId(), "Start");
// find the user task
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
//ksession = restoreSession(ksession, true);
WorkItem workItem = testHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("admin", workItem.getParameter("GroupId"));
I can call +ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);+ to complete the +User Task+. But instead, I want to change the actual state of the process, let's say set it to "+Script Task 1+". How can I do that?
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/797845#797845]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
13 years, 2 months