Delete a List of Facts
by Weiss, Wolfgang
Hi,
I want to delete a list of facts from the working memory and therefore created following rule:
rule "delete rule"
agenda-group "evaluation"
salience 50
no-loop true
when
$facts : ArrayList(size > 0) from collect (Fact())
then
logger.info("delete rule, number of facts in list: " + $facts.size());
for (int i = 0; i < $facts.size(); i++) {
Fact f = (Fact)$facts.get(i);
logger.info("retract fact id: " + f.getId());
retract(f);
}
end
When inserting 10 facts with IDs 1 to 10 and then fire all rules, I get following result:
delete rule, number of facts in list: 10
retract fact id: 1
retract fact id: 3
retract fact id: 5
retract fact id: 7
retract fact id: 9
but, the facts 2, 4, 6, 8 and 10 are not deleted. I would have expected to set "no-loop" to true, as I do some modification of facts and don't want that this rule is fired again with the same facts. When I set "no-loop" to false, I get following result:
delete rule, number of facts in list: 10
retract fact id: 1
retract fact id: 3
retract fact id: 5
retract fact id: 7
retract fact id: 9
delete rule, number of facts in list: 5
retract fact id: 2
retract fact id: 6
retract fact id: 10
delete rule, number of facts in list: 2
retract fact id: 4
delete rule, number of facts in list: 1
retract fact id: 8
now, all facts are deleted but the "delete rule" was fired 4 times. Is this the intended behavior of Drools? Is there a way to fire a rule only once and delete a list of facts?
I can reproduce this behavior with Drools 5.5.0.Final and 6.0.0.Beta2 but did not try any other version.
Best Regards,
Wolfgang
11 years, 7 months
Benefits of pluggable operators
by Thomas Grayson
What are the benefits of using pluggable operators (implementations of org.drools.base.evaluators.EvaluatorDefinition such str, matches, or before) versus simply making an equivalent function call? I've read the Creating pluggable operators<http://blog.athico.com/2010/06/creating-pluggable-oprators.html> blog post. Apart from saying that the Eclipse plugin can recognize these operators, it doesn't really make a case for why I'd want to create my own implementation. One might argue that operators enhance reusability, but a static method offers much the same benefit. Does a pluggable operator have any optimization, caching, or other advantage?
For example, here are two ways to match the start of a string in a property of a fact, one using the "str[startsWith]" operator and another with Java's String.startsWith method:
declare Fact
key : String @key
end
rule "Use operator"
when
Fact(key str[startsWith] "abc")
then
// do something
end
rule "Use method"
when
Fact(key.startsWith("abc"))
then
// do something
end
Does one of these perform better than the other?
Best wishes,
Tom
11 years, 7 months
Guvnor 5.5 deployment error on WAS8
by mbrameshkumar
Hi,
I am trying to deploy drools guvnor 5.5 on was8.0 through admin console. It
fails with NullPointerException.
Could you please suggest me the changes required in tomcat version of
guvnor war to deploy it in WAS 8 environment. Do I need to rebuild the war
file with different configurations for WAS env?
Please guide me to proceed on this.
Thanks in advance
Best regards
Ramesh
--
View this message in context: http://drools.46999.n3.nabble.com/Guvnor-5-5-deployment-error-on-WAS8-tp4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
Error deserializing Knowledge Package in Drools 5.5.0
by Narkha
Hello
I'm getting an exception when adding a Collection<KnowledgePackage> after
read it from a file with readObject()
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at
org.drools.base.ClassObjectType.isAssignableFrom(ClassObjectType.java:180)
at
org.drools.reteoo.builder.PatternBuilder.attachPattern(PatternBuilder.java:95)
at org.drools.reteoo.builder.PatternBuilder.build(PatternBuilder.java:80)
at
org.drools.reteoo.builder.GroupElementBuilder$AndBuilder.build(GroupElementBuilder.java:112)
at
org.drools.reteoo.builder.GroupElementBuilder.build(GroupElementBuilder.java:70)
at
org.drools.reteoo.builder.ReteooRuleBuilder.addSubRule(ReteooRuleBuilder.java:161)
at
org.drools.reteoo.builder.ReteooRuleBuilder.addRule(ReteooRuleBuilder.java:134)
at org.drools.reteoo.ReteooBuilder.addRule(ReteooBuilder.java:113)
at org.drools.reteoo.ReteooRuleBase.addRule(ReteooRuleBase.java:445)
at org.drools.common.AbstractRuleBase.addRule(AbstractRuleBase.java:952)
at
org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:629)
*at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:472)*
at
org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:149)
at
andanta.conversacion.DroolsEmpresa.readKnowledgeBaseFromMemoryFile(DroolsEmpresa.java:304)
at
andanta.comunicacion.ServidorMR.cargaInfoConocimiento(ServidorMR.java:483)
at andanta.test.Tester.main(Tester.java:127)
The code for serialize the object is
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(
fileName ) );
out.writeObject( kbuilder.getKnowledgePackages());
out.close();
And the code for deserialize is
ObjectInputStream in = new ObjectInputStream( new FileInputStream(
fileName) );
Collection<KnowledgePackage> kpkgs =
(Collection<KnowledgePackage>)in.readObject();
in.close();
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kpkgs );
My environment is eclipse 3.7, java 7.0.21 y drools 5.5.0.
I thought this error may be due to a rule, but if I run
kbase.addKnowledgePackages after reading the rules from drl file, there will
be no exception.
Best Regards.
--
View this message in context: http://drools.46999.n3.nabble.com/Error-deserializing-Knowledge-Package-i...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
Reading a Guvnor PKG from drools API
by abhinay_agarwal
Hey,
I was trying to read a package(ResourceType.PKG), which i downloaded from
Guvnor, using KnowledgeBuilder, but I consistently get the following error
while trying to access the file.
Here's my code and the error,
**Code**
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "Goal Creation
Charges.pkg", getClass() ), ResourceType.PKG );
if ( kbuilder.hasErrors() ) {
System.err.println( kbuilder.getErrors().toString() );
}
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
**Error**
java.lang.RuntimeException: java.io.StreamCorruptedException: invalid stream
header: 7061636B
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:724)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
at
com.infosys.fps.drools.adapter.DroolsAdapter.readKnowledgeBase(DroolsAdapter.java:80)
at com.infosys.fps.drools.adapter.DroolsAdapter.main(DroolsAdapter.java:20)
Caused by: java.io.StreamCorruptedException: invalid stream header: 7061636B
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
at
org.drools.common.DroolsObjectInputStream.<init>(DroolsObjectInputStream.java:68)
at
org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:205)
at
org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:189)
at
org.drools.compiler.PackageBuilder.addPackageFromInputStream(PackageBuilder.java:819)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:711)
... 4 more
I have tried using both binary and source from guvnor, but neither of them
works. I get the same error. Is there something m doing wrong ?
Thanks,
Abhinay
--
View this message in context: http://drools.46999.n3.nabble.com/Reading-a-Guvnor-PKG-from-drools-API-tp...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
Shared Facts across nodes
by mauro
Hello all,
After searching the web and Drools forums for a couple of days, I couldn't
find a solution to the problem I've got to solve. Anyway, if there's a
thread pointing at the same problem, I apologize and please, let me know
where it is.
My current scenario involves a Drools cluster and demands high availability
and scalability of nodes.
I have to provide a pool of rules (Guvnor should easily handle that) and a
set of servers to process facts against those rules.
This is where I'm stuck at.
I need to make sure all generated facts are shared across drools servers at
the time they get into the cluster.
In other words, what I need is a kind of shared (and persistent) session,
and this session should contain unique facts, so the nodes don't waste time
processing what has already been processed by another node. Also, session
response time is critical.
Since I'm new to the Drools world, maybe I'm missing some important aspects
here, however, as far as I understood, Drools should be able to supply my
requirements.
Already read about Drools-Grid (Is it still alive? Being developed?
Reliable?) and JBoss Infinispan. Both seem to help on solving this
requirement, but I'm not sure whether they're the correct tools to attach to
the arch and get to the solution.
Moreover, I have to make sure an instance of Guvnor can share rules with
other instances being queried by the Drools servers.
How can I solve the problems?
Thank you in advance,
Mauro
--
View this message in context: http://drools.46999.n3.nabble.com/Shared-Facts-across-nodes-tp4023210.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
Action Object and Condition Object in XLS DTABLE
by Ramon Buckland
Hi.
I am working on Drools 5.5.0.Final and have a question regarding XLS and a Decision Table structure,
I have a ConditionObject and an ActionObject and wanted to know or see an example for XLS that produces a "does exist" for the ActionObject
in the when.
I can simply write the rule in a DRL, but translating how to make the XLS compiler create the same is proving challenging.
An example:
I want to produce a set of rules like below
rule "Test rule_11"
when
$c : ConditionObject( somefield )
EmbeddedObject(myField == AnEnum.SomeValue) from $c.embedded
$a : ActionObject( )
then
$a.someMethod("value")
$a.someMethod2(10)
$a.someMethod3("A")
end
rule "Test rule_12"
// some other AnEnum checks.
What I can't work out is how I get the test of "existence" of the Action Object into the "when" for the rule, so that I can "use" the Object in the ACTION.
In addition, is there a away that I can avoid needing a whole column just for "existence of an object with a field.. collect as a variable $c : (ConditionObject( somefield )" ?
CONDITION CONDITION ACTION ACTION ACTION
$c : ConditionObject EmbeddedObject() from $c.embedded
$param myField == AnEnum.$param $a.someMethod("$param") $a.someMethod2($param) $a.someMethod3($param)
"Description" "Description" "Description" "Description" "Description"
somefield SomeValue value 10 A
somefield SomeOtherValue someOtherValue 50 B
This is the XLS of the above.
https://www.dropbox.com/s/lw3zb5hwtjdbpcm/sample_rules.xls?v=1scns
When this sheet is compiled, I get the following: How do I setup a "condition" for ActionObject to get in the when ?
package packageName;
//generated from Decision Table
// rule values at A8, header at A3
rule "Test rule_8"
when
$c : ConditionObject(somefield)
EmbeddedObject(myField == AnEnum.SomeValue) from $c.embedded
then
$a.someMethod("value")
$a.someMethod2(10)
$a.someMethod3(A)
end
// rule values at A9, header at A3
rule "Test rule_9"
when
$c : ConditionObject(somefield)
EmbeddedObject(myField == AnEnum.SomeOtherValue) from $c.embedded
then
$a.someMethod("someOtherValue")
$a.someMethod2(50)
$a.someMethod3(B)
end
Ramon Buckland
ramon(a)thebuckland.com
11 years, 7 months