Quantcast

Serialization issue with StateKnowledgeSession

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Serialization issue with StateKnowledgeSession

chrisLi
Hi, all

I have a requirement to serialzie a stateful session as a snapshot.

private void serialize(OutputStream out) throws IOException{
                System.out.println("writing");
                DroolsObjectOutputStream droolsOut = new DroolsObjectOutputStream(
                                (OutputStream) out);
                droolsOut.writeLong(counter);
                droolsOut.writeLong(clock.getCurrentTime());
                droolsOut.writeObject(this.knowledgeBase);
               
                Marshaller marshaller = createSerializableMarshaller(this.knowledgeBase);
                marshaller.marshall(droolsOut, this.session);
               
                droolsOut.close();
                System.out.println("written");
        }

I used the above code to serialize the knowledgebase and session into a file simultaneously and it works well. Then I used the following code to attempt to deserialize them, but I failed.

  private void deserialize(InputStream in) throws IOException,
                ClassNotFoundException {
                System.out.println("reading");
                DroolsObjectInputStream droolsIn = new DroolsObjectInputStream(
                                (InputStream) in);
                this.counter = droolsIn.readLong();
                long clockTime = droolsIn.readLong();
                this.knowledgeBase = (KnowledgeBase) droolsIn.readObject();

                Marshaller marshaller = createSerializableMarshaller(this.knowledgeBase);
                this.session = marshaller.unmarshall(droolsIn);
                this.session.getSessionConfiguration().setOption(ClockTypeOption.get("pseudo"));
                this.clock = (PseudoClockScheduler) session.getSessionClock();
                this.clock.setStartupTime(clockTime);
                droolsIn.close();
                System.out.println("read");
        }

In my other codes, I set the clock type of session to "pseudo" with a KnowledgeSessionConfiguration

instance. However, when I serialized it, it's clock type was "realtime". It seems that the some of session's

fields were not serialized.

So, I wonder are there any other ways to serialize a session? I heard about XStream, is it appropriate to

serialize a session. And how?

Or, are there methods allowing me to set the clock type of a session to "pseudo" after deserializing it?

Thank you very much!

 



 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Serialization issue with StateKnowledgeSession

chrisLi
, I looked into Marshaller's API, and find the following method:

StatefulKnowledgeSession unmarshall(InputStream stream, KnowledgeSessionConfiguration config, Environment environment)

which can take a KnowledgeSessionConfiguration parameter. With it we can configure the deserialized stateful session.

Thank you very much.
Loading...