Showing posts with label Drools. Show all posts
Showing posts with label Drools. Show all posts

Monday, July 8, 2013

Drools Core

  1. create a knowledge builder to load processes from various resources (for example from the classpath or from file system)
  2. create a knowledge base from the builder
  3. instantiate a session based on the knowledge base
  4. start executing processes
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("ruleflow.rf"), ResourceType.DRF);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ProcessInstance processInstance = ksession.startProcess("com.sample.MyProcess");
ksession.fireAllRules();

Thursday, February 7, 2013

JBoss Drools

JBoss/JBoss AS (JavaBeans Open Source Software Application Server)

- now has a new name WildFly
- is a J2EE platform for developing and deploying enterprise Java applications, Web applications and services, and portals

Drools/JBoss Rules

- a rule language
- case sensitive
- single line comments starts with # or //, multi-line comments are enclosed in /* and */

Rule file - file ending with .drl

jBPM

- is a flexible java Business Process Management (BPM) Suite
BPM makes the bridge between business analysts, developers and end users, by offering process management features and tools in a way that both business users and developers like it

Components of jBPM

  • core process engine - the only required component
    • history log
    • human task service
  • graphical editors
    • eclipse plugin
    • web-based designer
  • Guvnor respository - can store all business processes
  • jBPM console - web-based console for managinf business processes

Core

knowledge base
   - used to look up the process definitions whenever necessary
   - uses a knowledge builder to load processes from various resources (for example from the classpath, from file system or process repository), i.e.
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("ruleflow.rf"), ResourceType.DRF);
   - can be dynamically changed (so you can add or remove processes at runtime)
session
   - instantiated from knowledge base and are used to execute processes and interact with the engine

Structure of a Rule File:

package package-name - must always be the first element
imports - optional, order does not matter
globals - optional, order does not matter, define global vars
functions - optional, order does not matter
function String hello(String name) {
    return "Hello "+name+"!";
}

queries - optional, order does not matter
rules - optional, order does not matter
rule "name"
    attributes
    when
        LHS
    then
        RHS
end


Common rule attributes: 

salience - priority, higher salience values are given higher priority, default is 0, can be positive or negative
agenda-group - a group name, only rules in the agenda group that has acquired the focus are allowed to fire
activation-group - same as if else, only one will fire

Ref:
http://docs.jboss.org/jbpm/v5.1/userguide/