}
public StatefulSession newStatefulSession(java.io.InputStream stream,
boolean keepReference,
SessionConfiguration conf) {
StatefulSession session = null;
try {
readLock();
try {
// first unwrap the byte[]
ObjectInputStream ois = new ObjectInputStream( stream );
// standard serialisation would have written the statateful session instance info to the stream first
// so we read it, but we don't need it, so just ignore.
ReteooStatefulSession rsession = (ReteooStatefulSession) ois.readObject();
// now unmarshall that byte[]
ByteArrayInputStream bais = new ByteArrayInputStream( rsession.bytes );
Marshaller marshaller = MarshallerFactory.newMarshaller( new KnowledgeBaseImpl( this ), new ObjectMarshallingStrategy[] { MarshallerFactory.newSerializeMarshallingStrategy() } );
Environment environment = EnvironmentFactory.newEnvironment();
KieSession ksession = marshaller.unmarshall( bais,
conf,
environment );
session = (StatefulSession) ((StatefulKnowledgeSessionImpl) ksession).session;
if ( keepReference ) {
super.addStatefulSession( session );
for (Object listener : session.getRuleBaseUpdateListeners()) {
addEventListener((RuleBaseEventListener) listener);
}
}
bais.close();