cancel
Showing results for 
Search instead for 
Did you mean: 

How to get a particular ProcessIntance from processEngine

rock_star
Champ in-the-making
Champ in-the-making
Hi Guys,

I am trying to get the particulat execution of the processEngine. This was achiveable as


Execution execution = processEngine.getRuntimeService().findExecutionById(executionId);

on 5.0-Beta but this seems to be not anymore in 5.1 release.

Can someone please tell me how do I acheive the same in 5.1 release? I have gone through the Javadoc of 5.1 lot of times now but does not seem to be any way there.

Please anyone reply on this as I am stuck for long time now.

Also, I am starting the processIntance as


processEngine.getRepositoryService().createDeployment().addClasspathResource("processes/si_gateway_example.bpmn20.xml").deploy();
      Map<String, Object> vars = new HashMap<String, Object>();
      vars.put("abc", 232);
      processEngine.getRuntimeService().startProcessInstanceByKey("testProcess", vars);
7 REPLIES 7

mproch
Champ in-the-making
Champ in-the-making
I think you should you executionQuery builder - it's quite easy to use:

        Execution execution = runtimeService.createExecutionQuery()
                .executionId(id).singleResult();

rock_star
Champ in-the-making
Champ in-the-making
Maciek, thanks for quick reply.

It seems that no processIntance/Execution is being attached to the ProcessEngine Instance.
I tried to list all executions/instances attached with processEngine but none was there.
The code below gives me size of list as ZERO and instance is null.
Not sure what i am doing wrong. I have attached the xonfig files. Please rename it to .rar extension if it does not extract.

Execution execution = processService.createExecutionQuery().executionId(executionId).singleResult();
    List<Execution> listExec = processService.createExecutionQuery().list();

    logger.info("List size is " + listExec.size());
    for (Execution execution2 : listExec) {
     logger.info("Instance id is " +  execution2.getProcessInstanceId());
     logger.info("execution  instance is " + execution2);
    
    }
    logger.info("Execution instance " + execution);

mproch
Champ in-the-making
Champ in-the-making
Hi, looking at your process, it looks like it finishes immediately after it starts - when you perform the query, the process is already finished. I think it's not possible to get finished process instances this way.
You have to use HistoryService then. I don't know too many details about it - but seems you can do similar queries using createHistoricProcessInstanceQuery or other methods

rock_star
Champ in-the-making
Champ in-the-making
Hi Maciek,

Thanks again. I used createHistoricProcessInstanceQuery  and it indeed seems that the process was finished.
Basically, I have a Spring bean which has a reference to processEngine and that sends out a message on a request channel. When the message comes back to the bean
, I am trying to send the message to next channel in reply handler of the bean which has reference to the ProcessEngine. So, I am wondering - why instance should not
be retreivable?
Is there a way that I can wake up that process intance? The reason i want that particular instance because the next step in that request channel should be part of the
same execution which was started for the first message.

Please let me know if there is a way. Also, I had gone trhough documentation. Just wondering if there is any other document related to Activiti which explain things in core.

List<HistoricProcessInstance> listProcessInstance = processEngine.getHistoryService().createHistoricProcessInstanceQuery().list();
    for (HistoricProcessInstance historicProcessInstance : listProcessInstance) {
   
     logger.info("Historic Instance id is " +  historicProcessInstance.getId());
     logger.info("Historic Business id is " +  historicProcessInstance.getBusinessKey());
     logger.info("Historic Business Def id is " +  historicProcessInstance.getProcessDefinitionId());
     logger.info("Historic Start time is " +  historicProcessInstance.getStartTime());
     logger.info("Historic End time is " +  historicProcessInstance.getEndTime());
     logger.info("Historic End time is " +  historicProcessInstance.getEndTime());
   
    }


ProcessEngine was started as below and bean above and below are in the same sping context/java process.


processEngine.getRepositoryService().createDeployment().addClasspathResource("processes/si_gateway_example.bpmn20.xml").deploy();            processEngine.getRuntimeService().startProcessInstanceByKey("sigatewayProcess", vars);

mproch
Champ in-the-making
Champ in-the-making
I don't know spring integration well, but in your inbound-gateway you have async="true" attribute. Doesn't it mean that the process continues without waiting for response? Which in this case means that it finishes.

About documentation - I think that the reference source is code itself - especially examples.

rock_star
Champ in-the-making
Champ in-the-making
yes, async="true" process will continue but it activates when there is reply on specified channel.

The internal class is implementing org.activiti.engine.impl.bpmn.ReceiveTaskActivity , which essentially is a wait-state implementation. So, i would have imagined that process instance should have been there! Smiley Sad

rock_star
Champ in-the-making
Champ in-the-making
Ok, I guess I am getting close to the reason now —

The statement below is not actually calling the Spring endPoint
BPMN
<serviceTask id="sigw" name="Spring Integration Gateway" activiti:expression="#{gateway}"/>

Spring endpoint:
<!– Activiti sends a message 'to' (inbound) Spring Integration 'from' Activiti –>
<activiti:inbound-gateway
   process-engine="processEngine"
   request-channel="request"
   async="true"
   reply-channel="response"
   forward-process-variables-as-message-headers="true"
   update-process-variables-from-reply-message-headers="true"
   id="gateway"
/>

Is their a way to invoke the gateway using some other expressions or class? I think class actually takes full qualified class name.