A.2. Events mechanism

During process execution, the Process Engine makes sure that all the relevant tasks are executed according to the Process definition, the underlying work items, and other resources. However, a Process instance often needs to react to a particular event it was not directly requesting. Such events can be created and caught by the Intermediate Event elements (see the Red Hat JBoss BPM Suite User Guide). Explicitly representing these events in a Process allows the author to specify how the particular Event should be handled.

An Event must specify the type of event it should handle. It can also define the name of a variable, which will store the data associated with the event. This allows subsequent elements in the Process to access the event data and take appropriate action based on this data.

An event can be signaled to a running instance of a process in a number of ways:

  • Internal event: Any action inside a process (for example, the action of an action node, or an on-entry or on-exit action of some node) can signal the occurrence of an internal event to the surrounding Process instance.

    Example A.3. Schema of the call sending an event to the Process instance

    kcontext.getProcessInstance().signalEvent(type, eventData);
  • External event: A process instance can be notified of an event from outside

    Example A.4. Schema of the call notifying a Process instance about an external event

    processInstance.signalEvent(type, eventData);
  • External event using event correlation: Instead of notifying a Process instance directly, you can notify the entire Session and let the engine determine which Process instances might be interested in the event using event correlation. Event correlation is determined based on the event type. A Process instance that contains an Event element listening to external events of some type is notified whenever such an event occurs. To signal such an event to the process engine, write code such as:

    Example A.5. Schema of the call notifying a Session about an external event

    ksession.signalEvent(type, eventData);

Events can also be used to start a process. Whenever a Message Start Event defines an event trigger of a specific type, a new process instance starts every time that type of event is signalled to the process engine.

This mechanism is used for implementation of the Intermediate Events and can be used to define custom Events if necessary.