Signal a wait state and suspend related running subprocesses
festano1 Sep 24, 2010 8:45 AMHi All,
I'm trying to realize a complex use case with Jbpm 4, and I'm lookin for some advises and answers.
My requisites are to implements some kind of "phases" inside a business process (which models an authorization issuing system for a governative trade organization) that must be "modular" and pluggable to the basis of some normative & legal factors.
I've move to the use of sub-processes in order to implement this, using a dynamic el expression to decide in runtime what process definition of instantiate as sub-process, via parameterizing the jpdl sub-process' key attribute.
So the structure is composed by a main process, that groups these phases, and many other subprocesses which can can be
authored by external system and business designers.
Another requisite is that in one phase (es: when an integration request is started) the main process is paused,
a timer is started (the pause cannot be longer than a business value, and users must be notified if the suspension is reaching it's limit),
and then resumed.
For authoring sub-process I don't find seamless to design for any subprocess some kind of a "suspension" state
(this would be always present, and redundant), so I'm thinking to enforce the suspension state at the level of the main process:
### EXCEPTION ########################################### 10:42:32,067 INF | [DefaultCommandService] exception while executing command org.jbpm.pvm.internal.cmd.SignalCmd@3ce40 org.jbpm.api.JbpmException: execution[MainProcess.50026] has running subprocess: execution[SubProcessRequisitesEvaluation.340002] in state inactive-scope at org.jbpm.pvm.internal.model.ExecutionImpl.checkActive(ExecutionImpl.java:1090) at org.jbpm.pvm.internal.model.ExecutionImpl.signal(ExecutionImpl.java:427) at org.jbpm.pvm.internal.cmd.SignalCmd.execute(SignalCmd.java:61) at org.jbpm.pvm.internal.cmd.SignalCmd.execute(SignalCmd.java:35) at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42) at org.jbpm.pvm.internal.tx.SpringCommandCallback.doInTransaction(SpringCommandCallback.java:45) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130) at org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:49) at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53) at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40) at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:56) at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.signalExecutionById(ExecutionServiceImpl.java:93)
... ExecutionImpl execution = (ExecutionImpl) executionService.findExecutionById(processId); logger.info( "MAIN-PROCESS STATE= " + processId + " " + execution.getState() ); if(execution.getSubProcessInstance() != null){ logger.info( "SUB_PROCESS STATE= " + execution.getSubProcessInstance().getId() + " " + execution.getSubProcessInstance().getState() ); if(Execution.STATE_INACTIVE_SCOPE.equalsIgnoreCase(execution.getSubProcessInstance().getState())){ ExecutionImpl state = execution.getSubProcessInstance().findActiveExecutionIn(activeState); state.suspend(); execution.getSubProcessInstance().suspend(); logger.info( "SUB_PROCESS STATE= " + execution.getSubProcessInstance().getId() + " " + execution.getSubProcessInstance().getState() ); logger.info( "SUB_PROCESS ACTIVITY STATE " + state + " " + state.getState() ); execution.resume(); logger.info( "MAIN-PROCESS STATE " + execution + " " + execution.getState() ); } } executionService.signalExecutionById(processId, transitionName, variables);