Hi,
I want to serialize a StatefulKnowledgeSession in drools (which have rule
and fact)
Actually i know how to serialize a KnowledgeBase.
Here is my code for serialize a KnowledgeBase:
KnowledgeBuilder kBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add( ResourceFactory.newFileResource( "Sample.drl" ),
ResourceType.DRL );
if( kBuilder.hasErrors() ){
for( KnowledgeBuilderError err: kBuilder.getErrors() ){
System.err.println( err.toString() );
}
throw new IllegalStateException( "DRL errors" );
}
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );
OutputStream os = new FileOutputStream( "droolsCompiledFile" );
ObjectOutputStream oos = new ObjectOutputStream( os );
oos.writeObject( kBase );
oos.close();
This work fine, no problem here.
Here is my code for serialize a StatefulKnowledgeSession:
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add( ResourceFactory.newFileResource( "Sample.drl" ),
ResourceType.DRL );
if( kBuilder.hasErrors() ){
for( KnowledgeBuilderError err: kBuilder.getErrors() ){
System.err.println( err.toString() );
}
throw new IllegalStateException( "DRL errors" );
}
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );
try {
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
ksession.insert(message);
Marshaller marshaller = MarshallerFactory.newMarshaller(
ksession.getKnowledgeBase(), new ObjectMarshallingStrategy[]{
MarshallerFactory.newSerializeMarshallingStrategy() } );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectMarshallingStrategy oms =
MarshallerFactory.newIdentityMarshallingStrategy();
marshaller.marshall( baos, ksession );
ObjectOutputStream out = new ObjectOutputStream( baos );
out.writeObject( marshaller );
out.close();
baos.close();
ksession.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
But this didn't work.
I get always the same error:
"java.io.NotSerializableException"
I have try to not implement the "marshall" but this didn't work.
I don't know what I must do. Can someone help me?
Thank.
Best regards,
Clement Pernot
--
View this message in context:
http://drools.46999.n3.nabble.com/Drools-and-serialize-tp3161882p3161882....
Sent from the Drools: User forum mailing list archive at
Nabble.com.