In this guide we will discuss about Core-Engine API of jBPM. Core-Engine creates an API which we need to load processes and execute them.
This API allows us to first create a Knowledge Base which include all our process definition that needs to be executed by the Session. This session has a reference to the Knowledge Base.
To understand the jBPM Core-Engine API, we need to understand the following basic definition:
Knowledge Base
A Knowledge Base is a repository of all the relevant process definitions. It contains rules, processes, functions and type models. It always helps us to look up the processes definition whenever necessary. A Knowledge Base can be created only once and it can be changed dynamically.
The following code shows the creation of Knowledge Base:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("ruleflow.rf"), ResourceType.DRF); knowledgebase kbase = kbuilder.newknowledgeBase();
Session
A Knowledge Base contains a reference to the session. Whenever we want to start a process, we need to set up a session which is responsible for communication with the process engine. After setting up the session we are able to start the execution of our processes. Whenever a process starts executing, it creates an instance of that process and maintains the state of that process instance. A session can be created many times.
The following code shows the creation of Session:
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test"); // start a new process instance ksession.startProcess("com.sample.ruleflow"); logger.close();
Next Topic : Click Here