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.
12 years, 10 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.
12 years, 10 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.
12 years, 10 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
12 years, 10 months
Is it possible to deploy Guvnor and Form Builder on different nodes to work in embeded structure
by Zahid Ahmed
Hi,
I have a form builder embedded in guvnor. And both are deployed on the same node of jboss on porty 8080. I want to deploy these on different nodes and want form-builder to still open with in guvnor. I just wanna know that, Is it possible to deploy Guvnor on one node of jboss and Form builder on a different node. Being on different nodes form builder can still be embedded in guvnor. Is there any configuration available to do this. I want to do this to share server's load. People creating processes and forms both have different servers and the applications accessing assets are directly getting it from guvnor.
For example :
Node 1 :
IP : 127. 0.0.1
Port : 8080
URL : http://127.0.0.1:8080/drools-guvnor
Node 2 :
IP : 127. 0.0.1
Port : 8888
URL : http://127.0.0.1:8888/form-builder
Deployment Environment :
JBOSS-AS-7.1.1
Guvnor 5.4.0.Final
Jbpm-form-builder 5.4.0.Final
Thanks and Best Regards,
Zahid Ahmed
Senior Software Engineer | Emirates Group IT
P.O. Box 686 | Dubai, United Arab Emirates
T +971 4 245 2551| M +971 55 124 9171
12 years, 10 months
Re: [rules-users] How to dynamic remove or add the rules
by rjr201
You need to pass an Agenda Filter to the runRules() method that will filter
which rules are allowed to run.
For example..
public class MyAgendaFilter implements AgendaFilter {
/** List of rule names to be allowed to fired*/
ArrayList<String> rulesToFire;
public MyAgendaFilter() {
rulesToFire = new ArrayList<String>();
}
/**
* Adds a rule to list of rules to be allowed to fire
* @param name Name of rule to be fired
*/
public void addRuleToFire(String name) {
rulesToFire.add(name);
}
@Override
public boolean accept(Activation activation) {
if (rulesToFire.contains(activation.getRule().getName())) {
return true;
} else {
return false;
}
}
}
This can then be used as follows:
AgendaFilter filter = new MyAgendaFilter();
filter.addRuleToFire("Rule Name");
StatefulKnowledgeSession knowledgeSession =
kbase.newStatefulKnowledgeSession();
knowledgeSession.fireAllRules(filter);
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-dynamic-remove-or-add-the-rules-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
Is it possible to leave the "then" block empty?
by Aleksandar Toshovski
Hello,
I have many rules, which have exactly the same "then" block. Is it possible to leave the then cause empty? I only need to know is if a rule was activated or not and for this reason I'm using WorkingMemoryConsoleLogger.activationCreated().
Best Regards,
Aleksandar Toshovski
12 years, 10 months