Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| KIE API 6.0.0.CR2
PREV NEXT | FRAMES NO FRAMES

# KIE API 6.0.0.CR2 API

Drools & jBPM provide an knowledge-centric API, where rules and processes are first class citizens.

See:
Description

Builder API
org.kie.api.builder |

Other Packages
org.kie.api | The KnowledgeBase and its factory.
org.kie.api.builder.model |
org.kie.api.cdi |
org.kie.api.command |
org.kie.api.concurrent |
org.kie.api.conf |
org.kie.api.definition | All classes to create definitions, as built by the KnowledgeBuilder from artifact resources, can be found here.
org.kie.api.definition.process | The classes that make up a Process definition.
org.kie.api.definition.rule | The classes that make up a Rule definition.
org.kie.api.definition.type |
org.kie.api.event | Drools has a comprehensive event api for all parts of the platform.
org.kie.api.event.kiebase | Events emitted while updating the definitions in the KnowledgeBase.
org.kie.api.event.process | Events emitted while process instances are executing.
org.kie.api.event.rule | Events emitted while Rules are executing.
org.kie.api.io | io library for working with Resources See ResourceFactory for more details
org.kie.api.logger | Logger classes use to log the KnowledgeRuntime's execution.
org.kie.api.management |
org.kie.api.marshalling | Marshalling classes are used to marshall and unmarshal StatefulKnowledgeSessions See MarshallerFactory for more detailed information.
org.kie.api.osgi |
org.kie.api.persistence.jpa |
org.kie.api.runtime | The runtime engine classes, including StatefulKnowledgeSession and StatelessKnowledgeSession.
org.kie.api.runtime.conf |
org.kie.api.runtime.help |
org.kie.api.runtime.manager |
org.kie.api.runtime.process | The process runtime classes.
org.kie.api.runtime.rule | The rule runtime classes.
org.kie.api.task |
org.kie.api.task.model |
org.kie.api.time | Classes related to Time in Drools.

Drools & jBPM provide an knowledge-centric API, where rules and processes are first class citizens.

The most common interfaces you will use are:

- `org.kie.internal.builder.KnowledgeBuilder`
- `org.kie.internal.KnowledgeBase`
- `org.kie.internal.agent.KnowledgeAgent`
- `org.kie.internal.runtime.StatefulKnowledgeSession`
- `org.kie.internal.runtime.StatelessKnowledgeSession`

Factory classes, with static methods, provide instances of the above interfaces. A pluggable provider approach is used to allow provider implementations to be wired up to the factories at runtime. The Factories you will most commonly used are:

- `org.kie.internal.builder.KnowledgeBuilderFactory`
- `org.kie.internal.io.ResourceFactory`
- `org.kie.internal.KnowledgeBaseFactory`
- `org.kie.internal.agent.KnowledgeAgentFactory`

A Typical example to load a rule resource.

    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add( ResourceFactory.newUrlResource( url ),
                          ResourceType.DRL );
    if ( kbuilder.hasErrors() ) {
        System.err.println( builder.getErrors().toString() );
    }

    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages( builder.getKnowledgePackages() );

    StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();
    ksession.insert( new Fibonacci( 10 ) );
    ksession.fireAllRules();

    ksession.dispose();

A Typical example to load a process resource. Notice the ResourceType is changed to BPMN2 in this example.

    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add( ResourceFactory.newUrlResource( url ),
                  ResourceType.BPMN2 );
    KnowledgeBase kbase = kbuilder.newKnowledgeBase();
    StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();
    ksession.startProcess( "Buy Order Process" );
    ksession.dispose();

'kbuilder', 'kbase', 'ksession' are the variable identifiers often used, the k prefix is for 'knowledge'.

It is also possible to configure a KnowledgeBase using configuration, via a xml change set, instead of programmatically. Here is a simple change set:

    <change-set xmlns='http://drools.org/drools-5.0/change-set'
               xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
               xs:schemaLocation='http://drools.org/drools-5.0/change-set change-set-5.0.xsd' >
      <add>
        <resource source='classpath:org/domain/someRules.drl' type='DRL' />
        <resource source='classpath:org/domain/myProcess.bpmn2' type='BPMN2' />
      </add>
    </change-set>

And it is added just like any other ResourceType

    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add( ResourceFactory.newUrlResource( url ),
                  ResourceType.ChangeSet );

The majority of knowledge API is considered stable and should not change, experimental classes and API's will be marked as such.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| KIE API 6.0.0.CR2
PREV NEXT | FRAMES NO FRAMES

Copyright © 2001-2013 JBoss by Red Hat. All Rights Reserved.