流口水 全局 VaR 的序列化



我使用此代码完全序列化/反序列化流口水 (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;
}

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

我做错了什么?

我相信我在CR1发布后修复了这个问题。当前快照或 CR2 发布时尝试使用。

相关内容

  • 没有找到相关文章

最新更新