How Do We Get the Current Activity Type?

Is there an easy method to get the current Activity Type? In particular, is there a “hidden” delegate method to do this?

I know I can get the name of the activity (getCurrentActivityName()) and activity ID (getCurrentActivityId) using delegate methods. A reading of the Java docs seems to imply the only way to get this value is through some sort of historical query as it is recorded in the the ACT_HI_ACTINST table. I don’t know how to get that from the table in an “inexpensive” way in real time. I’m trying to do this in an activity listener.

What I need to do is identify the end_event activity of the process by something that cannot be altered by the developer. I cannot use the “end” event type as that occurs for every activity.

Thanks.

Michael

Hi Michael,

You can write something like

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.model.bpmn.instance.EndEvent;

public class MyDelegate implements JavaDelegate {

  @Override
  public void execute(DelegateExecution execution) throws Exception {
    boolean isEndEvent = execution.getBpmnModelElementInstance() instanceof EndEvent;
  }

}

Cheers,
Thorben

3 Likes

Thorben,

How “costly” is this code relative to other delegate execution calls? This would be in an activity listener so it would execute at least twice for every activity, thus efficiency is key.

I suppose I should tell you that we are trying to replace Camunda’s history mechanism with an external one and the filter for executing our code is in the activity listener. You can imagine how performance sensitive this would be. We have a projected throughput requirement of 3600 process starts per minute.

As always, thanks for the help.

Michael

One more question, is the “EndEvent” you are referring to an “end” as in the event name “end” which occurs for every activity, or is it the end of the actual process itself?

Michael

Hi Michael,

I think the cost is negligible since it does not require additional database calls. You should probably try that out yourself, though.

The interface org.camunda.bpm.model.bpmn.instance.EndEvent is part of Camunda’s BPMN model API and represents BPMN end events. The return value of execution.getBpmnModelElementInstance() is an object that represents the BPMN activity. You can access anything defined in the BPMN XML via its getters (you may have to cast it from FlowElement to the appropriate concrete event, activity, etc.). Accordingly, there are other interfaces like org.camunda.bpm.model.bpmn.instance.ServiceTask, etc.

Cheers,
Thorben

1 Like

Thorben,

Thanks for the information. I was able to use it to create a filter for the EndEvent activity. However, I should note that you will get two EndEvent activities, one for the actual activity in the process and one for the process itself. My assumption is that the same would be true for the StartEvent. In the end, I had to put a flag in after recording history for the “first” EndEvent (the activity within the process) so that it would not record the “second” EndEvent (the one for the process itself), because they would (or should) contain precisely the same process variable state.

Michael