This is exactly right. My only question is why the internal Drools
cache isn't scoped to the RuleBase or the session -- why is it scoped
to the VM...is it a static cache? If time permits I can try to look
into this, not sure how soon I could get to it , though. Is there an
issue in your bug tracking system for this?

On 7/14/07, Mark Proctor <[EMAIL PROTECTED]> wrote:

 I think this is related to  this:
         FooClassLoader loader1 = new FooClassLoader(original);
         Class instance1 = loader1.loadClass( "test.drools.classloader.Foo"
);
         FooClassLoader loader2 = new FooClassLoader(original);
         Class instance2 = loader2.loadClass( "test.drools.classloader.Foo"
);
         System.out.println( instance1.isAssignableFrom( instance2 ) );

 Notice the instances are not assignable. We generate bytecode field
readers, and cache them by string name. Now I imagine the second instance is
using that same cache with the code generated off the first classloader, and
thus providing the error. I'm not sure how to fix this.... expect it's a
point release fix now - patch welcome :)

 Mark

 Aaron Dixon wrote:
Here you go. It's an eclipse project. Only dependencies are the Drools
 4 deps. You'll see clearly in .classpath -- Run "Driver". Let me know
 if you have problems.

 On 7/13/07, Mark Proctor <[EMAIL PROTECTED]> wrote:

can you make an integration test for us? As we'll need to be easily able
 to reproduce this. We'll add it to our code base and fix. We'll probably
 add it as aprt of the MiscTest class:
http://anonsvn.labs.jboss.com/labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java


 Aaron Dixon wrote:
 > I am trying to sequentially perform two rules executions using two
 > different classloaders in the same VM. I create completely new state
 > for each execution, yet I still fail on the second execution. I
 > believe this has to do with some internal static cached state that
 > JBossRules is maintaining. A snippet of the code and exeception are
 > shown in this email.
 >
 >    public void demo() throws Exception {
 >        // Save original classloader
 >        ClassLoader original =
 > Thread.currentThread().getContextClassLoader();
 >
 >        // Create Classloader 1 with parent of original
 >        FooClassLoader loader1 = new FooClassLoader(original);
 >
Thread.currentThread().setContextClassLoader(loader1);
 >        testRules();
 >
 >        // Success so far...
 >
 >        // Create Classloader 2 with parent of original
 >        FooClassLoader loader2 = new FooClassLoader(original);
 >
Thread.currentThread().setContextClassLoader(loader2);
 >        testRules();
 >
 >        // Never make it to here.
 >
 >        // Restore
 >
Thread.currentThread().setContextClassLoader(original);
 >    }
 >
 >    private void testRules() throws Exception {
 >        PackageBuilder builder = new PackageBuilder();
 >        Package pkg = buildPackage(new String[] { "Foo.drl" }, builder);
 >        RuleBase base = RuleBaseFactory.newRuleBase();
 >        base.addPackage(pkg);
 >        StatelessSession session = base.newStatelessSession();
 >        final ClassLoader loader =
 > Thread.currentThread().getContextClassLoader();
 >        Object inst = loader.loadClass("com.foo.Foo").newInstance();
 >        session.execute(new Object[] { inst });
 >    }
 >
 >
 >
 > Exception in thread "main" java.lang.ClassCastException:
 >
adixon.prototype.rules.classloader.demo.copy.FooShadowProxy
 >     at
 >
org.drools.base.adixon.prototype.rules.classloader.demo.copy.Foo$getName.getValue(Unknown
 >
 > Source)
 >     at
 >
org.drools.base.ClassFieldExtractor.getValue(ClassFieldExtractor.java:94)
 >     at
 >
org.drools.base.evaluators.StringFactory$StringEqualEvaluator.evaluate(StringFactory.java:85)
 >
 >     at
 >
org.drools.rule.LiteralRestriction.isAllowed(LiteralRestriction.java:61)
 >     at
 >
org.drools.rule.LiteralConstraint.isAllowed(LiteralConstraint.java:82)
 >     at
org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:121)
 >     at
 >
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:20)
 >
 >     at
 >
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:159)
 >     at
org.drools.reteoo.Rete.assertObject(Rete.java:175)
 >     at
 >
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)
 >     at
 >
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:70)
 >
 >     at
 >
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:772)
 >
 >     at
 >
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:584)
 >
 >     at
 >
org.drools.reteoo.ReteooStatelessSession.execute(ReteooStatelessSession.java:63)
 >
 >     at
 >
adixon.prototype.rules.classloader.demo.copy.Driver.testRules(Driver.java:47)
 >
 >     at
 >
adixon.prototype.rules.classloader.demo.copy.Driver.go(Driver.java:33)
 >     at
 >
adixon.prototype.rules.classloader.demo.copy.Driver.main(Driver.java:17)
 > _______________________________________________
 > rules-dev mailing list
 > [email protected]
 > https://lists.jboss.org/mailman/listinfo/rules-dev
 >

 _______________________________________________
 rules-dev mailing list
 [email protected]
 https://lists.jboss.org/mailman/listinfo/rules-dev

 ________________________________

_______________________________________________
rules-dev mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-dev



_______________________________________________
rules-dev mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-dev


_______________________________________________
rules-dev mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-dev

Reply via email to