[jboss-svn-commits] JBL Code SVN: r14165 - 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
Sun Aug 12 23:29:33 EDT 2007


Author: mark.proctor at jboss.com
Date: 2007-08-12 23:29:33 -0400 (Sun, 12 Aug 2007)
New Revision: 14165

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBase.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java
Log:
JBRULES-1056 Performance of RuleBase().addPackage(.) goes down on sub sequent instances of RuleBase with large number of packages.
-I have rewritten the system so that the PackageCompilationData only marks itself as dirty and the RuleBase now handles reload() on the execution of a WorkingMemoryAction.

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBase.java	2007-08-13 01:16:09 UTC (rev 14164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBase.java	2007-08-13 03:29:33 UTC (rev 14165)
@@ -39,7 +39,7 @@
     Serializable {
 
     public static final int RETEOO = 1;
-    
+
     StatelessSession newStatelessSession();
 
     /**
@@ -93,7 +93,7 @@
      * @return A serialised initialized <code>WorkingMemory</code>.
      */
     StatefulSession newStatefulSession(InputStream stream) throws IOException,
-                                                      ClassNotFoundException;
+                                                          ClassNotFoundException;
 
     /**
      * RuleBases handle the returning of a Serialized WorkingMemory
@@ -112,11 +112,11 @@
      * @return A serialised initialized <code>WorkingMemory</code>.
      */
     StatefulSession newStatefulSession(InputStream stream,
-                                   boolean keepReference) throws IOException,
-                                                         ClassNotFoundException;
+                                       boolean keepReference) throws IOException,
+                                                             ClassNotFoundException;
 
     Package[] getPackages();
-    
+
     Package getPackage(String name);
 
     void addPackage(Package pkg) throws Exception;
@@ -126,5 +126,10 @@
     void removeRule(String packageName,
                     String ruleName);
 
+    void removeFunction(String packageName,
+                        String functionName);
+
+    void removeProcess(String id);
+
     public StatefulSession[] getStatefulSessions();
 }

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	2007-08-13 01:16:09 UTC (rev 14164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java	2007-08-13 03:29:33 UTC (rev 14165)
@@ -24,6 +24,7 @@
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -84,6 +85,8 @@
     protected FactHandleFactory                     factHandleFactory;
 
     protected Map                                   globals;
+    
+    private ReloadPackageCompilationData reloadPackageCompilationData = null;
 
     /**
      * WeakHashMap to keep references of WorkingMemories but allow them to be
@@ -185,12 +188,12 @@
             this.packageClassLoader = new CompositePackageClassLoader( Thread.currentThread().getContextClassLoader() );
             this.classLoader = new MapBackedClassLoader( Thread.currentThread().getContextClassLoader() );
         }
-            
+
         this.packageClassLoader.addClassLoader( this.classLoader );
-        
+
         for ( final Iterator it = this.pkgs.values().iterator(); it.hasNext(); ) {
             this.packageClassLoader.addClassLoader( ((Package) it.next()).getPackageCompilationData().getClassLoader() );
-        }       
+        }
 
         // Return the rules stored as a byte[]
         final byte[] bytes = (byte[]) stream.readObject();
@@ -254,8 +257,8 @@
 
     public Package[] getPackages() {
         return (Package[]) this.pkgs.values().toArray( new Package[this.pkgs.size()] );
-    }   
-    
+    }
+
     public Map getPackagesMap() {
         return this.pkgs;
     }
@@ -381,11 +384,17 @@
         }
 
         // Merge imports
-        // @TODO we should check for duplicates
         imports.addAll( newPkg.getImports() );
 
         // Add invokers
         compilationData.putAllInvokers( newCompilationData.getInvokers() );
+        
+        if ( compilationData.isDirty() ) {
+            if ( this.reloadPackageCompilationData == null ) {
+                this.reloadPackageCompilationData = new ReloadPackageCompilationData();
+            }
+            this.reloadPackageCompilationData.addPackageCompilationData( compilationData );            
+        }
 
         // Add globals
         for ( final Iterator it = newPkg.getGlobals().keySet().iterator(); it.hasNext(); ) {
@@ -407,13 +416,13 @@
                 pkg.addRule( newRule );
             }
         }
-        
+
         //and now the rule flows
         if ( newPkg.getRuleFlows() != Collections.EMPTY_MAP ) {
             Map flows = newPkg.getRuleFlows();
             for ( Iterator iter = flows.values().iterator(); iter.hasNext(); ) {
                 Process flow = (Process) iter.next();
-                pkg.addRuleFlow(flow);
+                pkg.addRuleFlow( flow );
             }
         }
     }
@@ -469,7 +478,7 @@
                 //and now the rule flows
                 Map flows = pkg.getRuleFlows();
                 for ( Iterator iter = flows.keySet().iterator(); iter.hasNext(); ) {
-                    removeProcess((String) iter.next());
+                    removeProcess( (String) iter.next() );
                 }
                 // removing the package itself from the list
                 this.pkgs.remove( pkg.getName() );
@@ -497,6 +506,8 @@
             int lastAquiredLock = 0;
             // get a snapshot of current working memories for locking
             final InternalWorkingMemory[] wms = getWorkingMemories();
+            
+            PackageCompilationData compilationData = null;
 
             try {
                 // Iterate each workingMemory and lock it
@@ -506,7 +517,11 @@
                 }
 
                 removeRule( rule );
-                pkg.removeRule( rule );
+                compilationData = pkg.removeRule( rule );
+                if ( this.reloadPackageCompilationData == null ) {
+                    this.reloadPackageCompilationData = new ReloadPackageCompilationData();
+                }
+                this.reloadPackageCompilationData.addPackageCompilationData( compilationData );
 
             } finally {
                 // Iterate each workingMemory and attempt to fire any rules, that were activated as a result 
@@ -516,23 +531,44 @@
                 for ( lastAquiredLock--; lastAquiredLock > -1; lastAquiredLock-- ) {
                     wms[lastAquiredLock].getLock().unlock();
                 }
-            }
+            }                       
         }
     }
 
     protected abstract void removeRule(Rule rule);
+    
+    public void removeFunction(String packageName, String functionName) {
+        synchronized ( this.pkgs ) {
+            final Package pkg = (Package) this.pkgs.get( packageName );
+            PackageCompilationData compilationData = pkg.removeFunction( functionName );
+            
+            if ( this.reloadPackageCompilationData == null ) {
+                this.reloadPackageCompilationData = new ReloadPackageCompilationData();
+            }
+            this.reloadPackageCompilationData.addPackageCompilationData( compilationData );            
+        }
+    }
 
     public synchronized void addProcess(final Process process) {
-        this.processes.put( process.getId(),
-                            process );
+        synchronized ( this.pkgs ) {
+            this.processes.put( process.getId(),
+                                process );
+        }
+        
     }
 
     public synchronized void removeProcess(final String id) {
-        this.processes.remove( id );
+        synchronized ( this.pkgs ) {        
+            this.processes.remove( id );
+        }
     }
 
     public Process getProcess(final String id) {
-        return (Process) this.processes.get( id );
+        Process process = null;
+        synchronized ( this.pkgs ) {
+            process = ( Process ) this.processes.get( id );
+        }
+        return process;
     }
 
     protected synchronized void addStatefulSession(final StatefulSession statefulSession) {
@@ -573,7 +609,7 @@
                                                                                       this.packageClassLoader );
 
         final AbstractWorkingMemory workingMemory = (AbstractWorkingMemory) streamWithLoader.readObject();
-        
+
         synchronized ( this.pkgs ) {
             workingMemory.setRuleBase( this );
             return (StatefulSession) workingMemory;
@@ -593,4 +629,41 @@
     public MapBackedClassLoader getMapBackedClassLoader() {
         return this.classLoader;
     }
+    
+    public void executeQueuedActions() {
+       synchronized ( this.pkgs ) {
+           if ( this.reloadPackageCompilationData != null ) {
+               this.reloadPackageCompilationData.execute( this );
+           }
+        }
+    }    
+    
+    public static class ReloadPackageCompilationData implements RuleBaseAction {
+        private Set set;
+        
+        public void addPackageCompilationData(PackageCompilationData packageCompilationData) {
+            if ( set == null ) {
+                this.set = new HashSet();
+            }
+            
+            this.set.add( packageCompilationData );
+        }
+        
+        public void execute(InternalRuleBase ruleBase) {
+            for ( Iterator it = this.set.iterator(); it.hasNext(); ) {
+                PackageCompilationData packageCompilationData = ( PackageCompilationData ) it.next();
+                packageCompilationData.reload();
+            }
+        }
+    }
+
+    public static interface RuleBaseAction {
+        public void execute(InternalRuleBase ruleBase);
+    }
+
+    //    public static class RuleBaseAction {
+    //        public void execute(InternalRuleBase ruleBase) {
+    //            
+    //        }
+    //    }
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-08-13 01:16:09 UTC (rev 14164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-08-13 03:29:33 UTC (rev 14165)
@@ -144,9 +144,9 @@
     protected boolean                      firing;
 
     protected boolean                      halt;
-    
-    private int 						   processCounter;
 
+    private int                            processCounter;
+
     // ------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------
@@ -191,7 +191,6 @@
         } else {
             this.discardOnLogicalOverride = false;
         }
-
     }
 
     // ------------------------------------------------------------
@@ -373,14 +372,14 @@
     public void clearAgendaGroup(final String group) {
         this.agenda.clearAgendaGroup( group );
     }
-    
+
     public void clearActivationGroup(final String group) {
         this.agenda.clearActivationGroup( group );
     }
-    
+
     public void clearRuleFlowGroup(final String group) {
         this.agenda.clearRuleFlowGroup( group );
-    }    
+    }
 
     public RuleBase getRuleBase() {
         return this.ruleBase;
@@ -439,10 +438,10 @@
             } finally {
                 this.firing = false;
                 // @todo (mproctor) disabling Otherwise management for now, not happy with the current implementation
-//                if ( noneFired ) {
-//                    doOtherwise( agendaFilter,
-//                                 fireLimit );
-//                }
+                //                if ( noneFired ) {
+                //                    doOtherwise( agendaFilter,
+                //                                 fireLimit );
+                //                }
 
             }
         }
@@ -757,7 +756,7 @@
                                 // and then re-add the handle. Otherwise we may end up with a leak.
                                 this.assertMap.remove( handle );
                                 Object oldObject = handle.getObject();
-                                if( oldObject instanceof ShadowProxy ) {
+                                if ( oldObject instanceof ShadowProxy ) {
                                     ((ShadowProxy) oldObject).setShadowedObject( object );
                                 } else {
                                     handle.setObject( object );
@@ -767,7 +766,7 @@
                                                     false );
                             } else {
                                 Object oldObject = handle.getObject();
-                                if( oldObject instanceof ShadowProxy ) {
+                                if ( oldObject instanceof ShadowProxy ) {
                                     ((ShadowProxy) oldObject).setShadowedObject( object );
                                 } else {
                                     handle.setObject( object );
@@ -836,6 +835,8 @@
                         Object object,
                         Rule rule,
                         Activation activation) {
+        this.ruleBase.executeQueuedActions();
+
         if ( activation != null ) {
             // release resources so that they can be GC'ed
             activation.getPropagationContext().releaseResources();
@@ -906,16 +907,16 @@
             // stop processing JavaBean PropertyChangeEvents
             // on the retracted Object
         } catch ( final IllegalArgumentException e ) {
-            throw new RuntimeDroolsException(  "Warning: The removePropertyChangeListener method on the class " + object.getClass() + " does not take a simple PropertyChangeListener argument so Drools will be unable to stop processing JavaBean"
-                                + " PropertyChangeEvents on the retracted Object" );
+            throw new RuntimeDroolsException( "Warning: The removePropertyChangeListener method on the class " + object.getClass() + " does not take a simple PropertyChangeListener argument so Drools will be unable to stop processing JavaBean"
+                                              + " PropertyChangeEvents on the retracted Object" );
         } catch ( final IllegalAccessException e ) {
-            throw new RuntimeDroolsException(  "Warning: The removePropertyChangeListener method on the class " + object.getClass() + " is not public so Drools will be unable to stop processing JavaBean PropertyChangeEvents on the retracted Object" );
+            throw new RuntimeDroolsException( "Warning: The removePropertyChangeListener method on the class " + object.getClass() + " is not public so Drools will be unable to stop processing JavaBean PropertyChangeEvents on the retracted Object" );
         } catch ( final InvocationTargetException e ) {
-            throw new RuntimeDroolsException(  "Warning: The removePropertyChangeL istener method on the class " + object.getClass() + " threw an InvocationTargetException so Drools will be unable to stop processing JavaBean"
-                                + " PropertyChangeEvents on the retracted Object: " + e.getMessage() );
+            throw new RuntimeDroolsException( "Warning: The removePropertyChangeL istener method on the class " + object.getClass() + " threw an InvocationTargetException so Drools will be unable to stop processing JavaBean"
+                                              + " PropertyChangeEvents on the retracted Object: " + e.getMessage() );
         } catch ( final SecurityException e ) {
-            throw new RuntimeDroolsException(  "Warning: The SecurityManager controlling the class " + object.getClass() + " did not allow the lookup of a removePropertyChangeListener method so Drools will be unable to stop processing JavaBean"
-                                + " PropertyChangeEvents on the retracted Object: " + e.getMessage() );
+            throw new RuntimeDroolsException( "Warning: The SecurityManager controlling the class " + object.getClass() + " did not allow the lookup of a removePropertyChangeListener method so Drools will be unable to stop processing JavaBean"
+                                              + " PropertyChangeEvents on the retracted Object: " + e.getMessage() );
         }
     }
 
@@ -940,6 +941,8 @@
                         final Activation activation) throws FactException {
         try {
             this.lock.lock();
+            this.ruleBase.executeQueuedActions();
+
             final InternalFactHandle handle = (InternalFactHandle) factHandle;
             if ( handle.getId() == -1 ) {
                 // can't retract an already retracted handle
@@ -1027,44 +1030,50 @@
     public void modifyRetract(final FactHandle factHandle,
                               final Rule rule,
                               final Activation activation) {
-        this.lock.lock();
-        // only needed if we maintain tms, but either way we must get it before we do the retract
-        int status = -1;
-        if ( this.maintainTms ) {
-            status = ((InternalFactHandle) factHandle).getEqualityKey().getStatus();
-        }
-        final InternalFactHandle handle = (InternalFactHandle) factHandle;
-        //final Object originalObject = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
+        try {
+            this.lock.lock();
+            this.ruleBase.executeQueuedActions();
 
-        if ( handle.getId() == -1 ) {
-            // the handle is invalid, most likely already  retracted, so return
-            return;
-        }
+            // only needed if we maintain tms, but either way we must get it before we do the retract
+            int status = -1;
+            if ( this.maintainTms ) {
+                status = ((InternalFactHandle) factHandle).getEqualityKey().getStatus();
+            }
+            final InternalFactHandle handle = (InternalFactHandle) factHandle;
+            //final Object originalObject = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
 
-        if ( activation != null ) {
-            // release resources so that they can be GC'ed
-            activation.getPropagationContext().releaseResources();
-        }
-        // Nowretract any trace  of the original fact
-        final PropagationContext propagationContext = new PropagationContextImpl( this.propagationIdCounter++,
-                                                                                  PropagationContext.MODIFICATION,
-                                                                                  rule,
-                                                                                  activation,
-                                                                                  this.agenda.getActiveActivations(),
-                                                                                  this.agenda.getDormantActivations() );
-        doRetract( handle,
-                   propagationContext );
+            if ( handle.getId() == -1 ) {
+                // the handle is invalid, most likely already  retracted, so return
+                return;
+            }
 
-        if ( this.maintainTms ) {
+            if ( activation != null ) {
+                // release resources so that they can be GC'ed
+                activation.getPropagationContext().releaseResources();
+            }
+            // Nowretract any trace  of the original fact
+            final PropagationContext propagationContext = new PropagationContextImpl( this.propagationIdCounter++,
+                                                                                      PropagationContext.MODIFICATION,
+                                                                                      rule,
+                                                                                      activation,
+                                                                                      this.agenda.getActiveActivations(),
+                                                                                      this.agenda.getDormantActivations() );
+            doRetract( handle,
+                       propagationContext );
 
-            // the hashCode and equality has changed, so we must update the EqualityKey
-            EqualityKey key = handle.getEqualityKey();
-            key.removeFactHandle( handle );
+            if ( this.maintainTms ) {
 
-            // If the equality key is now empty, then remove it
-            if ( key.isEmpty() ) {
-                this.tms.remove( key );
+                // the hashCode and equality has changed, so we must update the EqualityKey
+                EqualityKey key = handle.getEqualityKey();
+                key.removeFactHandle( handle );
+
+                // If the equality key is now empty, then remove it
+                if ( key.isEmpty() ) {
+                    this.tms.remove( key );
+                }
             }
+        } finally {
+            this.lock.unlock();
         }
     }
 
@@ -1081,6 +1090,9 @@
                              final Rule rule,
                              final Activation activation) {
         try {
+            this.lock.lock();
+            this.ruleBase.executeQueuedActions();
+            
             final InternalFactHandle handle = (InternalFactHandle) factHandle;
             final Object originalObject = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
 
@@ -1154,6 +1166,8 @@
                        final Activation activation) throws FactException {
         try {
             this.lock.lock();
+            this.ruleBase.executeQueuedActions();
+            
             // only needed if we maintain tms, but either way we must get it before we do the retract
             int status = -1;
             if ( this.maintainTms ) {
@@ -1352,12 +1366,12 @@
             final RuleFlowProcessInstance processInstance = new RuleFlowProcessInstanceImpl();
             processInstance.setWorkingMemory( this );
             processInstance.setProcess( process );
-            processInstance.setId(++processCounter);
+            processInstance.setId( ++processCounter );
             processInstance.start();
-            
-            getRuleFlowEventSupport().fireRuleFlowProcessStarted(
-            		processInstance, this );
-                
+
+            getRuleFlowEventSupport().fireRuleFlowProcessStarted( processInstance,
+                                                                  this );
+
             return processInstance;
         } else {
             throw new IllegalArgumentException( "Unknown process type: " + process.getClass() );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java	2007-08-13 01:16:09 UTC (rev 14164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java	2007-08-13 03:29:33 UTC (rev 14165)
@@ -57,6 +57,8 @@
     public Map getPackagesMap();
 
     void disposeStatefulSession(StatefulSession statefulSession);
+    
+    void executeQueuedActions();
 
     /**
      * Assert a fact object.

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java	2007-08-13 01:16:09 UTC (rev 14164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java	2007-08-13 03:29:33 UTC (rev 14165)
@@ -255,9 +255,10 @@
         return this.globals;
     }
 
-    public void removeFunction(final String functionName) {
+    public PackageCompilationData removeFunction(final String functionName) {
         this.functions.remove( functionName );
         this.packageCompilationData.remove( this.name + "." + StringUtils.ucFirst( functionName ) );
+        return this.packageCompilationData;
     }
 
     public FactTemplate getFactTemplate(final String name) {
@@ -321,7 +322,7 @@
         this.ruleFlows.remove( id );
     }
 
-    public void removeRule(final Rule rule) {
+    public PackageCompilationData removeRule(final Rule rule) {
         this.rules.remove( rule.getName() );
         final String consequenceName = rule.getConsequence().getClass().getName();
         this.packageCompilationData.remove( consequenceName );
@@ -331,6 +332,7 @@
         // Now remove the rule class - the name is a subset of the consequence name
         this.packageCompilationData.remove( consequenceName.substring( 0,
                                                                        consequenceName.indexOf( "ConsequenceInvoker" ) ) );
+        return this.packageCompilationData;
     }
 
     private void removeClasses(final ConditionalElement ce) {

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java	2007-08-13 01:16:09 UTC (rev 14164)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java	2007-08-13 03:29:33 UTC (rev 14165)
@@ -33,6 +33,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import org.drools.CheckedDroolsException;
 import org.drools.RuntimeDroolsException;
@@ -52,23 +53,24 @@
     /**
      *
      */
-    private static final long            serialVersionUID = 400L;
+    private static final long             serialVersionUID = 400L;
 
     private static final ProtectionDomain PROTECTION_DOMAIN;
 
-    private Map                          invokerLookups;
+    private Map                           invokerLookups;
 
-    private Object                       AST;
+    private Object                        AST;
 
-    private Map                          store;
+    private Map                           store;
 
-    private Map                          lineMappings;
+    private Map                           lineMappings;
 
-    private transient PackageClassLoader classLoader;
+    private transient PackageClassLoader  classLoader;
 
-    private transient ClassLoader        parentClassLoader;
+    private transient ClassLoader         parentClassLoader;
+    
+    private boolean                       dirty;
 
-
     static {
         PROTECTION_DOMAIN = (ProtectionDomain) AccessController.doPrivileged( new PrivilegedAction() {
             public Object run() {
@@ -90,11 +92,16 @@
         this.invokerLookups = new HashMap();
         this.store = new HashMap();
         this.lineMappings = new HashMap();
+        this.dirty = false;
     }
+    
+    public boolean isDirty() {
+        return this.dirty;
+    }
 
     private void initClassLoader(ClassLoader parentClassLoader) {
-        if (parentClassLoader == null ) {
-            throw new RuntimeDroolsException("PackageCompilationData cannot have a null parentClassLoader" );
+        if ( parentClassLoader == null ) {
+            throw new RuntimeDroolsException( "PackageCompilationData cannot have a null parentClassLoader" );
         }
         this.parentClassLoader = parentClassLoader;
         this.classLoader = new PackageClassLoader( this.parentClassLoader );
@@ -126,7 +133,7 @@
     public void readExternal(final ObjectInput stream) throws IOException,
                                                       ClassNotFoundException {
         if ( stream instanceof DroolsObjectInputStream ) {
-            DroolsObjectInputStream droolsStream = ( DroolsObjectInputStream ) stream;
+            DroolsObjectInputStream droolsStream = (DroolsObjectInputStream) stream;
             initClassLoader( droolsStream.getClassLoader() );
         } else {
             initClassLoader( Thread.currentThread().getContextClassLoader() );
@@ -149,10 +156,10 @@
     }
 
     public byte[] read(final String resourceName) {
-        final byte[] bytes = null;
+        byte[] bytes = null;
 
         if ( this.store != null ) {
-            return (byte[]) this.store.get( resourceName );
+            bytes = ( byte[] ) this.store.get( resourceName );
         }
         return bytes;
     }
@@ -162,7 +169,8 @@
         if ( this.store.put( resourceName,
                              clazzData ) != null ) {
             // we are updating an existing class so reload();
-            reload();
+            //reload();
+            this.dirty = true;
         } else {
             try {
                 wire( convertResourceToClassName( resourceName ) );
@@ -178,7 +186,8 @@
         this.invokerLookups.remove( resourceName );
         if ( this.store.remove( convertClassToResourcePath( resourceName ) ) != null ) {
             // we need to make sure the class is removed from the classLoader
-            reload();
+            // reload();
+            this.dirty = true;
         }
     }
 
@@ -206,8 +215,10 @@
 
         // Wire up invokers
         try {
-            for ( final Iterator it = this.invokerLookups.keySet().iterator(); it.hasNext(); ) {
-                wire( (String) it.next() );
+            for ( final Iterator it = this.invokerLookups.entrySet().iterator(); it.hasNext(); ) {
+                Entry entry = (Entry) it.next();
+                wire( (String) entry.getKey(),
+                      entry.getValue() );
             }
         } catch ( final ClassNotFoundException e ) {
             throw new RuntimeDroolsException( e );
@@ -217,6 +228,8 @@
             throw new RuntimeDroolsException( e );
         } catch ( final InstantiationException e ) {
             throw new RuntimeDroolsException( e );
+        } finally {
+            this.dirty = false;
         }
     }
 
@@ -279,12 +292,12 @@
     }
 
     public Map getLineMappings() {
-        if (this.lineMappings==null) {
+        if ( this.lineMappings == null ) {
             this.lineMappings = new HashMap();
         }
         return this.lineMappings;
     }
-    
+
     public LineMappings getLineMappings(final String className) {
         return (LineMappings) getLineMappings().get( className );
     }




More information about the jboss-svn-commits mailing list