Community

JBPM 4.3: Is it possible to leave current state on timer listener?

created by Nugroho Saputro in jBPM - View the full discussion

Hi All,

Please help me, I am newbie at JBPM 4.x. I have a problem with leaving a state programmatically in timer listener. I always get exception like this:

 


12 Apr 2010 11:21:11 ERROR org.jbpm.pvm.internal.cmd.ExecuteJobCmd  - exception while executing 'timer[30|2010-04-12 11:21:11,412|timeout]'
org.jbpm.api.JbpmException: execution[ADSLProvisioning.22] is not active: inactive-scope
     at org.jbpm.pvm.internal.model.ExecutionImpl.checkActive(ExecutionImpl.java:1024)
     at org.jbpm.pvm.internal.model.ExecutionImpl.take(ExecutionImpl.java:466)
     at org.jbpm.pvm.internal.model.ExecutionImpl.takeDefaultTransition(ExecutionImpl.java:449)
     at uk.co.upshot.jbpm.handler.OrderStatusChecker.notify(OrderStatusChecker.java:62)
     at org.jbpm.pvm.internal.wire.usercode.UserCodeEventListener.notify(UserCodeEventListener.java:39)

 

 

What I would like to do is checking status from database repeatedly every X minutes. When it found certain status e.g. COMPLETED it should go to the next state, otherwise it will repeat until that status is reached.

Currently I implement it as a state with a repeated timer:

<state name="Check Order Status">
  <on event="timeout">
    <timer duedate="10 minutes" repeat="10 minutes"></timer>
    <event-listener expr="#{OrderStatusChecker}"></event-listener>
  </on>
  <transition name="to-status-decision" to="status-decision"></transition>
</state>

 

 

and on the timer listener:

 

public class OrderStatusChecker implements EventListener {
 
    public void notify(EventListenerExecution event) throws Exception {        
        // Check status.
        String status = ...... get status from Database ...
        event.getProcessInstance().setVariable("status", status);
        
        if (status.equals("COMPLETED")) {
            // Leave current state
            ActivityExecution execution = (ActivityExecution) event.getParent();
            execution.takeDefaultTransition();
        }                
    }
}

 

 

 

Is it possible to do that in JBPM?  If it's not possible, is there any workaround for my case?

 

I use JBPM4.3 with spring 2.5.

 

Thank you.

 

Regards,

Nugroho

Reply to this message by going to Community

Start a new discussion in jBPM at Community