Drools:编译规则(或加载编译的规则)失败,JamVM中存在模糊的异常

时间:2011-11-23 16:21:07

标签: drools jamvm

我正在开发一个框架,作为其功能之一,它使机器人能够使用基于规则的系统。我们从Jess开始作为RBS,现在想要实现drools(使用Drools 5.2.0 final),它适用于在OpenJDK 6上运行的开发机器。

我们的机器人控制器运行ARM Linux和JamVM,之前是1.4.3,但我最近编译了1.5.4,因为它缺少了drools所需的类。失败之后,我使用与为控制器编译它时相同的配置在一台虚拟机中安装了JamVM,并且在失败时也出现了相同的例外情况。

一项小小的研究表明Drools + JamVM有bug报告,但这也意味着它通常 工作。


使用以下代码运行带有预编译规则的框架...

kBase = KnowledgeBaseFactory.newKnowledgeBase();

ObjectInputStream in;
Collection<KnowledgePackage> kpkgs;
try {
    in = new ObjectInputStream(Thread.currentThread().getContextClassLoader().getResourceAsStream(
            packageFile));
    kpkgs = (Collection<KnowledgePackage>) in.readObject();
    in.close();
} catch(IOException e) {
    throw new DisboticsException("Couldn't read drools knowledge package file!", e);
} catch(ClassNotFoundException e) {
    throw new DisboticsException("Drools knowledge package file didn't contain expected instance.", e);
}

kBase.addKnowledgePackages(kpkgs);
kSession = kBase.newStatefulKnowledgeSession();

......我遇到了这个例外:

java.lang.UnsupportedOperationException
   at java.util.AbstractList.add(AbstractList.java:131)
   at java.util.AbstractList.add(AbstractList.java:152)
   at org.drools.rule.JavaDialectRuntimeData.write(JavaDialectRuntimeData.java:383)
   at org.drools.rule.JavaDialectRuntimeData.merge(JavaDialectRuntimeData.java:266)
   at org.drools.rule.JavaDialectRuntimeData.clone(JavaDialectRuntimeData.java:251)
   at org.drools.rule.DialectRuntimeRegistry.merge(DialectRuntimeRegistry.java:110)
   at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:496)
   at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:427)
   at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:149)
   at disbotics.core.config.DroolsRulesPlugin.initialize(DroolsRulesPlugin.java:76)
   at disbotics.core.common.DisboticsCore.startFramework(DisboticsCore.java:109)
   at disbotics.core.common.DisboticsCore.main(DisboticsCore.java:56)
Exception in thread "main" org.drools.RuntimeDroolsException: java.lang.UnsupportedOperationException
   at org.drools.rule.JavaDialectRuntimeData.write(JavaDialectRuntimeData.java:386)
   at org.drools.rule.JavaDialectRuntimeData.merge(JavaDialectRuntimeData.java:266)
   at org.drools.rule.JavaDialectRuntimeData.clone(JavaDialectRuntimeData.java:251)
   at org.drools.rule.DialectRuntimeRegistry.merge(DialectRuntimeRegistry.java:110)
   at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:496)
   at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:427)
   at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:149)
   at disbotics.core.config.DroolsRulesPlugin.initialize(DroolsRulesPlugin.java:76)
   at disbotics.core.common.DisboticsCore.startFramework(DisboticsCore.java:109)
   at disbotics.core.common.DisboticsCore.main(DisboticsCore.java:56)
Caused by: java.lang.UnsupportedOperationException
   at java.util.AbstractList.add(AbstractList.java:131)
   at java.util.AbstractList.add(AbstractList.java:152)
   at org.drools.rule.JavaDialectRuntimeData.write(JavaDialectRuntimeData.java:383)
   ...9 more

...在OpenJDK中有效。奇怪的是,事实证明JavaDialectRuntimeData中的列表是通过Collections.emptyList()获得的,并且永远不会再次更改(或者eclipse建议......)。


使用此代码运行裸.drl个文件时:

Properties props = new Properties();
props.put("drools.dialect.java.compiler", "JANINO");

KnowledgeBuilderConfiguration kbConfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(props,
        (ClassLoader[]) null);
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbConfig);

kBuilder.add(ResourceFactory.newClassPathResource("disbotics/core/rules/drools/function.drl",
        DroolsRulesPlugin.class), ResourceType.DRL);
kBuilder.add(ResourceFactory.newClassPathResource(rulesFile, DroolsRulesPlugin.class), ResourceType.DRL);

if(kBuilder.hasErrors()) {
    String errorMessage = "";
    for(KnowledgeBuilderError error:kBuilder.getErrors())
        errorMessage = errorMessage + error.getMessage() + "\n";
    throw new DisboticsException(errorMessage);
}

kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.addKnowledgePackages(kBuilder.getKnowledgePackages());
kSession = kBase.newStatefulKnowledgeSession();

...我从规则编译器中得到这些(意外的)异常:

Exception in thread "main" disbotics.core.common.DisboticsException: Line 2:8 unexpected exception at input '"mvel"'. Exception: java.lang.UnsupportedOperationException. Stack trace:
 java.lang.UnsupportedOperationException
   at java.util.AbstractList.add(AbstractList.java:131)
   at java.util.AbstractList.add(AbstractList.java:152)
   at org.drools.lang.descr.PackageDescr.addAttribute(PackageDescr.java:138)
   at org.drools.lang.api.impl.PackageDescrBuilderImpl.attribute(PackageDescrBuilderImpl.java:93)
   at org.drools.lang.ParserHelper.start(ParserHelper.java:684)
   at org.drools.lang.DRLParser.stringAttribute(DRLParser.java:1289)
   at org.drools.lang.DRLParser.attribute(DRLParser.java:1062)
   at org.drools.lang.DRLParser.statement(DRLParser.java:276)
   at org.drools.lang.DRLParser.compilationUnit(DRLParser.java:155)
   at org.drools.compiler.DrlParser.compile(DrlParser.java:225)
   at org.drools.compiler.DrlParser.parse(DrlParser.java:136)
   at org.drools.compiler.DrlParser.parse(DrlParser.java:141)
   at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:352)
   at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:538)
   at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
   at disbotics.core.config.DroolsRulesPlugin.initialize(DroolsRulesPlugin.java:55)
   at disbotics.core.common.DisboticsCore.startFramework(DisboticsCore.java:109)
   at disbotics.core.common.DisboticsCore.main(DisboticsCore.java:56)

[ERR 107] Line 2:8 mismatched input '"mvel"' expecting one of the following tokens: '[package, import, global, declare, function, rule, query]'.
Line 4:0 unexpected exception at input 'global'. Exception: java.util.EmptyStackException. Stack trace:
 java.util.EmptyStackException
   at java.util.Stack.pop(Stack.java:109)
   at org.drools.lang.ParserHelper.popParaphrases(ParserHelper.java:421)
   at org.drools.lang.ParserHelper.end(ParserHelper.java:732)
   at org.drools.lang.DRLParser.globalStatement(DRLParser.java:401)
   at org.drools.lang.DRLParser.statement(DRLParser.java:261)
   at org.drools.lang.DRLParser.compilationUnit(DRLParser.java:155)
   at org.drools.compiler.DrlParser.compile(DrlParser.java:225)
   at org.drools.compiler.DrlParser.parse(DrlParser.java:136)
   at org.drools.compiler.DrlParser.parse(DrlParser.java:141)
   at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:352)
   at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:538)
   at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
   at disbotics.core.config.DroolsRulesPlugin.initialize(DroolsRulesPlugin.java:55)
   at disbotics.core.common.DisboticsCore.startFramework(DisboticsCore.java:109)
   at disbotics.core.common.DisboticsCore.main(DisboticsCore.java:56)

Parser returned a null Package
Line 2:8 unexpected exception at input '"java"'. Exception: java.lang.UnsupportedOperationException. Stack trace:
 java.lang.UnsupportedOperationException
   at java.util.AbstractList.add(AbstractList.java:131)
   at java.util.AbstractList.add(AbstractList.java:152)
   at org.drools.lang.descr.PackageDescr.addAttribute(PackageDescr.java:138)
   at org.drools.lang.api.impl.PackageDescrBuilderImpl.attribute(PackageDescrBuilderImpl.java:93)
   at org.drools.lang.ParserHelper.start(ParserHelper.java:684)
   at org.drools.lang.DRLParser.stringAttribute(DRLParser.java:1289)
   at org.drools.lang.DRLParser.attribute(DRLParser.java:1062)
   at org.drools.lang.DRLParser.statement(DRLParser.java:276)
   at org.drools.lang.DRLParser.compilationUnit(DRLParser.java:155)
   at org.drools.compiler.DrlParser.compile(DrlParser.java:225)
   at org.drools.compiler.DrlParser.parse(DrlParser.java:136)
   at org.drools.compiler.DrlParser.parse(DrlParser.java:141)
   at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:352)
   at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:538)
   at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
   at disbotics.core.config.DroolsRulesPlugin.initialize(DroolsRulesPlugin.java:57)
   at disbotics.core.common.DisboticsCore.startFramework(DisboticsCore.java:109)
   at disbotics.core.common.DisboticsCore.main(DisboticsCore.java:56)

[ERR 107] Line 2:8 mismatched input '"java"' expecting one of the following tokens: '[package, import, global, declare, function, rule, query]'.
Line 4:0 unexpected exception at input 'import'. Exception: java.util.EmptyStackException. Stack trace:
 java.util.EmptyStackException
   at java.util.Stack.pop(Stack.java:109)
   at org.drools.lang.ParserHelper.popParaphrases(ParserHelper.java:421)
   at org.drools.lang.ParserHelper.end(ParserHelper.java:732)
   at org.drools.lang.DRLParser.importStatement(DRLParser.java:349)
   at org.drools.lang.DRLParser.statement(DRLParser.java:258)
   at org.drools.lang.DRLParser.compilationUnit(DRLParser.java:155)
   at org.drools.compiler.DrlParser.compile(DrlParser.java:225)
   at org.drools.compiler.DrlParser.parse(DrlParser.java:136)
   at org.drools.compiler.DrlParser.parse(DrlParser.java:141)
   at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:352)
   at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:538)
   at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
   at disbotics.core.config.DroolsRulesPlugin.initialize(DroolsRulesPlugin.java:57)
   at disbotics.core.common.DisboticsCore.startFramework(DisboticsCore.java:109)
   at disbotics.core.common.DisboticsCore.main(DisboticsCore.java:56)

Line 6:0 unexpected exception at input 'rule'. Exception: java.util.EmptyStackException. Stack trace:
 java.util.EmptyStackException
   at java.util.Stack.pop(Stack.java:109)
   at org.drools.lang.ParserHelper.popParaphrases(ParserHelper.java:421)
   at org.drools.lang.ParserHelper.end(ParserHelper.java:732)
   at org.drools.lang.DRLParser.rule(DRLParser.java:886)
   at org.drools.lang.DRLParser.statement(DRLParser.java:267)
   at org.drools.lang.DRLParser.compilationUnit(DRLParser.java:155)
   at org.drools.compiler.DrlParser.compile(DrlParser.java:225)
   at org.drools.compiler.DrlParser.parse(DrlParser.java:136)
   at org.drools.compiler.DrlParser.parse(DrlParser.java:141)
   at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:352)
   at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:538)
   at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
   at disbotics.core.config.DroolsRulesPlugin.initialize(DroolsRulesPlugin.java:57)
   at disbotics.core.common.DisboticsCore.startFramework(DisboticsCore.java:109)
   at disbotics.core.common.DisboticsCore.main(DisboticsCore.java:56)

Parser returned a null Package

   at disbotics.core.config.DroolsRulesPlugin.initialize(DroolsRulesPlugin.java:63)
   at disbotics.core.common.DisboticsCore.startFramework(DisboticsCore.java:109)
   at disbotics.core.common.DisboticsCore.main(DisboticsCore.java:56)

再次,编译规则在OpenJDK中运行得很好。我们正在使用Janino,它在类路径上被正确引用(运行时使用的类路径由Maven构建创建,因此包含drools / janino /其他任何引用的所有jar)


有谁知道这里发生了什么和/或如何让Drools与JamVM合作?

1 个答案:

答案 0 :(得分:2)

您是否正在使用OpenJDK 1.6编译知识包?然后尝试用1.5.4加载它?您应该尝试使用1.5.4编译原始包,看看是否有相同的错误。

对于堆栈跟踪,看起来您正试图将某些内容添加到不可修改的列表中吗?

基本上你在这里得到例外:kBase.addKnowledgePackages(kpkgs); 正确?