[jboss-svn-commits] JBL Code SVN: r36571 - in labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools: reteoo and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jan 24 14:04:39 EST 2011


Author: tsurdilovic
Date: 2011-01-24 14:04:39 -0500 (Mon, 24 Jan 2011)
New Revision: 36571

Modified:
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/impl/StatelessKnowledgeSessionImpl.java
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
Log:
BRMS-542 : Ruleflow broken inside BusinessRulesProcessor

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/impl/StatelessKnowledgeSessionImpl.java
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/impl/StatelessKnowledgeSessionImpl.java	2011-01-24 16:11:33 UTC (rev 36570)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/impl/StatelessKnowledgeSessionImpl.java	2011-01-24 19:04:39 UTC (rev 36571)
@@ -16,9 +16,12 @@
 
 package org.drools.impl;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.drools.SessionConfiguration;
@@ -33,6 +36,7 @@
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalRuleBase;
 import org.drools.event.AgendaEventSupport;
+import org.drools.event.RuleFlowEventListener;
 import org.drools.event.RuleFlowEventSupport;
 import org.drools.event.WorkingMemoryEventSupport;
 import org.drools.event.process.ProcessEventListener;
@@ -72,6 +76,7 @@
     public WorkingMemoryEventSupport                                          workingMemoryEventSupport = new WorkingMemoryEventSupport();
     public AgendaEventSupport                                                 agendaEventSupport        = new AgendaEventSupport();
     public RuleFlowEventSupport                                               ruleFlowEventSupport      = new RuleFlowEventSupport();
+    public List<RuleFlowEventListener> copiedRuleFlowEventListeners =         new ArrayList<RuleFlowEventListener>();
 
     private KnowledgeSessionConfiguration                                     conf;
     private Environment                                                       environment;
@@ -119,11 +124,28 @@
         }
         this.ruleBase.readLock();
         try {
-            ReteooWorkingMemory wm = new ReteooWorkingMemory( this.ruleBase.nextWorkingMemoryCounter(),
-                                                              this.ruleBase,
-                                                              (SessionConfiguration) this.conf,
-                                                              this.environment );
-
+        	ReteooWorkingMemory wm;
+        	if(this.ruleFlowEventSupport.getEventListeners().size() > 0) {
+        		wm = new ReteooWorkingMemory( this.ruleBase.nextWorkingMemoryCounter(),
+                        this.ruleBase,
+                        (SessionConfiguration) this.conf,
+                        this.environment,
+                        this.ruleFlowEventSupport);
+        	} else {
+        		wm = new ReteooWorkingMemory( this.ruleBase.nextWorkingMemoryCounter(),
+                        this.ruleBase,
+                        (SessionConfiguration) this.conf,
+                        this.environment );
+        		
+        		// copy the ruleflow event listeners
+            	Iterator<RuleFlowEventListener> wmFlowListenerIter = wm.getRuleFlowEventListeners().iterator();
+            	while ( wmFlowListenerIter.hasNext() ) {
+            		RuleFlowEventListener rfel = wmFlowListenerIter.next();
+            		this.ruleFlowEventSupport.addEventListener(rfel);
+            		this.copiedRuleFlowEventListeners.add(rfel);
+            	}
+            	wm.setRuleFlowEventSupport( this.ruleFlowEventSupport );
+        	}
             // we don't pass the mapped listener wrappers to the session constructor anymore,
             // because they would be ignored anyway, since the wm already contains those listeners
             StatefulKnowledgeSessionImpl ksession = new StatefulKnowledgeSessionImpl( wm,
@@ -133,7 +155,6 @@
             wm.setKnowledgeRuntime( ksession );
             wm.setWorkingMemoryEventSupport( this.workingMemoryEventSupport );
             wm.setAgendaEventSupport( this.agendaEventSupport );
-            wm.setRuleFlowEventSupport( this.ruleFlowEventSupport );
 
             final InternalFactHandle handle =  wm.getFactHandleFactory().newFactHandle( InitialFactImpl.getInstance(),
                                                                                         wm.getObjectTypeConfigurationRegistry().getObjectTypeConf( EntryPoint.DEFAULT,
@@ -283,6 +304,7 @@
             }
         } finally {
             ((StatefulKnowledgeSessionImpl) ksession).session.endBatchExecution();
+            cleanupRuleFlowEventListeners();
         }
     }
 
@@ -291,6 +313,7 @@
 
         ksession.insert( object );
         ksession.fireAllRules( );
+        cleanupRuleFlowEventListeners( );
     }
 
     public void execute(Iterable objects) {
@@ -300,10 +323,22 @@
             ksession.insert( object );
         }
         ksession.fireAllRules( );
+        cleanupRuleFlowEventListeners( );
     }
     
     public Environment getEnvironment() {
     	return environment;
     }
+    
+    private void cleanupRuleFlowEventListeners() {
+    	if(this.ruleFlowEventSupport.getEventListeners().size() > 0 && (this.copiedRuleFlowEventListeners != null && this.copiedRuleFlowEventListeners.size() > 0)) {
+    		for(RuleFlowEventListener nextEventListener : this.copiedRuleFlowEventListeners) {
+    			if(this.ruleFlowEventSupport.getEventListeners().contains(nextEventListener)) {
+    				this.ruleFlowEventSupport.removeEventListener(nextEventListener);
+    			}
+    		}
+    	}
+    	this.copiedRuleFlowEventListeners = new ArrayList<RuleFlowEventListener>();
+    }
 
 }

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2011-01-24 16:11:33 UTC (rev 36570)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2011-01-24 19:04:39 UTC (rev 36571)
@@ -101,6 +101,28 @@
         this.agenda = new DefaultAgenda( ruleBase );
         this.agenda.setWorkingMemory( this );
     }
+    
+    /**
+     * TODO - CHECK!!
+     * @param id
+     * @param ruleBase
+     * @param config
+     * @param environment
+     * @param ruleFlowEventSupport
+     */
+    public ReteooWorkingMemory(final int id,
+            final InternalRuleBase ruleBase,
+            final SessionConfiguration config,
+            final Environment environment,
+            final RuleFlowEventSupport ruleFlowEventSupport) {
+    	this( id,
+    			ruleBase,
+    			config,
+    			environment,
+    			new WorkingMemoryEventSupport(),
+    	        new AgendaEventSupport(),
+    	        ruleFlowEventSupport);
+    }
 
     public ReteooWorkingMemory(final int id,
                                final InternalRuleBase ruleBase,



More information about the jboss-svn-commits mailing list