Hi all,
I need to obtain the key of the current process definition in an event listener (for metering purposes). I came up with the solution below, which has a couple issues:
- I don’t know what guarantee I have that Context.getCommandContext() will work in my listener (it does in my basic tests…)
- I have to downcast the engine config to ProcessEngineConfigurationImpl
Is there a better way to achieve this? Obviously I cannot afford going back to the DB every time…
public class TimingListener implements FlowableEventListener {
...
public void onEvent(FlowableActivityEvent event)
{
String activityId = event.getActivityId();
String processId = event.getProcessDefinitionId();
ProcessEngineConfigurationImpl engineConfig = (ProcessEngineConfigurationImpl)
Context.getCommandContext().getCurrentEngineConfiguration();
ProcessDefinitionCacheEntry entry = engineConfig.getDeploymentManager().
getProcessDefinitionCache().get(processId);
processKey = entry.getProcessDefinition().getKey()
The listener is added as a typed listener for FlowableEngineEventType.ACTIVITY_STARTED, FlowableEngineEventType.ACTIVITY_COMPLETED and FlowableEngineEventType.ACTIVITY_CANCELLED event types.