[jboss-svn-commits] JBL Code SVN: r21099 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: common and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 17 23:02:43 EDT 2008
Author: mark.proctor at jboss.com
Date: 2008-07-17 23:02:42 -0400 (Thu, 17 Jul 2008)
New Revision: 21099
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldReader.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
Log:
JBRULES-1684 Package merging is incorrect for dialects
-field Readers are generated against old class for internal fact models.
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldReader.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldReader.java 2008-07-18 00:41:06 UTC (rev 21098)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldReader.java 2008-07-18 03:02:42 UTC (rev 21099)
@@ -80,22 +80,26 @@
public void writeExternal(ObjectOutput out) throws IOException {
// Call even if there is no default serializable fields.
- out.writeObject( clazz );
+ out.writeObject( clazz.getName() );
out.writeObject( fieldName );
}
public void readExternal(final ObjectInput is) throws ClassNotFoundException,
IOException {
- clazz = (Class< ? >) is.readObject();
+ String clsName = (String) is.readObject();
fieldName = (String) is.readObject();
if ( is instanceof DroolsObjectInput ) {
DroolsObjectInput droolsInput = (DroolsObjectInput) is;
+ this.clazz = droolsInput.getClassLoader().loadClass( clsName );
reader = droolsInput.getExtractorFactory().getReader( clazz,
fieldName,
droolsInput.getClassLoader() );
- } else reader = ClassFieldAccessorCache.getInstance().getReader( clazz,
+ } else {
+ this.clazz = getClass().getClassLoader() .loadClass( clsName );
+ reader = ClassFieldAccessorCache.getInstance().getReader( clazz,
fieldName,
getClass().getClassLoader() );
+ }
}
private void init(final ClassLoader classLoader,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-07-18 00:41:06 UTC (rev 21098)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-07-18 03:02:42 UTC (rev 21099)
@@ -311,14 +311,14 @@
this.removeEventListener( (RuleBaseEventListener) it.next() );
}
}
-
+
public StatefulSession readStatefulSession(final InputStream stream,
Marshaller marshaller) throws IOException,
ClassNotFoundException {
- return readStatefulSession( stream,
- true,
- marshaller );
- }
+ return readStatefulSession( stream,
+ true,
+ marshaller );
+ }
/**
* @see RuleBase
@@ -434,19 +434,20 @@
// create a new package, use the same parent classloader as the incoming new package
pkg = new Package( newPkg.getName(),
new MapBackedClassLoader( newPkg.getPackageScopeClassLoader().getParent() ) );
- //newPkg.getPackageScopeClassLoader() );
+ //newPkg.getPackageScopeClassLoader() );
pkgs.put( pkg.getName(),
pkg );
// add the dialect registry composite classloader (which uses the above classloader as it's parent)
this.packageClassLoader.addClassLoader( pkg.getDialectRuntimeRegistry().getClassLoader() );
- }
-// else {
-//
-// this.packageClassLoader.addClassLoader( newPkg.getDialectRuntimeRegistry().getClassLoader() );
-// }
-
+ }
+ // else {
+ //
+ // this.packageClassLoader.addClassLoader( newPkg.getDialectRuntimeRegistry().getClassLoader() );
+ // }
+
// now merge the new package into the existing one
- mergePackage( pkg, newPkg );
+ mergePackage( pkg,
+ newPkg );
// Add the type declarations to the RuleBase
if ( newPkg.getTypeDeclarations() != null ) {
@@ -459,7 +460,7 @@
type );
}
}
- }
+ }
// add the rules to the RuleBase
final Rule[] rules = newPkg.getRules();
@@ -467,7 +468,7 @@
addRule( newPkg,
rules[i] );
}
-
+
// add the flows to the RuleBase
if ( newPkg.getRuleFlows() != null ) {
final Map flows = newPkg.getRuleFlows();
@@ -495,7 +496,7 @@
* and the actual Rule objects into the package).
*/
private void mergePackage(final Package pkg,
- final Package newPkg) {
+ final Package newPkg) {
// Merge imports
final Map<String, ImportDeclaration> imports = pkg.getImports();
imports.putAll( newPkg.getImports() );
@@ -513,11 +514,12 @@
pkg.addGlobal( identifier,
type );
// this isn't a package merge, it's adding to the rulebase, but I've put it here for convienience
- this.globals.put( identifier, type );
- }
+ this.globals.put( identifier,
+ type );
+ }
}
}
-
+
// merge the type declarations
if ( newPkg.getTypeDeclarations() != null ) {
// add type declarations
@@ -528,11 +530,11 @@
pkg.addTypeDeclaration( type );
}
}
- }
-
+ }
+
// merge the contents of the MapBackedClassloader, that is the root of the dialect registry's composite classloader.
- pkg.getPackageScopeClassLoader().getStore().putAll( newPkg.getPackageScopeClassLoader().getStore() );
-
+ pkg.getPackageScopeClassLoader().getStore().putAll( newPkg.getPackageScopeClassLoader().getStore() );
+
//Merge rules into the RuleBase package
//as this is needed for individual rule removal later on
final Rule[] newRules = newPkg.getRules();
@@ -546,8 +548,8 @@
}
pkg.addRule( newRule );
- }
-
+ }
+
//Merge The Rule Flows
if ( newPkg.getRuleFlows() != null ) {
final Map flows = newPkg.getRuleFlows();
@@ -555,7 +557,7 @@
final Process flow = (Process) iter.next();
pkg.addProcess( flow );
}
- }
+ }
pkg.getDialectRuntimeRegistry().merge( newPkg.getDialectRuntimeRegistry() );
@@ -578,7 +580,7 @@
}
public synchronized void addRule(final Package pkg,
- final Rule rule) throws InvalidPatternException {
+ final Rule rule) throws InvalidPatternException {
this.eventSupport.fireBeforeRuleAdded( pkg,
rule );
if ( !rule.isValid() ) {
@@ -692,7 +694,7 @@
}
public void removeRule(final Package pkg,
- final Rule rule) {
+ final Rule rule) {
this.eventSupport.fireBeforeRuleRemoved( pkg,
rule );
removeRule( rule );
@@ -818,11 +820,11 @@
}
return false;
}
-
- public FactType getFactType( final String name ) {
+
+ public FactType getFactType(final String name) {
for ( Package pkg : this.pkgs.values() ) {
FactType type = pkg.getFactType( name );
- if( type != null ) {
+ if ( type != null ) {
return type;
}
}
@@ -832,7 +834,7 @@
public static class ReloadPackageCompilationData
implements
RuleBaseAction {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
private Set<DialectRuntimeRegistry> set;
public void readExternal(ObjectInput in) throws IOException,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java 2008-07-18 00:41:06 UTC (rev 21098)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java 2008-07-18 03:02:42 UTC (rev 21099)
@@ -16,6 +16,12 @@
package org.drools.reteoo.builder;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -23,6 +29,8 @@
import org.drools.RuntimeDroolsException;
import org.drools.base.ClassObjectType;
import org.drools.base.DroolsQuery;
+import org.drools.common.DroolsObjectInputStream;
+import org.drools.common.DroolsObjectOutputStream;
import org.drools.common.InstanceNotEqualsConstraint;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.AlphaNode;
@@ -202,6 +210,7 @@
boolean objectMemory = context.isObjectTypeNodeMemoryEnabled();
boolean alphaMemory = context.isAlphaMemoryAllowed();
+ ObjectType objectType = pattern.getObjectType();
if ( pattern.getObjectType() instanceof ClassObjectType ) {
// Is this the query node, if so we don't want any memory
if ( DroolsQuery.class == ((ClassObjectType) pattern.getObjectType()).getClassType() ) {
@@ -210,6 +219,31 @@
context.setTerminalNodeMemoryEnabled( false );
context.setAlphaNodeMemoryAllowed( false );
}
+
+ Class cls = ((ClassObjectType)pattern.getObjectType()).getClassType();
+ try {
+ Class rbCls = context.getRuleBase().getCompositePackageClassLoader().loadClass( cls.getName() );
+ if ( cls != rbCls ) {
+ // the class has been redefined as part of the merge, us the redefined version
+ objectType = new ClassObjectType( rbCls );
+
+ // @FIXME ok this is just plain nasty, but I want something to work for now.
+ // we now need to serialize the alpha constraints, to force the fields readers to be regenerated (shitty classloader issues)
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DroolsObjectOutputStream stream = new DroolsObjectOutputStream( baos );
+ List list = new ArrayList( alphaConstraints.size() );
+ for ( final Iterator it = alphaConstraints.iterator(); it.hasNext(); ) {
+ AlphaNodeFieldConstraint constraint = (AlphaNodeFieldConstraint) it.next();
+ constraint.writeExternal( stream );
+ constraint = constraint.getClass().newInstance();
+ constraint.readExternal( new DroolsObjectInputStream( new ByteArrayInputStream( baos.toByteArray() ), context.getRuleBase().getCompositePackageClassLoader() ) );
+ list.add( constraint );
+ }
+ alphaConstraints = list;
+ }
+ } catch ( Exception e ) {
+ throw new RuntimeDroolsException( "Unable to Attach ObjectTypeNode as class cannot be found '" + cls.getName() + "'", e );
+ }
}
context.setObjectSource( (ObjectSource) utils.attachNode( context,
@@ -220,7 +254,7 @@
context.setObjectSource( (ObjectSource) utils.attachNode( context,
new ObjectTypeNode( context.getNextId(),
(EntryPointNode) context.getObjectSource(),
- pattern.getObjectType(),
+ objectType,
context ) ) );
for ( final Iterator it = alphaConstraints.iterator(); it.hasNext(); ) {
More information about the jboss-svn-commits
mailing list