Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV NEXT | FRAMES NO FRAMES

# Knowledge API 5.4.0.Final API

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

See:
Description

Knowledge Base API
org.drools | The KnowledgeBase and its factory.

Builder API
org.drools.builder | The builder package is responsible for building knowledge definitions from artifact resources.

Definition API
org.drools.definition | All classes to create definitions, as built by the KnowledgeBuilder from artifact resources, can be found here.
org.drools.definition.process | The classes that make up a Process definition.
org.drools.definition.rule | The classes that make up a Rule definition.
org.drools.definition.type |

Event API
org.drools.event | Drools has a comprehensive event api for all parts of the platform.
org.drools.event.io |
org.drools.event.knowledgeagent |
org.drools.event.knowledgebase | Events emitted while updating the definitions in the KnowledgeBase.
org.drools.event.process | Events emitted while process instances are executing.
org.drools.event.rule | Events emitted while Rules are executing.

Runtime API
org.drools.runtime | The runtime engine classes, including StatefulKnowledgeSession and StatelessKnowledgeSession.
org.drools.runtime.conf |
org.drools.runtime.help |
org.drools.runtime.process | The process runtime classes.
org.drools.runtime.rule | The rule runtime classes.

Time API
org.drools.time | Classes related to Time in Drools.

Other Packages
org.drools.agent | The KnowlegeAgent provides automatic loading, caching and re-loading, of resources and is configured from a properties files.
org.drools.agent.conf |
org.drools.builder.conf |
org.drools.builder.help | Providers helper classes that can be used during building.
org.drools.command |
org.drools.concurrent |
org.drools.conf |
org.drools.io | io library for working with Resources See ResourceFactory for more details
org.drools.logger | Logger classes use to log the KnowledgeRuntime's execution.
org.drools.management |
org.drools.marshalling | Marshalling classes are used to marshall and unmarshal StatefulKnowledgeSessions See MarshallerFactory for more detailed information.
org.drools.osgi.api |
org.drools.persistence.jpa |
org.drools.task.service |

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

The most common interfaces you will use are:

- `org.drools.builder.KnowledgeBuilder`
- `org.drools.KnowledgeBase`
- `org.drools.agent.KnowledgeAgent`
- `org.drools.runtime.StatefulKnowledgeSession`
- `org.drools.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.drools.builder.KnowledgeBuilderFactory`
- `org.drools.io.ResourceFactory`
- `org.drools.KnowledgeBaseFactory`
- `org.drools.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
PREV NEXT | FRAMES NO FRAMES

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