Detailed explanation of the basic API of KIE

When using some terms, I sometimes use KIE project, KIE engine or Drools project, Drools engine. Everyone should understand that KIE is a general term for projects such as Drools, so in most cases KIE or specifically Drools are similar of.

Now we start to understand the related APIs of KIE. In this helloworld example, we have been exposed to the following classes and interfaces:

kie-api-class-1

We get a KieContainer through the KieServices object, then KieContainer creates a new KieSession according to the session name, and finally runs the rules through KieSession.

KieServices:

This interface provides many methods, through which you can access KIE related objects related to construction and operation. For example, you can obtain KieContainer, use KieContainer to access KBase and KSession and other information; you can obtain KieRepository objects, and use KieRepository to manage KieModule, etc.

KieServices is a center, through which various objects are obtained to complete the construction, management and execution of rules.

KieContainer:

It can be understood that KieContainer is a container of KieBase. What is KieBase?

KieBase

KieBase is a knowledge warehouse, including a number of rules, processes, methods, etc. In Drools, it is mainly rules and methods. KieBase itself does not contain runtime data and the like. If you need to execute the rules in KieBase, you need to KieSession needs to be created based on KieBase.

KieSession:

KieSession is a session that deals with the Drools engine. It is created based on KieBase. It contains runtime data, including "facts", and performs rule operations on runtime data facts. It is a more convenient way to create KieSession through KieContainer. In fact, it is essentially created from KieBase. of.

KieSession is the session channel through which the application interacts with the rule engine.

Creating KieBase is a very expensive thing. KieBase will build a knowledge (rule, process) warehouse, while creating KieSession is a very low-cost thing, so KieBase will build a cache, but KieSession doesn't have to.

A more complete class relationship is as follows:

kie-api-class-2

KieRepository:

KieRepository is a singleton object, it is a repository for storing KieModule, KieModule is defined by the kmodule.xml file (of course not just defined by it).

ChooseProject:

KieContainer initializes and constructs KieModule through KieProject, and stores KieModule in KieRepository. Then KieContainer can find the information defined by KieModule through KieProject, and construct KieBase and KieSession according to this information.

ClasspathKieProject:

ClasspathKieProject implements the KieProject interface, which provides the ability to construct KieModule based on the META-INF/kmodule.xml file in the classpath, which is one of the basic guarantees that we can construct Drools components based on Maven.

It means that as long as we organize our rule files or process files according to the Maven project structure mentioned earlier, we can load and build the model with very little code.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326644544&siteId=291194637