Triggerable CMMN Service Task

Hi,

Is there a CMMN equivalent of the “triggerable” servicetask feature in BPMN?
Use case would be to schedule some asynchronous (long-running) action when the plan item instance becomes ACTIVE, and to COMPLETE it via an API call when the answer comes in.

CmmnRuntimeService has a method for “triggerPlanItemInstance”, but the behavior class linked to a custom java delegate PlanItem does not implement CmmnTriggerableActivityBehavior…

The default delegate doesn’t expose that method, but the org.flowable.cmmn.engine.impl.behavior.CmmnTriggerableActivityBehavior interface does. Many of the default behaviors actually implement that interface, because in CMMN most of the plan items need to complete after executing the behavior.

Hi Joram,
Thanks for your reply! I had identified this interface, but am confused on how to link this behavior to a custom ServiceTask. If I implement a servicetask by implementing the PlanItemJavaDelegate, how can one specify the behavior to be CmmnTriggerableAcvitiyBehavior? Unless I’m mistaken, the behavior interface is not to be implemented upon the servicetask itself, is it?

If I trace through the Flowable engine code, I see a triggerable behavior being applied to UserTask etc… but my custom servicetask always ends up with non-triggerable behavior.

Sorry, I missed your response. If you implement the CmmnTriggerableAcvitiyBehavior interface and use it instead the PlanItemJavaDelegate, the engine will pick it up.

Indeed, the behaviors with wait state (like the user task) use this. But I assume you’ve tried this by setting it in the class attribute of the service task? Do you have an example that we can try?

Hi Joram,

I’m still missing the point I’m afraid.

  • If I implement only the CmmnTriggerableActivityBehavior on the service task class, the deployment fails:
    FlowableException: Delegate expression ${testDelegate} did neither resolve to an implementation of interface org.flowable.cmmn.engine.impl.behavior.PlanItemActivityBehavior nor interface org.flowable.cmmn.api.delegate.PlanItemJavaDelegate

  • If I also implement the PlanItemJavaDelegate or PlanItemActivityBehavior interface, the original exception occures when I “trigger” the task:
    FlowableException: Cannot trigger a plan item which activity behavior does not implement the interface org.flowable.cmmn.engine.impl.behavior.CmmnTriggerableActivityBehavior interface

Just to be 100% sure: I’m simply implementing these interfaces on the custom delegate class itself, right?
Like this:

public class TestDelegate implements CmmnTriggerableActivityBehavior {

@Override
public void trigger(DelegatePlanItemInstance planItemInstance) {
	System.err.println("trigger");
}

@Override
public void execute(DelegatePlanItemInstance delegatePlanItemInstance) {
	System.err.println("execute");
}

}

I’m still thinking this is related to a Delegate implementation class vs its attached Behaviour class. I would expect the CmmnTriggerableActivityBehavior interface on the behaviour class, not on the delegate class itself, or am I wrong?

It looks like you are correct. I assumed that the javadoc on flowable-engine/modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/delegate/PlanItemJavaDelegate.java at main · flowable/flowable-engine · GitHub was correct, but it isn’t.

Fixed it here: Cmmn: fix plan item java delegate trigger not possible · flowable/flowable-engine@65bd7ab · GitHub

Correct. The behaviour class didn’t implement the interface that implements the trigger method. Hence, it never passes it through to the actual delegate.

1 Like

Hi Joram,
Works like a charm - thanks a lot!
regards
Günther