[rules-users] Serialization issue with StateKnowledgeSession

chrisLi shengtao0077 at 163.com
Thu Jul 12 20:57:01 EDT 2012


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!

  



 


--
View this message in context: http://drools.46999.n3.nabble.com/Serialization-issue-with-StateKnowledgeSession-tp4018643.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list