我们正在使用 Drools 6.3和JDK 1.8 版本在我们的计划中实施某些业务规则。我们使用drools中的trait / don概念编写了我们的业务规则之一,如下所示:
declare Patient
@Traitable
end
declare trait PatientTrait end
declare EvalTime
@role( event)
@timestamp (evalTime)
evalTime: Date
end
declare Fired
guid: String
end
declare trait eligible_adult_patient extends com.test.trait.PatientTrait end
rule "External Data eligible_adult_patient"
when
EvalTime($evalTime: evalTime)
$item: Patient(birthDate before [23741d] $evalTime)
then
don($item, eligible_adult_patient.class, true);
end
rule "Rule logic for rule585bf9ed_a1ae_46de_8f5c_65ce605d48b9"
when
not(Fired( guid == "585bf9ed-a1ae-46de-8f5c-65ce605d48b9" ))
patient:Patient()
(exists(eligible_adult_patient())))
then
insert(new Fired("585bf9ed-a1ae-46de-8f5c-65ce605d48b9"));
end
我们使用以下代码生成KIEBase:
KieContainer kieContainer = kieServices.newKieContainer(kieBuilder.getKieModule().getReleaseId());
KieBase kieBase = kieContainer.getKieBase();
生成KIEBase后,我们尝试序列化KIEBase,然后将其作为Blob存储到数据库中。 对于规则的下一个请求,我们尝试从DB检索KIEBase并对其进行反序列化。在此期间,我们得到以下异常:
java.io.InvalidClassException: org.drools.core.reteoo.TraitObjectTypeNode; no valid constructor
at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:150)
at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:790)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1775)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at org.drools.core.reteoo.BetaNode.readExternal(BetaNode.java:219)
at org.drools.core.reteoo.NotNode.readExternal(NotNode.java:63)
at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1842)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1799)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at org.drools.core.reteoo.AbstractTerminalNode.readExternal(AbstractTerminalNode.java:62)
at org.drools.core.reteoo.RuleTerminalNode.readExternal(RuleTerminalNode.java:159)
at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1842)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1799)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1707)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1345)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at java.util.HashMap.readObject(HashMap.java:1396)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1900)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at org.drools.core.reteoo.ReteooBuilder.readExternal(ReteooBuilder.java:405)
at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1842)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1799)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at org.drools.core.impl.KnowledgeBaseImpl.readExternal(KnowledgeBaseImpl.java:500)
at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1842)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1799)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:205)
at org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:161)
at org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:131)
at org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:116)
当我们查看 org.drools.core.reteoo.TraitObjectTypeNode 类时,它没有no-arg构造函数,这会在反序列化时导致上述问题。
所以我的问题是:
针对上述反序列化问题的任何建议解决方案
推荐的方法是将KIEBase仅存储在内存缓存中,还是将KIEBase存储在存储(如DB)/分布式缓存(序列化和反序列化)中也很好
赞赏这方面的任何帮助
Punith