Show Table of Contents
3.4. Defining Sessions
You can create a Kie Session either using the API or in the
kmodule.xml project descriptor file of your project via the Project Editor.
Defining Kie Session using API
Once you have loaded your Kie Base, you need to create a Kie Session to interact with the Process Engine to run and manage its Process instances.
Example 3.1. Creating a Kie Session and starting a MyProcess instance
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.process.ProcessInstance;
...
KieSession ksession = kBase.newKieSession();
ProcessInstance processInstance = ksession.startProcess("com.sample.MyProcess");
You can interact with Process instances through the
ProcessRuntime interface that the Kie Sesssions implement.
ProcessRuntime methods
- ProcessInstance startProcess(String processId);
- The method starts a new Process instance of the process with the specified ID and returns the ProcessInstance reference
- ProcessInstance startProcess(String processId, Map<String, Object> parameters);
- The method starts a new process instance of the process with the specified ID and returns the ProcessInstance reference. Additional parameters provided as a Map (as name-value pairs) are set as variables of the process instance.
- void signalEvent(String type, Object event);
- The method signals the Process Engine that an event of the defined type has occurred. The event parameter can contain additional information related to the event. All process instances that are listening to this type of external event are notified. For performance reasons, it is recommended to use this type of event signaling only if exactly one process instance is able to notify other process instances. For internal event within one process instance, use the signalEvent method that also includes the processInstanceId of the respective process instance.
- void signalEvent(String type, Object event, long processInstanceId);
- The method signals to a Process instance that an event has occurred. The type parameter defines which type of event and the event parameter can contain additional information related to the event. All node instances inside the given Process instance that are listening to this type of (internal) event are notified. Note that the event is only processed inside the given Process instance. No other Process instances waiting for this type of event are notified.
- Collection<ProcessInstance> getProcessInstances();
- The method returns a collection of the currently active Process instaces. Only Process instances that are currently loaded and active in the Process Engine are returned. When using persistence, the persisted Process instances are not returned. It is recommended to use the history log to collect the information about the state of your Process instances instead.
- ProcessInstance getProcessInstance(long processInstanceId);
- The method returns the Process instance with the given id. Only active Process instances are returned: if a Process instance has been completed, the method returns
null. - void abortProcessInstance(long processInstanceId);
- The method aborts the Process instance with the given ID. If the Process instance has been completed or aborted, or it cannot be found, the method throws an IllegalArgumentException.
- WorkItemManager getWorkItemManager();
- The method returns the WorkItemManager related to the Kie Session. The returned object reference can be used to register new WorkItemHandlers or to complete or abort WorkItems.
Defining Kie Session in the Project Editor
To define a Kie Session in the web environment in the
kmodule.xml file, do the following:
- Open your project properties with the Project Editor: in the Project Explorer, locate your project root. In the perspective menu, go to → .
- In the drop-down box of the Project Screen view, click Knowledge bases and sessions.
- On the left side, select .
- You can now add a new ksession and set default, state, and clock.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.