0

我使用此代码来完全序列化/反序列化 drools (5.4.0.CR1) 状态会话对象:

private static void writeObject(ObjectOutputStream out, KnowledgeBase knowledgeBase, StatefulKnowledgeSession session) throws IOException
{
    // out.defaultWriteObject();
    DroolsObjectOutputStream droolsOut = new DroolsObjectOutputStream(out);
    droolsOut.writeObject(knowledgeBase);
    Marshaller marshaller = createSerializableMarshaller(knowledgeBase);
    marshaller.marshall(droolsOut, session);
}

private static Marshaller createSerializableMarshaller(KnowledgeBase knowledgeBase)
{
    ObjectMarshallingStrategyAcceptor acceptor = MarshallerFactory.newClassFilterAcceptor(new String[] { "*.*" });
    ObjectMarshallingStrategy strategy = MarshallerFactory.newSerializeMarshallingStrategy(acceptor);
    Marshaller marshaller = MarshallerFactory.newMarshaller(knowledgeBase, new ObjectMarshallingStrategy[] { strategy });
    return marshaller;
}

private static StatefulKnowledgeSession readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
    // in.defaultReadObject();
    DroolsObjectInputStream droolsIn = new DroolsObjectInputStream(in);
    KnowledgeBase knowledgeBase = (KnowledgeBase) droolsIn.readObject();
    Marshaller marshaller = createSerializableMarshaller(knowledgeBase);
    StatefulKnowledgeSession statefulSession = marshaller.unmarshall(droolsIn);

    return statefulSession;
}

它工作正常,唯一的问题是会话的全局变量丢失了。

我究竟做错了什么?

4

1 回答 1

0

我相信我在 CR1 发布后解决了这个问题。在发布时尝试当前快照或 CR2。

于 2012-04-17T20:29:50.240 回答