|
| 1 | +[id='event-listeners-interfaces-ref_{context}'] |
| 2 | += Interfaces for event listeners |
| 3 | + |
| 4 | +You can use the following interfaces to develop event listeners for the {PROCESS_ENGINE}. |
| 5 | + |
| 6 | +== Interfaces for process event listeners |
| 7 | + |
| 8 | +You can develop a class that implements the `ProcessEventListener` interface. This class can listen to process-related events, such as starting or completing a process or entering and leaving a node. |
| 9 | + |
| 10 | +The following source code shows the different methods of the `ProcessEventListener` interface: |
| 11 | + |
| 12 | +.The `ProcessEventListener` interface |
| 13 | +[source,java] |
| 14 | +---- |
| 15 | +public interface ProcessEventListener |
| 16 | + extends |
| 17 | + EventListener { |
| 18 | +
|
| 19 | + /** |
| 20 | + * This listener method is invoked right before a process instance is being started. |
| 21 | + * @param event |
| 22 | + */ |
| 23 | + void beforeProcessStarted(ProcessStartedEvent event); |
| 24 | +
|
| 25 | + /** |
| 26 | + * This listener method is invoked right after a process instance has been started. |
| 27 | + * @param event |
| 28 | + */ |
| 29 | + void afterProcessStarted(ProcessStartedEvent event); |
| 30 | +
|
| 31 | + /** |
| 32 | + * This listener method is invoked right before a process instance is being completed (or aborted). |
| 33 | + * @param event |
| 34 | + */ |
| 35 | + void beforeProcessCompleted(ProcessCompletedEvent event); |
| 36 | +
|
| 37 | + /** |
| 38 | + * This listener method is invoked right after a process instance has been completed (or aborted). |
| 39 | + * @param event |
| 40 | + */ |
| 41 | + void afterProcessCompleted(ProcessCompletedEvent event); |
| 42 | +
|
| 43 | + /** |
| 44 | + * This listener method is invoked right before a node in a process instance is being triggered |
| 45 | + * (which is when the node is being entered, for example when an incoming connection triggers it). |
| 46 | + * @param event |
| 47 | + */ |
| 48 | + void beforeNodeTriggered(ProcessNodeTriggeredEvent event); |
| 49 | +
|
| 50 | + /** |
| 51 | + * This listener method is invoked right after a node in a process instance has been triggered |
| 52 | + * (which is when the node was entered, for example when an incoming connection triggered it). |
| 53 | + * @param event |
| 54 | + */ |
| 55 | + void afterNodeTriggered(ProcessNodeTriggeredEvent event); |
| 56 | +
|
| 57 | + /** |
| 58 | + * This listener method is invoked right before a node in a process instance is being left |
| 59 | + * (which is when the node is completed, for example when it has performed the task it was |
| 60 | + * designed for). |
| 61 | + * @param event |
| 62 | + */ |
| 63 | + void beforeNodeLeft(ProcessNodeLeftEvent event); |
| 64 | +
|
| 65 | + /** |
| 66 | + * This listener method is invoked right after a node in a process instance has been left |
| 67 | + * (which is when the node was completed, for example when it performed the task it was |
| 68 | + * designed for). |
| 69 | + * @param event |
| 70 | + */ |
| 71 | + void afterNodeLeft(ProcessNodeLeftEvent event); |
| 72 | +
|
| 73 | + /** |
| 74 | + * This listener method is invoked right before the value of a process variable is being changed. |
| 75 | + * @param event |
| 76 | + */ |
| 77 | + void beforeVariableChanged(ProcessVariableChangedEvent event); |
| 78 | +
|
| 79 | + /** |
| 80 | + * This listener method is invoked right after the value of a process variable has been changed. |
| 81 | + * @param event |
| 82 | + */ |
| 83 | + void afterVariableChanged(ProcessVariableChangedEvent event); |
| 84 | +
|
| 85 | + /** |
| 86 | + * This listener method is invoked right before a process/node instance's SLA has been violated. |
| 87 | + * @param event |
| 88 | + */ |
| 89 | + default void beforeSLAViolated(SLAViolatedEvent event) {} |
| 90 | +
|
| 91 | + /** |
| 92 | + * This listener method is invoked right after a process/node instance's SLA has been violated. |
| 93 | + * @param event |
| 94 | + */ |
| 95 | + default void afterSLAViolated(SLAViolatedEvent event) {} |
| 96 | +
|
| 97 | + /** |
| 98 | + * This listener method is invoked when a signal is sent |
| 99 | + * @param event |
| 100 | + */ |
| 101 | + default void onSignal(SignalEvent event) {} |
| 102 | +
|
| 103 | + /** |
| 104 | + * This listener method is invoked when a message is sent |
| 105 | + * @param event |
| 106 | + */ |
| 107 | + default void onMessage(MessageEvent event) {} |
| 108 | +} |
| 109 | +---- |
| 110 | + |
| 111 | +You can implement any of these methods to process the corresponding event. |
| 112 | + |
| 113 | +For the definition of the event classes that the {PROCESS_ENGINE} passes to the methods, see the `org.kie.api.event.process` package in the https://docs.jboss.org/drools/release/{COMMUNITY_VERSION_FINAL}/kie-api-javadoc/index.html[Java documentation]. |
| 114 | + |
| 115 | +You can use the methods of the event class to retrieve other classes that contain all information about the entities involved in the event. |
| 116 | + |
| 117 | +The following example is a part of a node-related event, such as `afterNodeLeft()`, and retrieves the process instance and node type. |
| 118 | + |
| 119 | +.Retrieving the process instance and node type in a node-related event |
| 120 | +[source,java] |
| 121 | +---- |
| 122 | +WorkflowProcessInstance processInstance = event.getNodeInstance().getProcessInstance() |
| 123 | +NodeType nodeType = event.getNodeInstance().getNode().getNodeType() |
| 124 | +---- |
| 125 | + |
| 126 | +== Interfaces for task lifecycle event listeners |
| 127 | + |
| 128 | +You can develop a class that implements the `TaskLifecycleEventListener` interface. This class can listen to events related to the lifecycle of tasks, such as assignment of an owner or completion of a task. |
| 129 | + |
| 130 | +The following source code shows the different methods of the `TaskLifecycleEventListener` interface: |
| 131 | + |
| 132 | +.The `TaskLifecycleEventListener` interface |
| 133 | +[source,java] |
| 134 | +---- |
| 135 | +public interface TaskLifeCycleEventListener extends EventListener { |
| 136 | +
|
| 137 | + public enum AssignmentType { |
| 138 | + POT_OWNER, |
| 139 | + EXCL_OWNER, |
| 140 | + ADMIN; |
| 141 | + } |
| 142 | +
|
| 143 | + public void beforeTaskActivatedEvent(TaskEvent event); |
| 144 | + public void beforeTaskClaimedEvent(TaskEvent event); |
| 145 | + public void beforeTaskSkippedEvent(TaskEvent event); |
| 146 | + public void beforeTaskStartedEvent(TaskEvent event); |
| 147 | + public void beforeTaskStoppedEvent(TaskEvent event); |
| 148 | + public void beforeTaskCompletedEvent(TaskEvent event); |
| 149 | + public void beforeTaskFailedEvent(TaskEvent event); |
| 150 | + public void beforeTaskAddedEvent(TaskEvent event); |
| 151 | + public void beforeTaskExitedEvent(TaskEvent event); |
| 152 | + public void beforeTaskReleasedEvent(TaskEvent event); |
| 153 | + public void beforeTaskResumedEvent(TaskEvent event); |
| 154 | + public void beforeTaskSuspendedEvent(TaskEvent event); |
| 155 | + public void beforeTaskForwardedEvent(TaskEvent event); |
| 156 | + public void beforeTaskDelegatedEvent(TaskEvent event); |
| 157 | + public void beforeTaskNominatedEvent(TaskEvent event); |
| 158 | + public default void beforeTaskUpdatedEvent(TaskEvent event){}; |
| 159 | + public default void beforeTaskReassignedEvent(TaskEvent event){}; |
| 160 | + public default void beforeTaskNotificationEvent(TaskEvent event){}; |
| 161 | + public default void beforeTaskInputVariableChangedEvent(TaskEvent event, Map<String, Object> variables){}; |
| 162 | + public default void beforeTaskOutputVariableChangedEvent(TaskEvent event, Map<String, Object> variables){}; |
| 163 | + public default void beforeTaskAssignmentsAddedEvent(TaskEvent event, AssignmentType type, List<OrganizationalEntity> entities){}; |
| 164 | + public default void beforeTaskAssignmentsRemovedEvent(TaskEvent event, AssignmentType type, List<OrganizationalEntity> entities){}; |
| 165 | +
|
| 166 | + public void afterTaskActivatedEvent(TaskEvent event); |
| 167 | + public void afterTaskClaimedEvent(TaskEvent event); |
| 168 | + public void afterTaskSkippedEvent(TaskEvent event); |
| 169 | + public void afterTaskStartedEvent(TaskEvent event); |
| 170 | + public void afterTaskStoppedEvent(TaskEvent event); |
| 171 | + public void afterTaskCompletedEvent(TaskEvent event); |
| 172 | + public void afterTaskFailedEvent(TaskEvent event); |
| 173 | + public void afterTaskAddedEvent(TaskEvent event); |
| 174 | + public void afterTaskExitedEvent(TaskEvent event); |
| 175 | + public void afterTaskReleasedEvent(TaskEvent event); |
| 176 | + public void afterTaskResumedEvent(TaskEvent event); |
| 177 | + public void afterTaskSuspendedEvent(TaskEvent event); |
| 178 | + public void afterTaskForwardedEvent(TaskEvent event); |
| 179 | + public void afterTaskDelegatedEvent(TaskEvent event); |
| 180 | + public void afterTaskNominatedEvent(TaskEvent event); |
| 181 | + public default void afterTaskReassignedEvent(TaskEvent event){}; |
| 182 | + public default void afterTaskUpdatedEvent(TaskEvent event){}; |
| 183 | + public default void afterTaskNotificationEvent(TaskEvent event){}; |
| 184 | + public default void afterTaskInputVariableChangedEvent(TaskEvent event, Map<String, Object> variables){}; |
| 185 | + public default void afterTaskOutputVariableChangedEvent(TaskEvent event, Map<String, Object> variables){}; |
| 186 | + public default void afterTaskAssignmentsAddedEvent(TaskEvent event, AssignmentType type, List<OrganizationalEntity> entities){}; |
| 187 | + public default void afterTaskAssignmentsRemovedEvent(TaskEvent event, AssignmentType type, List<OrganizationalEntity> entities){}; |
| 188 | +
|
| 189 | +} |
| 190 | +---- |
| 191 | + |
| 192 | +You can implement any of these methods to process the corresponding event. |
| 193 | + |
| 194 | +For the definition of the event class that the {PROCESS_ENGINE} passes to the methods, see the `org.kie.api.task` package in the https://docs.jboss.org/drools/release/{COMMUNITY_VERSION_FINAL}/kie-api-javadoc/index.html[Java documentation]. |
| 195 | + |
| 196 | +You can use the methods of the event class to retrieve the classes representing the task, task context, and task metadata. |
0 commit comments