Dear all,
I have a Jess application that consists of some rules and some facts, of
which possibly some are shadow facts coupled to Java objects. Before I
fire the rules on these facts I want to perform a dry run and depending
on the outcome perform the run again, but now for real. Altering a
shadow fact might have some side effects in Java, which should not occur
during the dry run.
For this purpose I use two rete engines: real and shadow. Real is
instantiated for some clp file and implements the application including
shadow facts with their associated Java objects. The shadow engine is
for the dry run and is constructed as follows:
shadow = real.createPeer();
Next, I copy all the facts from the real engine to the shadow engine:
for( Iterator i = real.listFacts(); i.hasNext(); )
{ Fact fact = (Fact)(i.next());
shadow.assertFact( new Fact( fact ) );
}
Because I copy only the facts and not the objects associated to the
shadow facts, each shadow fact in the shadow engine is now just an
ordinary fact with no object associated to it. This allows me to reason
about them by running the Jess application without worrying about the
underlying Java program to change. Based on the outcome I do, or do not,
run the program in the real engine that will, in fact, alter the Java
program. I am somehow shadowing the shadow facts.
This works just fine as long as all the objects pertaining to the shadow
facts are instantiated beforehand. That is, no shadow fact is
instantiated in a RHS of any rule (if I do I end up with Java objects
just the same). My first idea was to define a function 'create' as an
alternative for 'definstance' that depending on whether the run is
performed on the shadow or real engine uses assert or definstance to
create a shadow fact. However, calling assert for some template that has
been defined out of a Java class doesn't seem to work, e.g.:
(deftemplate customer (declare (from-class Customer)))
(assert (customer (id 1)))
results in an error: "Message: Not a Comparable:
<Java-Object:jess.SerializablePD>"
Any advice on how to do this properly?
- Nick.
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [email protected]'
in the BODY of a message to [email protected], NOT to the list
(use your own address!) List problems? Notify [email protected].
--------------------------------------------------------------------