简体   繁体   中英

Drools: Cannot deserialize knowledge base

we are using Drools 7.5.0 and Java8.

We have a server application that processes sensor events and has about 1200 sessions. Each session as a parameterized knowledge. When we restart the server we have to recover all sessions which is not as fast as we would like to see it. Therefore try to optimize the recovery process by loading the serialized knowledge bases from the database.

We use the following code to serialize and deserialize a knowledge base:

public static byte[] serializeKieBase(KieBase kieBase) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new DroolsObjectOutputStream(baos);
    oos.writeObject(kieBase);
    oos.close();

    return baos.toByteArray();
}

public static KieBase deserializeKieBase(byte[] serializedBase) throws IOException, ClassNotFoundException {
    ByteArrayInputStream is = new ByteArrayInputStream(serializedBase);
    ObjectInputStream ois = new DroolsObjectInputStream(is);

    return (KieBase) ois.readObject();
}

The events are immutable and have final fields. When we restore the session we get the following exception:

java.lang.RuntimeException: Unknown extractor for com.easierlife.rs.model.Measurement-location

It is thrown in this line of code: https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/core/common/DroolsObjectInputStream.java#L150

What is confusing...

  1. We do use a setter or so in our rules, they are working fine, except this issue.
  2. We have written tests to check if the events are serializable and deserialize and it works fine.
  3. when we add the setter for this field it works fine, but we do not understand why.

Did you use the getter method (getLocation) in the drools syntax? If so, drools serializes and deserializes the field accessor using method accessors

if you change the drools to use the location field directly, it should work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM