Declaring events separately from rules breaks expires
by Samuli Saarinen
Hello,
I have the following situation with Drools 5.1.1: 2 drl files where one
contains an event declaration:
declare Event1
@role(event)
@expires(1s)
end
and other has a simple rule:
rule "Evt1"
when
e: Event1(value == 10)
then
System.out.println(e);
end
And I have the following test which fails:
ses.insert(new Event1(1));
ses.fireAllRules();
clock.advanceTime(2, TimeUnit.SECONDS);
ses.fireAllRules();
assertEquals(ses.getFactCount(), 0L);
The same test passes if the rule and event declaration are on the same
drl file.
Further more if I declare the event in both of the files with different
@expires the one being used is the one that is added first. I was hoping
that the first declaration to be a "default expires" that could be
overwritten later on with a new declaration but it seems that this is
currently not possible.
Cheers,
Samuli
--
Remion Oy Etävalvontajärjestelmät liiketoiminnan
Samuli Saarinen tehostamiseen
gsm +358 (0)50 3560075
fax +358 (0)3 2125064 www.remion.com
13 years, 10 months
Instructions for upgrading designer.war?
by Han Ming Low
Hi,
I understand that the designer.war is a project by intalio.
When looking at the source for the war at
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/contrib/designer/desi...,
I saw the changes to be made to make it compatible with Drools.
I think I can do some of the steps like
1) changing the web.xml to use tomcat instead of jetty
2) added slf4j library
3) move lib/bpmn2 library to web-inf/lib
4) changes to oryx.js that involve
- commenting out the header
- commenting out the log
- change the repository url from "/designer/uuidRepository?uuid="+ uuid to
"/drools-guvnor/org.drools.guvnor.Guvnor/guvnorAPI?action=load&uuid="+ uuid
However, I'm not sure what is the BPMN2 import/export classes to replace in
WEB-INF/classes
Can someone could tell me which are the classes?
I can also help to update the designer. :)
Thanks.
Han Ming
13 years, 10 months
How do I prevent the package registry from being null in my package builder?
by retoy
I just installed Drools and wanted to build a simple RuleFlow.
But When I add any process containing constraints or rules to my
Knowledgebuilder, I'm always getting a NullPointerException, because the
"package registry" seems to be null.
.....
java.lang.NullPointerException
at org.drools.compiler.ProcessBuilder.buildProcess(ProcessBuilder.java:119)
at
org.drools.compiler.ProcessBuilder.addProcessFromFile(ProcessBuilder.java:223)
at
org.drools.compiler.PackageBuilder.addProcessFromXml(PackageBuilder.java:447)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:503)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:25)
.....
ProcessBuilder.java:118 PackageRegistry pkgRegistry =
this.packageBuilder.getPackageRegistry(process.getPackageName());
ProcessBuilder.java:119 org.drools.rule.Package p =
pkgRegistry.getPackage();
.....
The ruleflow is successfully validated though when i press that button in
eclipse... Can somebody give me a hint what's missing?
Thanks!
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/How-do-I-prevent-the-...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 11 months
Trying to get Eclipse Java code to call Guvnor
by John Peterson
I'm using the example code from the Red Hat Magazine -
http://magazine.redhat.com/2008/08/12/jboss-drools-how-to-tuning-guvnor-
part-1/ - to try to get the sample code to work, but I keep getting the
following error:
Exception in thread "main" java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at
org.drools.agent.RuleAgent.loadFromProperties(RuleAgent.java:299)
at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:256)
at test.GuvnorTest.main(GuvnorTest.java:15)
It appears to be unable to find my 'Guvnor.properties' file, but I have
it in the classpath (I actually have it in several different places on
my C: drive as I tried to figure out why it couldn't find it). Does
anyone have any thoughts on what's wrong here?
I'd appreciate any guidance. It seems like this should be a simple
answer but I haven't been able to figure it out.
13 years, 11 months
About for and inheritance
by Chris Woodrow
Hi,
I recently find out a few issues using for, and I wanted to share it with
you. I made a simple exemple to illustrate my purpose.
My classes are (I did not represent accessors & constructors):
public class Cheese {
protected String name;
}
public class FrenchCheese extends Cheese{
private String smell;
}
public class Person {
private Cheese likes;
}
Here is my rule set :
package rules
rule "likes cheese"
when
$person : Person ()
Cheese( ) from $person.getLikes()
then
System.out.println("likes cheese");
end
rule "likes french cheese"
when
$person : Person ()
FrenchCheese( ) from $person.getLikes()
then
System.out.println("likes french cheese");
end
First test :
Cheese cheese = new FrenchCheese("good", "camembert");
Person person = new Person();
person.setLikes(cheese);
Output :
likes french cheese
likes cheese
Wich is expected...
Second test :
Cheese cheese = new Cheese();
Person person = new Person();
person.setLikes(cheese);
Output :
likes french cheese
likes cheese
That's the first strange thing. As far as I am concerned, rule "likes french
cheese" should not match (since a Cheese is not a FrenchCheese).
I made a change to the second rule :
rule "likes french cheese"
when
$person : Person ()
FrenchCheese( smell == "good" ) from $person.getLikes()
then
System.out.println("likes french cheese");
end
Third test :
Cheese cheese = new Cheese();
Person person = new Person();
person.setLikes(cheese);
output :
It throwed an exception : Exception in thread "main"
java.lang.ClassCastException: rules.Cheese
I am not saying the ClassCastException is not to expect in such a case but I
think I would simply expect it not to match (as far as a Cheese is not a
FrenchCheese).
Chris
13 years, 11 months
Integration of Drools with Hadoop
by Roger Smith
We are working on a project to integrate Drools with Apache Hadoop,
http://hadoop.apache.org/, and run into some road blocks. We would very much
appreciate any suggestions/help from this list.
We have an app where we call drools rule engine inside the reducer task of a
Hadoop map reduce job. It throws a NullPointerException when we the rule
package resource to the knowledge builder. The same code works fine when
run as part of a stand alone app.
Code:
private static Map<String, StatefulKnowledgeSession> sessions =
new HashMap<String, StatefulKnowledgeSession>();
private static final String RULE_PACK_DIR = "
file:///home/roger/Projects/gridx/ <file:///\\home\pranab\Projects\gridx\>";
private static final String RULE_PACK_EXT = ".drl";
public int process(String rulePackage, String dateTime, String type)
throws TException {
int rate = 0;
StatefulKnowledgeSession session = sessions.get(rulePackage);
if (null == session){
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
String rulePackPath = RULE_PACK_DIR + rulePackage +
RULE_PACK_EXT;
kbuilder.add( ResourceFactory.newFileResource(rulePackPath ),
ResourceType.DRL);
if ( kbuilder.hasErrors() ) {
System.err.println( kbuilder.getErrors().toString() );
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
session = kbase.newStatefulKnowledgeSession();
sessions.put(rulePackage, session);
}
ContractRule contractRule = new ContractRule();
contractRule.prepare(dateTime, type);;
FactHandle ruleHandle = session.insert(contractRule);
session.fireAllRules();
System.out.println("" + contractRule);
rate = contractRule.getRate();
session.retract(ruleHandle);
return rate;
}
This line throws the exception:
kbuilder.add( ResourceFactory.newFileResource(rulePackPath ),
ResourceType.DRL);
It works fine as a stand alone app, outside hadoop
Roger Smith
14 years
Upload an existing .drl for the Guvnor dynamically
by Vandewilly
Is there any api available that allows me to load an existing file drl for
the Guvnor repository. In my case, I can not upload through the web
interface, only in a dynamic way through a java class.
--
Vandewilly Oliveira
14 years
Drools 4.0, Support for multiple pattern in accumulate source pattern
by Juergen
It appears as if accumulate does support only a single pattern CE as
source pattern, e.g.:
Number() from accumulate(
Cheese(
price : price
),
sum( price )
)
Is it possible to have more than one pattern in the source pattern, e.g.:
Number() from accumulate(
Cheese(
price : price,
type : type
)
Person(
favouriteCheese == type,
age > 30
),
sum( price )
)
The same could be said for collect, but there the problem to specify
which item of a matching tuple is to be collected, but this could be
handled recreating collect via accumulate, e.g.:
Collection() from accumulate(
cheese : Cheese(
type : type
)
Person(
favouriteCheese == type,
age > 30
),
collect( cheese )
)
14 years