[jboss-svn-commits] JBL Code SVN: r18558 - labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Feb 21 15:29:38 EST 2008


Author: tirelli
Date: 2008-02-21 15:29:38 -0500 (Thu, 21 Feb 2008)
New Revision: 18558

Modified:
   labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
Log:
JBRULES-1481: stoping action queue recursion

Modified: labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2008-02-21 20:18:35 UTC (rev 18557)
+++ labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2008-02-21 20:29:38 UTC (rev 18558)
@@ -28,6 +28,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Queue;
 import java.util.Map.Entry;
 
 import org.drools.Agenda;
@@ -88,71 +89,73 @@
     // ------------------------------------------------------------
     // Constants
     // ------------------------------------------------------------
-    protected static final Class[]                  ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES = new Class[]{PropertyChangeListener.class};
+    protected static final Class[]         ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES = new Class[]{PropertyChangeListener.class};
 
     // ------------------------------------------------------------
     // Instance members
     // ------------------------------------------------------------
-    protected long                                  id;
+    protected long                         id;
 
     /** The arguments used when adding/removing a property change listener. */
-    protected final Object[]                        addRemovePropertyChangeListenerArgs           = new Object[]{this};
+    protected final Object[]               addRemovePropertyChangeListenerArgs           = new Object[]{this};
 
     /** The actual memory for the <code>JoinNode</code>s. */
-    protected final PrimitiveLongMap                nodeMemories                                  = new PrimitiveLongMap( 32,
-                                                                                                                          8 );
+    protected final PrimitiveLongMap       nodeMemories                                  = new PrimitiveLongMap( 32,
+                                                                                                                 8 );
     /** Object-to-handle mapping. */
-    private final ObjectHashMap                     assertMap;
-    private final ObjectHashMap                     identityMap;
+    private final ObjectHashMap            assertMap;
+    private final ObjectHashMap            identityMap;
 
-    protected Map                                   queryResults                                  = Collections.EMPTY_MAP;
+    protected Map                          queryResults                                  = Collections.EMPTY_MAP;
 
     /** Global values which are associated with this memory. */
-    protected GlobalResolver                        globalResolver;
+    protected GlobalResolver               globalResolver;
 
-    protected static final Object                   NULL                                          = new Serializable() {
-                                                                                                      private static final long serialVersionUID = 400L;
-                                                                                                  };
+    protected static final Object          NULL                                          = new Serializable() {
+                                                                                             private static final long serialVersionUID = 400L;
+                                                                                         };
 
     /** The eventSupport */
-    protected WorkingMemoryEventSupport             workingMemoryEventSupport                     = new WorkingMemoryEventSupport();
+    protected WorkingMemoryEventSupport    workingMemoryEventSupport                     = new WorkingMemoryEventSupport();
 
-    protected AgendaEventSupport                    agendaEventSupport                            = new AgendaEventSupport();
+    protected AgendaEventSupport           agendaEventSupport                            = new AgendaEventSupport();
 
-    protected RuleFlowEventSupport                  ruleFlowEventSupport                          = new RuleFlowEventSupport();
-    
-    protected List                                  __ruleBaseEventListeners                      = new LinkedList();                      
+    protected RuleFlowEventSupport         ruleFlowEventSupport                          = new RuleFlowEventSupport();
 
+    protected List                         __ruleBaseEventListeners                      = new LinkedList();
+
     /** The <code>RuleBase</code> with which this memory is associated. */
-    protected transient InternalRuleBase            ruleBase;
+    protected transient InternalRuleBase   ruleBase;
 
-    protected final FactHandleFactory               handleFactory;
+    protected final FactHandleFactory      handleFactory;
 
-    protected final TruthMaintenanceSystem          tms;
+    protected final TruthMaintenanceSystem tms;
 
     /** Rule-firing agenda. */
-    protected DefaultAgenda                         agenda;
+    protected DefaultAgenda                agenda;
 
-    protected final List                            actionQueue                                   = new ArrayList();
+    protected final Queue                  actionQueue                                   = new LinkedList();
 
-    protected final ReentrantLock                   lock                                          = new ReentrantLock();
+    protected boolean                      evaluatingActionQueue;
 
-    protected final boolean                         discardOnLogicalOverride;
+    protected final ReentrantLock          lock                                          = new ReentrantLock();
 
-    protected long                                  propagationIdCounter;
+    protected final boolean                discardOnLogicalOverride;
 
-    private final boolean                           maintainTms;
+    protected long                         propagationIdCounter;
 
-    private final boolean                           sequential;
+    private final boolean                  maintainTms;
 
-    private List                                    liaPropagations                               = Collections.EMPTY_LIST;
+    private final boolean                  sequential;
 
+    private List                           liaPropagations                               = Collections.EMPTY_LIST;
+
     /** Flag to determine if a rule is currently being fired. */
-    protected boolean                               firing;
+    protected boolean                      firing;
 
-    protected boolean                               halt;
+    protected boolean                      halt;
 
-    private int                                     processCounter;
+    private int                            processCounter;
 
     // ------------------------------------------------------------
     // Constructors
@@ -387,7 +390,7 @@
     public long getId() {
         return this.id;
     }
-    
+
     public void setId(long id) {
         this.id = id;
     }
@@ -1309,16 +1312,15 @@
     }
 
     public void executeQueuedActions() {
-        while ( !actionQueue.isEmpty() ) {
-            final WorkingMemoryAction action = (WorkingMemoryAction) actionQueue.get( 0 );
-            actionQueue.remove( 0 );
-            action.execute( this );
+        if( ! evaluatingActionQueue ) {
+            evaluatingActionQueue = true;
+            WorkingMemoryAction action = null;
+            
+            while ( ( action = (WorkingMemoryAction) actionQueue.poll() ) != null ) {
+                action.execute( this );
+            }
+            evaluatingActionQueue = false;
         }
-        //        for ( final Iterator it = this.actionQueue.iterator(); it.hasNext(); ) {
-        //            final WorkingMemoryAction action = (WorkingMemoryAction) it.next();
-        //            it.remove();
-        //            action.execute( this );
-        //        }
     }
 
     public void queueWorkingMemoryAction(final WorkingMemoryAction action) {




More information about the jboss-svn-commits mailing list