Skip to content

Commit

Permalink
Updated for Drools 6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bsbodden committed Jan 11, 2015
1 parent 5ba3dfd commit c5402df
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
.classpath
.project
.settings/*
/target/
10 changes: 0 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<artifactId>drools-core</artifactId>
<groupId>org.drools</groupId>
<version>5.4.0.Final</version>
</dependency>
<dependency>
<artifactId>drools-compiler</artifactId>
<groupId>org.drools</groupId>
<version>5.4.0.Final</version>
</dependency>
<dependency>
<artifactId>xstream</artifactId>
<groupId>com.thoughtworks.xstream</groupId>
Expand Down
52 changes: 13 additions & 39 deletions src/main/java/org/integrallis/drools/DroolsTest.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,30 @@
package org.integrallis.drools;

import org.apache.log4j.Logger;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

public class DroolsTest {

private static Logger applicationLogger = Logger.getLogger(DroolsTest.class);

public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase knowledgeBase = readKnowledgeBase();
StatefulKnowledgeSession knowledgeSession = knowledgeBase.newStatefulKnowledgeSession();

knowledgeSession.setGlobal("myLogger", applicationLogger);

KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(knowledgeSession, "test");
KieSession knowledgeSession = null;
try {
// load up the knowledge base
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
knowledgeSession = kContainer.newKieSession("ksession-rules");

knowledgeSession.setGlobal("applicationLogger", applicationLogger);
knowledgeSession.insert(new SomeClass("Hey you!"));

knowledgeSession.fireAllRules();
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}

private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
knowledgeBuilder.add(ResourceFactory.newClassPathResource("sample.drl"), ResourceType.DRL);
KnowledgeBuilderErrors errors = knowledgeBuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
return knowledgeBase;
} finally {
knowledgeSession.dispose();
}
}



}
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/kmodule.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="rules" packages="rules">
<ksession name="ksession-rules"/>
</kbase>
</kmodule>
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/maven/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
groupId=org.integrallis
artifactId=drools-greeter
version=0.0.1
12 changes: 12 additions & 0 deletions src/main/resources/rules/sample.drl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.integrallis.drools

global org.apache.log4j.Logger applicationLogger

rule "LoggingWithLog4J"
when
object : SomeClass()
then
applicationLogger.info("SomeClass says " + object.getMessage());

end

12 changes: 0 additions & 12 deletions src/main/rules/sample.drl

This file was deleted.

0 comments on commit c5402df

Please sign in to comment.