由于我可以设置计时器事件的持续时间,我可以通过java代码访问它吗?还是作为一个camunda变量?
答案 0 :(得分:2)
如果要访问XML中定义的属性,可以使用BPMN Model API。例如:
String processDefinitionId = ...
String timerEventId = ...
BpmnModelInstance bpmnModel = repositoryService.getBpmnModelInstance(processDefinitionId);
CatchEvent timerEvent = bpmnModel.getModelElementById(timerEventId);
TimerEventDefinition timerEventDefinition =
(TimerEventDefinition) timerEvent.getEventDefinitions().iterator().next();
TimeDuration duration = timerEventDefinition.getTimeDuration();
String configuredDuration = duration.getTextContent();
如果您想获得计时器在下次运行时触发的实际时间,您将需要查询相应的作业:
String processDefinitionId = ...
String timerEventId = ...
String processInstanceId = ...
Job timerJob = managementService.createJobQuery()
.processDefinitionId(processDefinitionId)
.activityId(activityId)
.processInstanceId(processInstanceId)
.singleResult();
Date firingDate = timerJob.getDueDate();
请注意,如果您查询的流程实例尚未到达计时器事件,则timerJob
为空。