Has anybody an idea
what’s these problems? I didn’t find any test cases, are there any test cases
for serializing the PKG files? What am I doing wrong?
Von: rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] Im Auftrag von Bernd Rücker
Gesendet: Dienstag, 1. September 2009 17:26
An: rules-users@lists.jboss.org
Betreff: [rules-users] WG: Serialization of packages: InvalidClassException
/ serialVersionUID
The exception of the
KnowledgePackage serialization (by the way, this is described in the docs, that
you can serialize the KnowledgePackages!):
/home/bruecker/workspace/1/iKS2/iks_drools_rules/drools-rules.pkg
Exception in thread "main"
java.io.NotSerializableException:
org.drools.definitions.impl.KnowledgePackageImp
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at
org.drools.util.DroolsStreamUtils.streamOut(DroolsStreamUtils.java:79)
at
org.drools.util.DroolsStreamUtils.streamOut(DroolsStreamUtils.java:61)
So this doesn’t work
either
(http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-expert/html_single/index.html#d0e992):
3.2.4. Building
and Deployment in Separate Processes
Both
the KnowledgeBase and
the KnowledgePackage are
units of deployment and serializable. This means you can have one machine do
any necessary building, requiring drools-compiler.jar, and have
another machine deploy and execute everything, needing only drools-core.jar.
Although
serialization is standard Java, we present an example of how one machine might
write out the deployment unit and how another machine might read in and use
that deployment unit.
Example 3.15. Writing
the KnowledgePackage to an OutputStream
ObjectOutputStream
out = new ObjectOutputStream( new FileOutputStream( fileName ) );
out.writeObject(
kpkgs );
out.close();
Example 3.16. Reading
the KnowledgePackage from an InputStream
ObjectInputStream
in = new ObjectInputStream( new FileInputStream( fileName ) );
//
The input stream might contain an individual
//
package or a collection.
@SuppressWarnings(
"unchecked" )
Collection<KnowledgePackage>
kpkgs =
()in.readObject( Collection<KnowledgePackage> );
in.close();
KnowledgeBase
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(
kpkgs );
The KnowledgeBase is
also serializable and some people may prefer to build and then store the KnowledgeBase
itself, instead of the Knowledge Packages.
Drools
Guvnor, our server side management system, uses this deployment approach. After
Guvnor has compiled and published serialized Knowledge Packages on a URL,
Drools can use the URL resource type to load them.
Von: Bernd Rücker
[mailto:bernd.ruecker@camunda.com]
Gesendet: Dienstag, 1. September 2009 17:21
An: 'rules-users@lists.jboss.org'
Betreff: Serialization of packages: InvalidClassException /
serialVersionUID
Hi!
I really struggled some time with
serialization issues: I want to create a pkg and package that with the jar.
>From there I want to read it during runtime.
Easy I thought. Drools 5 way should be to
serialize the KnowledgeBase, right? At least, this is what the AntTask does.
If I try to serialize the KnowledgePackage
I get an excpetion anyway:
Okay. Back to the KnowledgeBase. Serialized
with Drools 5.0.0.M4 and try to read it with 5.0.0.M5:
Caused by:
java.io.InvalidClassException:
org.drools.impl.KnowledgeBaseImpl;
local class incompatible: stream
classdesc serialVersionUID = -4540376767025107954,
local class serialVersionUID
= -3186110098262381425
So it seems Drools Packages are NOT
compatible between minor versions? This would be a disaster for deployment. Or
do I serialize the wrong thing? Unfortunately I didn’t find anything in the
docs about it.
Then I tried to do it the “old” Drools 4
way and serialize Package objects, but same problem with a different
serialVersionUID!
Why do these important classes don’t have a
serialVersionUID? Or how should that be loaded? Must be a big issue with
Govner, so I think there must be a solution already?
Thanks for any help!
Cheers
Bernd