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 に答える