Solved. See my follow up to "trouble dynamically changing packages of a
rulebase".
cb
Charles Binford wrote:
This is related to yesterday's post titled "trouble
dynamically
changing packages of a rulebase".
I decided to try and reduce the problem down as much as possible so I
started with "Hello World" program automatically created with Eclipse
when you create a new Drools Project.
I modified the program to do the following additional work:
1. unload the pkg
2. add a second pkg to the same rulebase
* (new rule set is same, except is uses the string "So long"
instead of "Goodbye")
3. - create new session
4. - add new facts to the new session
* (this time I use the word "Welcome" instead of "Hello")
5. - fireall rules
When I run within Eclipse, I get:
Hello World
Goodbye cruel world
Goodbye cruel world
Welcome World
So long cruel world
Notice that the Goodbye line comes out twice. The second time is
printed when I single step (in the eclipse debugger) over the line
ruleBase.addPackage( pkg );
in step 2 above.
When I run from the command line I don't get the extra line ("javadr"
is just a one line shell script that has all of the drools classpath
stuff specified).
javadr com/sample/DroolsTest
Hello World
Goodbye cruel world
Welcome World
So long cruel world
I don't know of this is related to my real issue (see yesterday's
post) or not. The similarity is that BOTH BEHAVE DIFFERENTLY when run
under Eclipse vs. command line.
Here is the portion of the src that shows what I added/modified....
// Now try second set of rules
readRule2("/Sample2.drl", "com.sample");
workingMemory = ruleBase.newStatefulSession();
message.setMessage( "Welcome World" );
message.setStatus( Message.HELLO );
workingMemory.insert( message );
workingMemory.fireAllRules();
private static RuleBase readRule2(String file, String remPkgName)
throws Exception {
//read in the source
Reader source = new InputStreamReader(
DroolsTest.class.getResourceAsStream( file ) );
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( source );
Package pkg = builder.getPackage();
if (remPkgName != null) {
ruleBase.removePackage(remPkgName);
}
ruleBase.addPackage( pkg );
return ruleBase;
}
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users