For the KnowledgeAgent, a resource of type PKG is a single KnowledgePackage
object; reading is done like this, according to KnoledgeAgentImpl
InputStream is = null;
KnowledgePackageImp kpkg = null;
try {
is = resource.getInputStream();
Object object = DroolsStreamUtils.streamIn( is );
if ( object instanceof KnowledgePackageImp ) {
kpkg = ((KnowledgePackageImp) object);
} else {
kpkg = new KnowledgePackageImp( (Package) object );
}
for ( Rule rule : kpkg.pkg.getRules() ) {
rule.setResource( resource );
}
} catch ( Exception ex ) {
...
} finally {
...
}
return kpkg;
-W
2011/6/14 Lisa Horton <LHorton(a)abclegal.com>
Drools 5.1.1
I create a package from a decision table:
ObjectOutputStream out;
try {
out = new
ObjectOutputStream(new FileOutputStream(“venue.pkg”));
out.writeObject(knowledgeBase.getKnowledgePackages()); // knowledgeBase
previously loaded from spreadsheet
out.close();
} catch (IOException ex) {
logger.debug(ex.getMessage());
}
I can load this package directly into a knowledge base and run rules with
no errors:
ObjectInputStream in;
Collection<KnowledgePackage> packages =
null;
try {
in = new
ObjectInputStream(new FileInputStream(“venue.pkg”));
packages =
(Collection<KnowledgePackage>) in.readObject();
in.close();
} catch (Exception ex) {
logger.debug(ex.getMessage());
}
knowledgeBase.addKnowledgePackages(packages);
HOWEVER if I try to load the same package using a knowledge agent:
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("TheAgent");
kagent.applyChangeSet(ResourceFactory.newFileResource(“ChangeSet.xml”));
The package does not load. Any idea of the cause of these exceptions?
[2011:06:165 10:06:159:info] ResourceChangeNotification created
[2011:06:165 10:06:161:info] ResourceChangeScanner reconfigured with
interval=60
[2011:06:165 10:06:161:info] ResourceChangeScanner created with default
interval=60
[2011:06:165 10:06:162:debug] ResourceChangeNotification monitor added
monitor=org.drools.io.impl.ResourceChangeScannerImpl@5c73a7ab
[2011:06:165 10:06:163:debug] KnowledgeAgent building resource map
[2011:06:165 10:06:163:info] KnowledegAgent has started listening for
ChangeSet notifications
[2011:06:165 10:06:163:info] KnowledgeAgent created, with configuration:
monitorChangeSetEvents=true scanResources=true scanDirectories=true
newInstance=true
[2011:06:165 10:06:413:info] KnowledgeAgent applying ChangeSet
[2011:06:165 10:06:415:debug] KnowledgeAgent notifier subscribing to
resource=[ClassPathResource path='com/abclegal/rules/resources/venue.pkg']
[2011:06:165 10:06:415:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@5fe0f2f6 to
resource=[ClassPathResource path='com/abclegal/rules/resources/venue.pkg']
[2011:06:165 10:06:416:debug] ResourceChangeScanner subcribing
notifier=org.drools.io.impl.ResourceChangeNotifierImpl@296f25a7 to
resource=[ClassPathResource path='com/abclegal/rules/resources/venue.pkg']
[2011:06:165 10:06:416:debug] KnowledgeAgent rebuilding KnowledgeBase using
ChangeSet
[2011:06:165 10:06:556:exception]
java.lang.RuntimeException: KnowledgeAgent exception while trying to
deserialize KnowledgeDefinitionsPackage
at
org.drools.agent.impl.KnowledgeAgentImpl.createPackageFromResource(KnowledgeAgentImpl.java:664)
at
org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:889)
at
org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:704)
at
org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:584)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:185)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:168)
at
com.abclegal.rules.RulesUtilities.createKnowledgeBaseUsingAgent(RulesUtilities.java:91)
at
com.abclegal.rules.RulesBenchmarks.benchmarkVenueSelection(RulesBenchmarks.java:39)
at com.abclegal.rules.RulesBenchmarks.main(RulesBenchmarks.java:33)
Caused by: java.lang.ClassCastException: [B cannot be cast to
org.drools.rule.DialectRuntimeRegistry
at org.drools.rule.Package.readExternal(Package.java:197)
at
org.drools.definitions.impl.KnowledgePackageImp.readExternal(KnowledgePackageImp.java:115)
at
java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1791)
at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
at
java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at java.util.ArrayList.readObject(ArrayList.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
at
java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at
java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at
org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:205)
at
org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:174)
at
org.drools.agent.impl.KnowledgeAgentImpl.createPackageFromResource(KnowledgeAgentImpl.java:653)
... 8 more
[2011:06:165 10:06:856:debug] KnowledgeAgent obtaining pkg
resource=[ClassPathResource path='com/abclegal/rules/resources/venue.pkg']
[2011:06:165 10:06:856:exception]
java.lang.RuntimeException: KnowledgeAgent exception while trying to
deserialize KnowledgeDefinitionsPackage
at
org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:914)
at
org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:704)
at
org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:584)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:185)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:168)
at
com.abclegal.rules.RulesUtilities.createKnowledgeBaseUsingAgent(RulesUtilities.java:91)
at
com.abclegal.rules.RulesBenchmarks.benchmarkVenueSelection(RulesBenchmarks.java:39)
at com.abclegal.rules.RulesBenchmarks.main(RulesBenchmarks.java:33)
Caused by: java.lang.NullPointerException
at
org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:906)
... 7 more
[2011:06:165 10:06:865:info] KnowledgeAgent new KnowledgeBase now built and
in use
[2011:06:165 10:06:865:debug] KnowledgeAgent finished rebuilding
KnowledgeBase using ChangeSet
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users