我使用此代码完全序列化/反序列化drools(5.4.0.CR1)statefull会话对象:
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;
}
它工作正常,唯一的问题是会话的全局变量丢失。
我做错了什么?
答案 0 :(得分:0)
我相信我在CR1发布后修复了这个问题。在发布时尝试当前快照或CR2。