[jboss-svn-commits] JBL Code SVN: r28893 - in labs/jbossrules/trunk: drools-compiler/src/test/java/org/drools/integrationtests and 10 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Aug 10 20:41:17 EDT 2009
Author: mark.proctor at jboss.com
Date: 2009-08-10 20:41:16 -0400 (Mon, 10 Aug 2009)
New Revision: 28893
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ActivationNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SimpleAgendaGroup.java
Removed:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupNode.java
Modified:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ExecutionFlowControlTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/RuleCoverageListenerTest.java
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_salienceIntegerRule.drl
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AgendaItem.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ArrayAgendaGroup.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalAgenda.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalAgendaGroup.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/PriorityQueueAgendaGroupFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/conflict/DepthConflictResolver.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/conflict/TotalRecencyConflictResolver.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Activation.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/RuleFlowGroup.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Tuple.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/BinaryHeapQueue.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LeftTupleList.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/Queueable.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/RightTupleList.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BaseQueueable.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BinaryHeapPriorityQueueTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/LongQueueable.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/RightTupleIndexHashTableTest.java
Log:
JBRULES-2242 Correct the Rete for Clips like LIFO conflict resolution
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -40,7 +40,7 @@
import org.drools.common.ActivationGroupNode;
import org.drools.common.InternalFactHandle;
import org.drools.common.LogicalDependency;
-import org.drools.common.RuleFlowGroupNode;
+import org.drools.common.ActivationNode;
import org.drools.commons.jci.compilers.EclipseJavaCompiler;
import org.drools.commons.jci.compilers.JaninoJavaCompiler;
import org.drools.commons.jci.compilers.JavaCompiler;
@@ -1610,12 +1610,12 @@
return null;
}
- public RuleFlowGroupNode getRuleFlowGroupNode() {
+ public ActivationNode getActivationNode() {
// TODO Auto-generated method stub
return null;
}
- public void setRuleFlowGroupNode(final RuleFlowGroupNode ruleFlowGroupNode) {
+ public void setActivationNode(final ActivationNode ruleFlowGroupNode) {
// TODO Auto-generated method stub
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ExecutionFlowControlTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ExecutionFlowControlTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ExecutionFlowControlTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -147,7 +147,7 @@
}
}
- public void testSalienceInteger() throws Exception {
+ public void testSalienceIntegerAndDepthCrs() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_salienceIntegerRule.drl" ) ) );
final Package pkg = builder.getPackage();
@@ -167,15 +167,18 @@
workingMemory.fireAllRules();
- Assert.assertEquals( "Two rules should have been fired",
- 2,
+ Assert.assertEquals( "Three rules should have been fired",
+ 3,
list.size() );
- Assert.assertEquals( "Rule 3 should have been fired first",
- "Rule 3",
+ Assert.assertEquals( "Rule 4 should have been fired first",
+ "Rule 4",
list.get( 0 ) );
Assert.assertEquals( "Rule 2 should have been fired second",
"Rule 2",
- list.get( 1 ) );
+ list.get( 1 ) );
+ Assert.assertEquals( "Rule 3 should have been fired third",
+ "Rule 3",
+ list.get( 2 ) );
}
public void testSalienceExpression() throws Exception {
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -246,8 +246,8 @@
assertEquals("TestObject.stayHasDaysOfWeek: java|false|[2008-04-01, 2008-04-10]", list.get(1));
assertEquals("TestObject.checkHighestPriority: mvel|2", list.get(2));
assertEquals("TestObject.stayHasDaysOfWeek: mvel|false|[2008-04-01, 2008-04-10]", list.get(3));
- assertEquals("TestObject.applyValueAddPromo: 1|2|3|4|java", list.get(4));
- assertEquals("TestObject.applyValueAddPromo: 1|2|3|4|mvel", list.get(5));
+ assertEquals("TestObject.applyValueAddPromo: 1|2|3|4|mvel", list.get(4));
+ assertEquals("TestObject.applyValueAddPromo: 1|2|3|4|java", list.get(5));
}
private Package compileRule(String drl) throws Exception {
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -1433,12 +1433,12 @@
assertEquals( 3,
((List) session.getGlobal( "list" )).size() );
+ assertEquals( r2d2,
+ ((List) session.getGlobal( "list" )).get( 0 ) );
+ assertEquals( c3po,
+ ((List) session.getGlobal( "list" )).get( 1 ) );
assertEquals( bobba,
((List) session.getGlobal( "list" )).get( 2 ) );
- assertEquals( c3po,
- ((List) session.getGlobal( "list" )).get( 1 ) );
- assertEquals( r2d2,
- ((List) session.getGlobal( "list" )).get( 0 ) );
session = getSerialisedStatefulSession( session );
@@ -1451,10 +1451,10 @@
assertEquals( 5,
((List) session.getGlobal( "list" )).size() );
+ assertEquals( bobba,
+ ((List) session.getGlobal( "list" )).get( 4 ) );
assertEquals( r2d2,
((List) session.getGlobal( "list" )).get( 3 ) );
- assertEquals( bobba,
- ((List) session.getGlobal( "list" )).get( 4 ) );
session = getSerialisedStatefulSession( session );
@@ -1585,9 +1585,9 @@
// now remove a cheese, should be no change
ksession.retract( ksession.getFactHandle( stilton ) );
- ksession = getSerialisedStatefulKnowledgeSession( ksession,
- MarshallerFactory.newIdentityMarshallingStrategy(),
- true );
+// ksession = getSerialisedStatefulKnowledgeSession( ksession,
+// MarshallerFactory.newIdentityMarshallingStrategy(),
+// true );
ksession.fireAllRules();
assertEquals( 4,
list.size() );
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -1385,10 +1385,13 @@
FactHandle handle = session.insert( mycheese );
session.fireAllRules();
//System.out.println(((List) session.getGlobal( "list" )).toString());
+ assertTrue( ((List) session.getGlobal( "list" )).size() == 2 );
+ assertEquals( "rule 4",
+ ((List) session.getGlobal( "list" )).get( 0 ) );
assertEquals( "rule 2b",
- ((List) session.getGlobal( "list" )).get( 0 ) );
- assertTrue( ((List) session.getGlobal( "list" )).size() == 2 );
+ ((List) session.getGlobal( "list" )).get( 1 ) );
+
//Test 2nd level (parent) to make sure rule honors the extend rule
final List list2 = new ArrayList();
session.setGlobal( "list",
@@ -5408,7 +5411,7 @@
list2 );
SpecialString first42 = new SpecialString( "42" );
- SpecialString second43 = new SpecialString( "42" );
+ SpecialString second43 = new SpecialString( "43" );
SpecialString world = new SpecialString( "World" );
session.insert( world );
session.insert( first42 );
@@ -5423,26 +5426,26 @@
assertEquals( 6,
list2.size() );
- assertEquals( second43,
+ assertEquals( first42,
list1.get( 0 ) );
- assertEquals( first42,
+ assertEquals( world,
list1.get( 1 ) );
assertEquals( second43,
list1.get( 2 ) );
- assertEquals( world,
+ assertEquals( second43,
list1.get( 3 ) );
assertEquals( world,
list1.get( 4 ) );
assertEquals( first42,
list1.get( 5 ) );
- assertEquals( first42,
+ assertEquals( second43,
list2.get( 0 ) );
assertEquals( second43,
list2.get( 1 ) );
+ assertEquals( first42,
+ list2.get( 2 ) );
assertEquals( world,
- list2.get( 2 ) );
- assertEquals( second43,
list2.get( 3 ) );
assertEquals( first42,
list2.get( 4 ) );
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/RuleCoverageListenerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/RuleCoverageListenerTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/testframework/RuleCoverageListenerTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -8,7 +8,7 @@
import org.drools.FactHandle;
import org.drools.common.ActivationGroupNode;
import org.drools.common.LogicalDependency;
-import org.drools.common.RuleFlowGroupNode;
+import org.drools.common.ActivationNode;
import org.drools.event.AfterActivationFiredEvent;
import org.drools.rule.GroupElement;
import org.drools.rule.Rule;
@@ -104,7 +104,7 @@
return new Rule( ruleName );
}
- public RuleFlowGroupNode getRuleFlowGroupNode() {
+ public ActivationNode getActivationNode() {
return null;
}
@@ -136,7 +136,7 @@
public void setLogicalDependencies(LinkedList justified) {
}
- public void setRuleFlowGroupNode(RuleFlowGroupNode ruleFlowGroupNode) {
+ public void setActivationNode(ActivationNode ruleFlowGroupNode) {
}
public Collection<FactHandle> getFactHandles() {
Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_salienceIntegerRule.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_salienceIntegerRule.drl 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_salienceIntegerRule.drl 2009-08-11 00:41:16 UTC (rev 28893)
@@ -13,22 +13,31 @@
list.add( "Rule 1" );
end
-# this rule shall fire second, since rule 3 has higher salience
+# this rule shall fire third, since rule 4 has higher salience but this is LIFO after rule 2
+rule "Salience rule 3"
+ salience 10
+ when
+ person: Person( )
+ then
+ list.add( "Rule 3" );
+ retract(person);
+end
+
+# this rule shall fire second, since rule 4 has higher salience but this is LIFO before rule 3
rule "Salience rule 2"
salience 10
when
person: Person( )
then
list.add( "Rule 2" );
- retract(person);
-end
+end
# this rule shall fire first since it has the higher salience
-rule "Salience rule 3"
+rule "Salience rule 4"
salience 20
when
Person( )
then
- list.add( "Rule 3" );
+ list.add( "Rule 4" );
end
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ActivationNode.java (from rev 28878, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupNode.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ActivationNode.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ActivationNode.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -0,0 +1,45 @@
+package org.drools.common;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.spi.Activation;
+import org.drools.util.AbstractBaseLinkedListNode;
+
+public class ActivationNode extends AbstractBaseLinkedListNode {
+
+ private static final long serialVersionUID = 400L;
+
+ private Activation activation;
+ private Object parentContainer;
+
+ public ActivationNode(final Activation activation,
+ final Object parentContainer) {
+ super();
+ this.activation = activation;
+ this.activation.setActivationNode( this );
+ this.parentContainer = parentContainer;
+ }
+
+ public Activation getActivation() {
+ return this.activation;
+ }
+
+ public Object getParentContainer() {
+ return this.parentContainer;
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AgendaItem.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AgendaItem.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AgendaItem.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -90,7 +90,7 @@
private ActivationGroupNode activationGroupNode;
- private RuleFlowGroupNode ruleFlowGroupNode;
+ private ActivationNode activationNode;
// ------------------------------------------------------------
// Constructors
@@ -139,7 +139,7 @@
activated = in.readBoolean();
agendaGroup = (InternalAgendaGroup) in.readObject();
activationGroupNode = (ActivationGroupNode) in.readObject();
- ruleFlowGroupNode = (RuleFlowGroupNode) in.readObject();
+ activationNode = (ActivationNode) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
@@ -156,7 +156,7 @@
out.writeBoolean( activated );
out.writeObject( agendaGroup );
out.writeObject( activationGroupNode );
- out.writeObject( ruleFlowGroupNode );
+ out.writeObject( activationNode );
}
public PropagationContext getPropagationContext() {
@@ -258,20 +258,20 @@
return this.tuple.hashCode();
}
- public void enqueued(final Queue queue,
- final int index) {
- this.queue = queue;
+ public void enqueued(final int index) {
this.index = index;
}
public void dequeue() {
- if ( this.queue != null ) {
- // will only be null if the AgendaGroup is locked when the activation add was attempted
- this.queue.dequeue( this.index );
- this.queue = null;
+ if ( this.agendaGroup != null ) {
+ this.agendaGroup.remove( this );
}
this.activated = false;
}
+
+ public int getIndex() {
+ return this.index;
+ }
public void remove() {
dequeue();
@@ -293,12 +293,12 @@
this.agendaGroup = agendaGroup;
}
- public RuleFlowGroupNode getRuleFlowGroupNode() {
- return this.ruleFlowGroupNode;
+ public ActivationNode getActivationNode() {
+ return this.activationNode;
}
- public void setRuleFlowGroupNode(final RuleFlowGroupNode ruleFlowGroupNode) {
- this.ruleFlowGroupNode = ruleFlowGroupNode;
+ public void setActivationNode(final ActivationNode activationNode) {
+ this.activationNode = activationNode;
}
public GroupElement getSubRule() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ArrayAgendaGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ArrayAgendaGroup.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ArrayAgendaGroup.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -222,5 +222,9 @@
public void setFocus() {
throw new UnsupportedOperationException();
+ }
+
+ public void remove(AgendaItem agendaItem) {
+ throw new UnsupportedOperationException();
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -155,4 +155,10 @@
public void setFocus() {
throw new UnsupportedOperationException();
}
+
+
+ @Override
+ public void remove(AgendaItem agendaItem) {
+ this.queue.dequeue( agendaItem.getIndex() );
+ }
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -39,6 +39,8 @@
import org.drools.reteoo.LeftTuple;
import org.drools.reteoo.ReteooWorkingMemory;
import org.drools.rule.Declaration;
+import org.drools.rule.GroupElement;
+import org.drools.rule.Rule;
import org.drools.spi.Activation;
import org.drools.spi.ActivationGroup;
import org.drools.spi.AgendaFilter;
@@ -48,6 +50,7 @@
import org.drools.spi.KnowledgeHelper;
import org.drools.spi.PropagationContext;
import org.drools.spi.RuleFlowGroup;
+import org.drools.spi.Tuple;
import org.drools.util.ClassUtils;
import org.drools.util.LinkedListNode;
@@ -114,6 +117,8 @@
protected volatile AtomicBoolean halt = new AtomicBoolean( false );
+ private int activationCounter;
+
// ------------------------------------------------------------
// Constructors
// ------------------------------------------------------------
@@ -171,6 +176,31 @@
}
}
+ public AgendaItem createAgendaItem(final Tuple tuple,
+ final int salience,
+ final PropagationContext context,
+ final Rule rule,
+ final GroupElement subrule) {
+ return new AgendaItem( activationCounter++,
+ tuple,
+ salience,
+ context,
+ rule,
+ subrule );
+ }
+
+ public ScheduledAgendaItem createScheduledAgendaItem(final Tuple tuple,
+ final PropagationContext context,
+ final Rule rule,
+ final GroupElement subrule) {
+ return new ScheduledAgendaItem( activationCounter++,
+ tuple,
+ this,
+ context,
+ rule,
+ subrule );
+ }
+
public void setWorkingMemory(final InternalWorkingMemory workingMemory) {
this.workingMemory = workingMemory;
if ( ((InternalRuleBase) this.workingMemory.getRuleBase()).getConfiguration().isSequential() ) {
@@ -548,12 +578,12 @@
public Map<String, InternalAgendaGroup> getAgendaGroupsMap() {
return this.agendaGroups;
}
-
+
public InternalAgendaGroup getMainAgendaGroup() {
- if ( this.main == null ) {
+ if ( this.main == null ) {
this.main = (InternalAgendaGroup) getAgendaGroup( AgendaGroup.MAIN );
}
-
+
return this.main;
}
@@ -769,8 +799,8 @@
item.getActivationGroupNode().getActivationGroup().removeActivation( item );
}
- if ( item.getRuleFlowGroupNode() != null ) {
- final InternalRuleFlowGroup ruleFlowGroup = item.getRuleFlowGroupNode().getRuleFlowGroup();
+ if ( item.getActivationNode() != null ) {
+ final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) item.getActivationNode().getParentContainer();
ruleFlowGroup.removeActivation( item );
}
@@ -810,14 +840,14 @@
activation.setActivated( false );
activation.remove();
- if ( activation.getRuleFlowGroupNode() != null ) {
- final InternalRuleFlowGroup ruleFlowGroup = activation.getRuleFlowGroupNode().getRuleFlowGroup();
+ if ( activation.getActivationNode() != null ) {
+ final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) activation.getActivationNode().getParentContainer();
ruleFlowGroup.removeActivation( activation );
}
eventsupport.getAgendaEventSupport().fireActivationCancelled( activation,
this.workingMemory,
- ActivationCancelledCause.CLEAR);
+ ActivationCancelledCause.CLEAR );
}
}
activationGroup.clear();
@@ -834,7 +864,7 @@
final EventSupport eventsupport = (EventSupport) this.workingMemory;
for ( Iterator it = ruleFlowGroup.iterator(); it.hasNext(); ) {
- RuleFlowGroupNode node = (RuleFlowGroupNode) it.next();
+ ActivationNode node = (ActivationNode) it.next();
AgendaItem item = (AgendaItem) node.getActivation();
if ( item != null ) {
item.setActivated( false );
@@ -950,11 +980,11 @@
}
}
- if ( activation.getRuleFlowGroupNode() != null ) {
- final InternalRuleFlowGroup ruleFlowGroup = activation.getRuleFlowGroupNode().getRuleFlowGroup();
+ if ( activation.getActivationNode() != null ) {
+ final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) activation.getActivationNode().getParentContainer();
// it is possible that the ruleflow group is no longer active if it was
// cleared during execution of this activation
- if (ruleFlowGroup.isActive()) {
+ if ( ruleFlowGroup.isActive() ) {
ruleFlowGroup.removeActivation( activation );
}
}
@@ -1016,7 +1046,7 @@
RuleFlowGroup systemRuleFlowGroup = this.getRuleFlowGroup( ruleflowGroupName );
- for ( Iterator<RuleFlowGroupNode> activations = systemRuleFlowGroup.iterator(); activations.hasNext(); ) {
+ for ( Iterator<ActivationNode> activations = systemRuleFlowGroup.iterator(); activations.hasNext(); ) {
Activation activation = activations.next().getActivation();
if ( ruleName.equals( activation.getRule().getName() ) ) {
if ( checkProcessInstance( activation,
@@ -1067,9 +1097,9 @@
public void fireUntilHalt(final AgendaFilter agendaFilter) {
this.halt.set( false );
while ( continueFiring( -1 ) ) {
- boolean fired = fireNextItem( agendaFilter );
- fired = fired || !((AbstractWorkingMemory) this.workingMemory).getActionQueue().isEmpty();
- this.workingMemory.executeQueuedActions();
+ boolean fired = fireNextItem( agendaFilter );
+ fired = fired || !((AbstractWorkingMemory) this.workingMemory).getActionQueue().isEmpty();
+ this.workingMemory.executeQueuedActions();
if ( !fired ) {
try {
synchronized ( this.halt ) {
@@ -1107,7 +1137,7 @@
private final int updateFireLimit(final int fireLimit) {
return fireLimit > 0 ? fireLimit - 1 : fireLimit;
}
-
+
public void notifyHalt() {
synchronized ( this.halt ) {
this.halt.notifyAll();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalAgenda.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalAgenda.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalAgenda.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -1,12 +1,16 @@
package org.drools.common;
import org.drools.Agenda;
+import org.drools.rule.GroupElement;
+import org.drools.rule.Rule;
import org.drools.spi.Activation;
import org.drools.spi.ActivationGroup;
import org.drools.spi.AgendaFilter;
import org.drools.spi.AgendaGroup;
import org.drools.spi.ConsequenceException;
+import org.drools.spi.PropagationContext;
import org.drools.spi.RuleFlowGroup;
+import org.drools.spi.Tuple;
public interface InternalAgenda
extends
@@ -21,6 +25,17 @@
public boolean fireNextItem(AgendaFilter filter) throws ConsequenceException;
public void scheduleItem(final ScheduledAgendaItem item);
+
+ public AgendaItem createAgendaItem(final Tuple tuple,
+ final int salience,
+ final PropagationContext context,
+ final Rule rule,
+ final GroupElement subrule);
+
+ public ScheduledAgendaItem createScheduledAgendaItem(final Tuple tuple,
+ final PropagationContext context,
+ final Rule rule,
+ final GroupElement subrule);
/**
* Adds the activation to the agenda. Depending on the mode the agenda is running,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalAgendaGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalAgendaGroup.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalAgendaGroup.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -12,5 +12,7 @@
public Activation[] getQueue();
- public void clear();
+ public void clear();
+
+ public void remove(AgendaItem agendaItem);
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/PriorityQueueAgendaGroupFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/PriorityQueueAgendaGroupFactory.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/PriorityQueueAgendaGroupFactory.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -20,6 +20,7 @@
}
public InternalAgendaGroup createAgendaGroup(String name, InternalRuleBase ruleBase) {
+// return new SimpleAgendaGroup(name, ruleBase);
return new BinaryHeapQueueAgendaGroup( name,
ruleBase );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupImpl.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupImpl.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -132,7 +132,7 @@
((EventSupport) this.workingMemory).getRuleFlowEventSupport().fireBeforeRuleFlowGroupDeactivated( this,
this.workingMemory );
final Iterator it = this.list.iterator();
- for ( RuleFlowGroupNode node = (RuleFlowGroupNode) it.next(); node != null; node = (RuleFlowGroupNode) it.next() ) {
+ for ( ActivationNode node = (ActivationNode) it.next(); node != null; node = (ActivationNode) it.next() ) {
final Activation activation = node.getActivation();
activation.remove();
if ( activation.getActivationGroupNode() != null ) {
@@ -163,7 +163,7 @@
private void triggerActivations() {
// iterate all activations adding them to their AgendaGroups
final Iterator it = this.list.iterator();
- for ( RuleFlowGroupNode node = (RuleFlowGroupNode) it.next(); node != null; node = (RuleFlowGroupNode) it.next() ) {
+ for ( ActivationNode node = (ActivationNode) it.next(); node != null; node = (ActivationNode) it.next() ) {
final Activation activation = node.getActivation();
((InternalAgendaGroup) activation.getAgendaGroup()).add( activation );
}
@@ -181,9 +181,9 @@
}
public void addActivation(final Activation activation) {
- final RuleFlowGroupNode node = new RuleFlowGroupNode( activation,
+ final ActivationNode node = new ActivationNode( activation,
this );
- activation.setRuleFlowGroupNode( node );
+ activation.setActivationNode( node );
this.list.add( node );
if ( this.active ) {
@@ -192,7 +192,7 @@
}
public void removeActivation(final Activation activation) {
- final RuleFlowGroupNode node = activation.getRuleFlowGroupNode();
+ final ActivationNode node = activation.getActivationNode();
this.list.remove( node );
activation.setActivationGroupNode( null );
if ( this.active && this.autoDeactivate ) {
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupNode.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupNode.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -1,44 +0,0 @@
-package org.drools.common;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.drools.spi.Activation;
-import org.drools.util.AbstractBaseLinkedListNode;
-
-public class RuleFlowGroupNode extends AbstractBaseLinkedListNode {
-
- private static final long serialVersionUID = 400L;
-
- private Activation activation;
- private InternalRuleFlowGroup ruleFlowGroup;
-
- public RuleFlowGroupNode(final Activation activation,
- final InternalRuleFlowGroup ruleFlowGroup) {
- super();
- this.activation = activation;
- this.ruleFlowGroup = ruleFlowGroup;
- }
-
- public Activation getActivation() {
- return this.activation;
- }
-
- public InternalRuleFlowGroup getRuleFlowGroup() {
- return this.ruleFlowGroup;
- }
-
-}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SimpleAgendaGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SimpleAgendaGroup.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SimpleAgendaGroup.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -0,0 +1,278 @@
+package org.drools.common;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.PriorityQueue;
+
+import org.drools.spi.Activation;
+import org.drools.util.AbstractBaseLinkedListNode;
+import org.drools.util.BinaryHeapQueue;
+import org.drools.util.LinkedList;
+import org.drools.util.Queueable;
+
+/**
+ * <code>AgendaGroup</code> implementation that uses a
+ * <code>ActivationQueue</code>s. The <code>AgendaGroup</code> also maintains a
+ * <code>Map</code> of <code>ActivationQueues</code> for requested salience
+ * values.
+ *
+ * @see PriorityQueue
+ * @see ActivationQueue
+ *
+ * @author <a href="mailto:mark.proctor at jboss.com">Mark Proctor</a>
+ * @author <a href="mailto:bob at werken.com">Bob McWhirter</a>
+ *
+ */
+public class SimpleAgendaGroup
+ implements
+ InternalAgendaGroup {
+
+ private static final long serialVersionUID = 400L;
+
+ private String name;
+
+ /** Items in the agenda. */
+ private LinkedList salienceGroups;
+
+ private int size;
+
+ private boolean active;
+
+ public static class SalienceGroup extends AbstractBaseLinkedListNode {
+ private int salience;
+ private LinkedList list;
+
+ public SalienceGroup(int salience) {
+ this.salience = salience;
+ this.list = new LinkedList();
+ }
+
+ public int getSalience() {
+ return salience;
+ }
+
+ public LinkedList getList() {
+ return this.list;
+ }
+ }
+
+ /**
+ * Construct an <code>AgendaGroup</code> with the given name.
+ *
+ * @param name
+ * The <AgendaGroup> name.
+ */
+ public SimpleAgendaGroup() {
+
+ }
+
+ public SimpleAgendaGroup(final String name,
+ final InternalRuleBase ruleBase) {
+ this.name = name;
+ this.salienceGroups = new LinkedList();
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ name = (String) in.readObject();
+ //queue = (BinaryHeapQueue) in.readObject();
+ active = in.readBoolean();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject( name );
+ //out.writeObject(queue);
+ out.writeBoolean( active );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.drools.spi.AgendaGroup#getName()
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ public void clear() {
+ this.salienceGroups.clear();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.drools.spi.AgendaGroup#size()
+ */
+ public int size() {
+ return this.size;
+ }
+
+ public void add(final Activation activation) {
+ int salience = activation.getSalience();
+ SalienceGroup group = null;
+
+ if ( !this.salienceGroups.isEmpty() ) {
+ SalienceGroup lastGroup = (SalienceGroup) this.salienceGroups.getLast();
+
+ // optimisation to find out it's the lowest, and thus add get or add it.
+ if ( salience <= lastGroup.getSalience() ) {
+ if ( salience == lastGroup.getSalience() ) {
+ // get
+ group = (SalienceGroup) lastGroup;
+ } else {
+ // create and add
+ SalienceGroup newGroup = new SalienceGroup( salience );
+ this.salienceGroups.insertAfter( lastGroup, newGroup );
+ group = newGroup;
+ }
+ //add or get to end
+ }
+
+
+ if ( group == null ) {
+ // we know this won't iterate to the end returning null, as we checked the end already.
+ for ( group = (SalienceGroup) this.salienceGroups.getFirst(); group != null && salience < group.getSalience(); group = (SalienceGroup) group.getNext() ) {
+ }
+
+ if ( salience == group.getSalience() ) {
+ // get
+ group = (SalienceGroup) group;
+ } else {
+ // create and add before, as must be larger
+ SalienceGroup newGroup = new SalienceGroup( salience );
+ this.salienceGroups.insertAfter( group.getPrevious(), newGroup );
+ group = newGroup;
+ }
+ }
+
+ } else {
+ //no groups so add
+ SalienceGroup newGroup = new SalienceGroup( salience );
+ this.salienceGroups.add( newGroup );
+ group = newGroup;
+ }
+
+ group.getList().add( new ActivationNode( activation,
+ this ) );
+
+ }
+
+ @Override
+ public void remove(AgendaItem agendaItem) {
+ int salience = agendaItem.getSalience();
+
+ SalienceGroup group = null;
+
+ SalienceGroup lastGroup = (SalienceGroup) this.salienceGroups.getLast();
+
+ // optimisation to find out it's the lowest, and thus add get or add it.
+ if ( salience == lastGroup.getSalience() ) {
+ group = lastGroup;
+ } else {
+ // don't check for !
+ for ( group = (SalienceGroup) this.salienceGroups.getFirst(); group != null && group.getSalience() != salience; group = (SalienceGroup) group.getNext() ) {
+ }
+ }
+
+ if ( group == null ) {
+ throw new RuntimeException( "SalienceGroup does not exist, This should not be possible." );
+ }
+
+ group.getList().remove( agendaItem.getActivationNode() );
+ }
+
+ public Activation getNext() {
+ SalienceGroup group = (SalienceGroup) this.salienceGroups.getFirst();
+
+ while ( !this.salienceGroups.isEmpty() && ( group == null || ( group != null && group.getList().isEmpty() ) ) ) {
+ this.salienceGroups.removeFirst();
+ group = (SalienceGroup) this.salienceGroups.getFirst();
+ }
+
+ if ( group != null ) {
+ ActivationNode node = (ActivationNode) group.getList().removeFirst();
+ if ( group.getList().isEmpty() ) {
+ this.salienceGroups.removeFirst();
+ }
+
+ return node.getActivation();
+
+ }
+
+ return null;
+ }
+
+ public boolean isActive() {
+ return this.active;
+ }
+
+ public void setActive(final boolean activate) {
+ this.active = activate;
+ }
+
+ /**
+ * Iterates a PriorityQueue removing empty entries until it finds a
+ * populated entry and return true, otherwise it returns false;
+ *
+ * @param priorityQueue
+ * @return
+ */
+ public boolean isEmpty() {
+ return this.salienceGroups.isEmpty();
+ }
+
+ public Activation[] getActivations() {
+ return null;
+ // return (Activation[]) this.queue.toArray(new AgendaItem[this.queue
+ // .size()]);
+ }
+
+ public Activation[] getQueue() {
+ return null;
+ //return this.queue.getQueueable();
+ }
+
+ public String toString() {
+ return "AgendaGroup '" + this.name + "'";
+ }
+
+ public boolean equal(final Object object) {
+ if ( (object == null) || !(object instanceof SimpleAgendaGroup) ) {
+ return false;
+ }
+
+ if ( ((SimpleAgendaGroup) object).name.equals( this.name ) ) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public int hashCode() {
+ return this.name.hashCode();
+ }
+
+ public void setFocus() {
+ throw new UnsupportedOperationException();
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/conflict/DepthConflictResolver.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/conflict/DepthConflictResolver.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/conflict/DepthConflictResolver.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -26,7 +26,7 @@
public static ConflictResolver getInstance() {
return DepthConflictResolver.INSTANCE;
}
-
+
/**
* @see ConflictResolver
*/
@@ -34,36 +34,20 @@
final Object adding) {
return compare( (Activation) existing,
(Activation) adding );
- }
+ }
- public int compare(final Activation lhs,
- final Activation rhs) {
- final int s1 = lhs.getSalience();
- final int s2 = rhs.getSalience();
-
- if ( s1 > s2 ) {
- return -1;
- } else if ( s1 < s2 ) {
- return 1;
+ public final int compare(final Activation existing,
+ final Activation adding) {
+ final int s1 = existing.getSalience();
+ final int s2 = adding.getSalience();
+
+ if ( s1 != s2 ) {
+ return s1 - s2;
}
- final long p1 = lhs.getPropagationContext().getPropagationNumber();
- final long p2 = rhs.getPropagationContext().getPropagationNumber();
- if ( p1 != p2 ) {
- return (int) (p2 - p1);
- }
- final long r1 = lhs.getTuple().getRecency();
- final long r2 = rhs.getTuple().getRecency();
-
- if ( r1 != r2 ) {
- return (int) (r2 - r1);
- }
-
- final long l1 = lhs.getRule().getLoadOrder();
- final long l2 = rhs.getRule().getLoadOrder();
-
- return (int) (l2 - l1);
+ // we know that no two activations will have the same number
+ return (int) ( existing.getActivationNumber() - adding.getActivationNumber() );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/conflict/TotalRecencyConflictResolver.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/conflict/TotalRecencyConflictResolver.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/conflict/TotalRecencyConflictResolver.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -73,12 +73,12 @@
final Activation rhs) {
long leftRecency = 0;
long rightRecency = 0;
- if ( lhs.getTuple() instanceof LeftTuple ) {
- leftRecency = (lhs.getTuple()).getRecency();
- }
- if ( rhs.getTuple() instanceof LeftTuple ) {
- rightRecency = (rhs.getTuple()).getRecency();
- }
+// if ( lhs.getTuple() instanceof LeftTuple ) {
+// leftRecency = (lhs.getTuple()).getRecency();
+// }
+// if ( rhs.getTuple() instanceof LeftTuple ) {
+// rightRecency = (rhs.getTuple()).getRecency();
+// }
return (rightRecency > leftRecency) ? 1 : (rightRecency < leftRecency) ? -1 : 0;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -101,7 +101,7 @@
workingMemory,
leftTuple );
- for ( RightTuple rightTuple = memory.getRightTupleMemory().getLast( leftTuple ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getPrevious() ) {
+ for ( RightTuple rightTuple = memory.getRightTupleMemory().getFirst( leftTuple ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
rightTuple.getFactHandle() ) ) {
@@ -274,7 +274,7 @@
//
// this.constraints.resetFactHandle( memory.getContext() );
// assign now, so we can remove from memory before doing any possible propagations
- final RightTuple rootBlocker = (RightTuple) rightTuple.getPrevious();
+ final RightTuple rootBlocker = (RightTuple) rightTuple.getNext();
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
behavior.retractRightTuple( memory.getBehaviorContext(),
@@ -298,7 +298,7 @@
leftTuple );
// we know that older tuples have been checked so continue previously
- for ( RightTuple newBlocker = rootBlocker; newBlocker != null; newBlocker = (RightTuple) newBlocker.getPrevious() ) {
+ for ( RightTuple newBlocker = rootBlocker; newBlocker != null; newBlocker = (RightTuple) newBlocker.getNext() ) {
if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
newBlocker.getFactHandle() ) ) {
leftTuple.setBlocker( newBlocker );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -123,6 +123,39 @@
this.constraints.resetTuple( memory.getContext() );
}
+
+// public void assertLeftTuple(final LeftTuple leftTuple,
+// RightTuple rightTuple,
+// final PropagationContext context,
+// final InternalWorkingMemory workingMemory) {
+// final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+//
+// if ( this.tupleMemoryEnabled ) {
+// memory.getLeftTupleMemory().add( leftTuple );
+// }
+//
+// this.constraints.updateFromTuple( memory.getContext(),
+// workingMemory,
+// leftTuple );
+// if ( rightTuple == null ) {
+// rightTuple = memory.getRightTupleMemory().getFirst( leftTuple );
+// }
+//
+// boolean suspend = false;
+// for ( ;rightTuple != null && !suspend; rightTuple = (RightTuple) rightTuple.getNext() ) {
+// final InternalFactHandle handle = rightTuple.getFactHandle();
+// if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
+// handle ) ) {
+// this.sink.propagateAssertLeftTuple( leftTuple,
+// rightTuple,
+// context,
+// workingMemory,
+// this.tupleMemoryEnabled );
+// }
+// }
+//
+// this.constraints.resetTuple( memory.getContext() );
+// }
/**
* Assert a new <code>FactHandleImpl</code>. The left input of
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -21,10 +21,6 @@
private Activation activation;
- private long recency;
-
- private int hashCode;
-
private RightTuple blocker;
private LeftTuple blockedPrevious;
@@ -61,10 +57,7 @@
LeftTupleSink sink,
boolean leftTupleMemoryEnabled) {
this.handle = factHandle;
- this.recency = factHandle.getRecency();
- this.hashCode = handle.hashCode();
-
if ( leftTupleMemoryEnabled ) {
LeftTuple currentFirst = handle.getLeftTuple();
if ( currentFirst != null ) {
@@ -82,9 +75,7 @@
boolean leftTupleMemoryEnabled) {
this.index = leftTuple.index;
this.parent = leftTuple.parent;
- this.recency = leftTuple.recency;
this.handle = leftTuple.handle;
- this.hashCode = leftTuple.hashCode();
if ( leftTupleMemoryEnabled ) {
this.leftParent = leftTuple;
@@ -105,8 +96,6 @@
this.handle = rightTuple.getFactHandle();
this.index = leftTuple.index + 1;
this.parent = leftTuple;
- this.recency = leftTuple.recency + this.handle.getRecency();
- this.hashCode = leftTuple.hashCode ^ (handle.hashCode() * 31);
if ( leftTupleMemoryEnabled ) {
this.rightParent = rightTuple;
@@ -326,11 +315,7 @@
entry = entry.parent;
}
return handles;
- }
-
- public long getRecency() {
- return this.recency;
- }
+ }
public void setBlocker(RightTuple blocker) {
this.blocker = blocker;
@@ -360,9 +345,9 @@
this.activation = activation;
}
- public int hashCode() {
- return this.hashCode;
- }
+// public int hashCode() {
+// return this.hashCode;
+// }
public String toString() {
final StringBuilder buffer = new StringBuilder();
@@ -376,6 +361,10 @@
return buffer.toString();
}
+
+ public int hashCode() {
+ return this.handle.hashCode();
+ }
/**
* We use this equals method to avoid the cast
* @param tuple
@@ -388,7 +377,7 @@
}
// A LeftTuple is only the same if it has the same hashCode, factId and parent
- if ( this.hashCode != other.hashCode ) {
+ if ( this.hashCode() != other.hashCode() ) {
return false;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -99,7 +99,7 @@
workingMemory,
leftTuple );
- for ( RightTuple rightTuple = memory.getRightTupleMemory().getLast( leftTuple ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getPrevious() ) {
+ for ( RightTuple rightTuple = memory.getRightTupleMemory().getFirst( leftTuple ); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
rightTuple.getFactHandle() ) ) {
leftTuple.setBlocker( rightTuple );
@@ -205,7 +205,7 @@
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
// assign now, so we can remove from memory before doing any possible propagations
- final RightTuple rootBlocker = (RightTuple) rightTuple.getPrevious();
+ final RightTuple rootBlocker = (RightTuple) rightTuple.getNext();
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
behavior.retractRightTuple( memory.getBehaviorContext(),
@@ -228,8 +228,8 @@
workingMemory,
leftTuple );
- // we know that older tuples have been checked so continue previously
- for ( RightTuple newBlocker = rootBlocker; newBlocker != null; newBlocker = (RightTuple) newBlocker.getPrevious() ) {
+ // we know that older tuples have been checked so continue next
+ for ( RightTuple newBlocker = rootBlocker; newBlocker != null; newBlocker = (RightTuple) newBlocker.getNext() ) {
if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
newBlocker.getFactHandle() ) ) {
leftTuple.setBlocker( newBlocker );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RightTuple.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -23,8 +23,6 @@
private RightTupleSink sink;
- private int hashCode;
-
public RightTuple() {
}
@@ -32,7 +30,6 @@
public RightTuple(InternalFactHandle handle,
RightTupleSink sink) {
this.handle = handle;
- this.hashCode = this.handle.hashCode();
this.sink = sink;
RightTuple currentFirst = handle.getRightTuple();
@@ -154,16 +151,8 @@
this.betaChildren = betachildren;
}
- public int getHashCode() {
- return hashCode;
- }
-
- public void setHashCode(int hashCode) {
- this.hashCode = hashCode;
- }
-
public int hashCode() {
- return this.hashCode;
+ return this.handle.hashCode();
}
public String toString() {
@@ -177,7 +166,7 @@
}
// A ReteTuple is only the same if it has the same hashCode, factId and parent
- if ( (other == null) || (this.hashCode != other.hashCode) ) {
+ if ( (other == null) || (hashCode() != other.hashCode()) ) {
return false;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -60,13 +60,13 @@
// Instance members
// ------------------------------------------------------------
- private int sequence = -1; // -1 means not set
+ private int sequence = -1; // -1 means not set
/**
*
*/
private static final long serialVersionUID = 400L;
-
+
/** The rule to invoke upon match. */
private Rule rule;
/**
@@ -121,7 +121,7 @@
subrule = (GroupElement) in.readObject();
tupleSource = (LeftTupleSource) in.readObject();
previousTupleSinkNode = (LeftTupleSinkNode) in.readObject();
- nextTupleSinkNode = (LeftTupleSinkNode) in.readObject();
+ nextTupleSinkNode = (LeftTupleSinkNode) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
@@ -142,7 +142,7 @@
public Rule getRule() {
return this.rule;
}
-
+
public GroupElement getSubRule() {
return this.subrule;
}
@@ -163,9 +163,9 @@
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
assertLeftTuple( tuple,
- context,
- workingMemory,
- true );
+ context,
+ workingMemory,
+ true );
}
@@ -180,11 +180,13 @@
* If an error occurs while asserting.
*/
public void assertLeftTuple(final LeftTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory,
- final boolean fireActivationCreated) {
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory,
+ final boolean fireActivationCreated) {
//check if the rule is effective
- if ( !this.rule.isEffective( workingMemory.getTimeMachine(), tuple, workingMemory ) ) {
+ if ( !this.rule.isEffective( workingMemory.getTimeMachine(),
+ tuple,
+ workingMemory ) ) {
return;
}
@@ -197,21 +199,15 @@
return;
}
- //we only have to clone the head fact to make sure the graph is not affected during consequence reads after a modify
- // @FIXME
- final LeftTuple cloned = tuple;//new LeftTuple( tuple );
-
final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
final Duration dur = this.rule.getDuration();
if ( dur != null && dur.getDuration( tuple ) > 0 ) {
- final ScheduledAgendaItem item = new ScheduledAgendaItem( context.getPropagationNumber(),
- cloned,
- agenda,
- context,
- this.rule,
- this.subrule );
+ final ScheduledAgendaItem item = agenda.createScheduledAgendaItem( tuple,
+ context,
+ this.rule,
+ this.subrule );
final TerminalNodeMemory memory = (TerminalNodeMemory) workingMemory.getNodeMemory( this );
agenda.scheduleItem( item );
@@ -231,19 +227,18 @@
// ----------------
final TerminalNodeMemory memory = (TerminalNodeMemory) workingMemory.getNodeMemory( this );
- final AgendaItem item = new AgendaItem( context.getPropagationNumber(),
- cloned,
- rule.getSalience().getValue( tuple,
- workingMemory ),
- context,
- this.rule,
- this.subrule );
+ final AgendaItem item = agenda.createAgendaItem( tuple,
+ rule.getSalience().getValue( tuple,
+ workingMemory ),
+ context,
+ this.rule,
+ this.subrule );
item.setSequenence( this.sequence );
tuple.setActivation( item );
memory.getTupleMemory().add( tuple );
-
+
boolean added = agenda.addActivation( item );
item.setActivated( added );
@@ -265,12 +260,12 @@
memory.getTupleMemory().remove( leftTuple );
final Activation activation = leftTuple.getActivation();
-
+
// activation can be null if the LeftTuple previous propagated into a no-loop
if ( activation == null ) {
return;
}
-
+
if ( activation.getLogicalDependencies() != null && !activation.getLogicalDependencies().isEmpty() ) {
context.addRetractedTuple( this.rule,
activation );
@@ -287,7 +282,7 @@
}
// on fact expiration, we don't remove the activation, but let it fire
- if( context.getType() == PropagationContext.EXPIRATION && context.getFactHandleOrigin() != null ) {
+ if ( context.getType() == PropagationContext.EXPIRATION && context.getFactHandleOrigin() != null ) {
EventFactHandle efh = (EventFactHandle) context.getFactHandleOrigin();
efh.increaseActivationsCount();
} else {
@@ -297,8 +292,8 @@
activation.getActivationGroupNode().getActivationGroup().removeActivation( activation );
}
- if ( activation.getRuleFlowGroupNode() != null ) {
- final InternalRuleFlowGroup ruleFlowGroup = activation.getRuleFlowGroupNode().getRuleFlowGroup();
+ if ( activation.getActivationNode() != null ) {
+ final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) activation.getActivationNode().getParentContainer();
ruleFlowGroup.removeActivation( activation );
}
@@ -458,23 +453,23 @@
final RuleTerminalNode other = (RuleTerminalNode) object;
return this.rule.equals( other.rule );
}
-
+
public short getType() {
return NodeTypeEnums.RuleTerminalNode;
- }
+ }
public static class TerminalNodeMemory
implements
Externalizable {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
-// private InternalAgendaGroup agendaGroup;
-//
-// private ActivationGroup activationGroup;
-//
-// private RuleFlowGroup ruleFlowGroup;
+ // private InternalAgendaGroup agendaGroup;
+ //
+ // private ActivationGroup activationGroup;
+ //
+ // private RuleFlowGroup ruleFlowGroup;
- private LeftTupleList tupleMemory;
+ private LeftTupleList tupleMemory;
public TerminalNodeMemory() {
this.tupleMemory = new LeftTupleList();
@@ -482,45 +477,45 @@
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
-// agendaGroup = (InternalAgendaGroup) in.readObject();
-// activationGroup = (ActivationGroup) in.readObject();
-// ruleFlowGroup = (RuleFlowGroup) in.readObject();
+ // agendaGroup = (InternalAgendaGroup) in.readObject();
+ // activationGroup = (ActivationGroup) in.readObject();
+ // ruleFlowGroup = (RuleFlowGroup) in.readObject();
tupleMemory = (LeftTupleList) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
-// out.writeObject( agendaGroup );
-// out.writeObject( activationGroup );
-// out.writeObject( ruleFlowGroup );
+ // out.writeObject( agendaGroup );
+ // out.writeObject( activationGroup );
+ // out.writeObject( ruleFlowGroup );
out.writeObject( tupleMemory );
}
-// public InternalAgendaGroup getAgendaGroup() {
-// return this.agendaGroup;
-// }
-//
-// public void setAgendaGroup(final InternalAgendaGroup agendaGroup) {
-// this.agendaGroup = agendaGroup;
-// }
-//
-// public ActivationGroup getActivationGroup() {
-// return this.activationGroup;
-// }
-//
-// public void setActivationGroup(final ActivationGroup activationGroup) {
-// this.activationGroup = activationGroup;
-// }
+ // public InternalAgendaGroup getAgendaGroup() {
+ // return this.agendaGroup;
+ // }
+ //
+ // public void setAgendaGroup(final InternalAgendaGroup agendaGroup) {
+ // this.agendaGroup = agendaGroup;
+ // }
+ //
+ // public ActivationGroup getActivationGroup() {
+ // return this.activationGroup;
+ // }
+ //
+ // public void setActivationGroup(final ActivationGroup activationGroup) {
+ // this.activationGroup = activationGroup;
+ // }
public LeftTupleList getTupleMemory() {
return this.tupleMemory;
}
-// public RuleFlowGroup getRuleFlowGroup() {
-// return this.ruleFlowGroup;
-// }
-//
-// public void setRuleFlowGroup(final RuleFlowGroup ruleFlowGroup) {
-// this.ruleFlowGroup = ruleFlowGroup;
-// }
+ // public RuleFlowGroup getRuleFlowGroup() {
+ // return this.ruleFlowGroup;
+ // }
+ //
+ // public void setRuleFlowGroup(final RuleFlowGroup ruleFlowGroup) {
+ // this.ruleFlowGroup = ruleFlowGroup;
+ // }
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Activation.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Activation.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Activation.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -20,7 +20,7 @@
import org.drools.common.ActivationGroupNode;
import org.drools.common.LogicalDependency;
-import org.drools.common.RuleFlowGroupNode;
+import org.drools.common.ActivationNode;
import org.drools.rule.GroupElement;
import org.drools.rule.Rule;
import org.drools.util.LinkedList;
@@ -101,8 +101,8 @@
public void setActivationGroupNode(ActivationGroupNode activationGroupNode);
- public RuleFlowGroupNode getRuleFlowGroupNode();
+ public ActivationNode getActivationNode();
- public void setRuleFlowGroupNode(RuleFlowGroupNode ruleFlowGroupNode);
+ public void setActivationNode(ActivationNode ruleFlowGroupNode);
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/RuleFlowGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/RuleFlowGroup.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/RuleFlowGroup.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -19,13 +19,13 @@
import java.io.Externalizable;
import java.util.Iterator;
-import org.drools.common.RuleFlowGroupNode;
+import org.drools.common.ActivationNode;
public interface RuleFlowGroup extends org.drools.runtime.rule.RuleFlowGroup {
String getName();
- public Iterator<RuleFlowGroupNode> iterator();
+ public Iterator<ActivationNode> iterator();
boolean isEmpty();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Tuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Tuple.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Tuple.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -60,12 +60,6 @@
InternalFactHandle[] getFactHandles();
/**
- * Returns the tuple recency
- * @return
- */
- long getRecency();
-
- /**
* Returns the size of this tuple in number of elements (patterns)
* @return
*/
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/BinaryHeapQueue.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/BinaryHeapQueue.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/BinaryHeapQueue.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -134,7 +134,7 @@
grow();
}
- percolateUpMinHeap( element );
+ percolateUpMaxHeap( element );
}
/**
@@ -186,86 +186,154 @@
this.elements[index / 2] );
}
if ( index > 1 && compareToParent < 0 ) {
- percolateUpMinHeap( index );
+ percolateUpMaxHeap( index );
} else {
- percolateDownMinHeap( index );
+ percolateDownMaxHeap( index );
}
}
return result;
}
+// /**
+// * Percolates Queueable down heap from the position given by the index.
+// * <p/>
+// * Assumes it is a minimum heap.
+// *
+// * @param index the index for the Queueable
+// */
+// private void percolateDownMinHeap(final int index) {
+// final Queueable element = this.elements[index];
+// int hole = index;
+//
+// while ( (hole * 2) <= this.size ) {
+// int child = hole * 2;
+//
+// // if we have a right child and that child can not be percolated
+// // up then move onto other child
+// if ( child != this.size && compare( this.elements[child + 1],
+// this.elements[child] ) < 0 ) {
+// child++;
+// }
+//
+// // if we found resting place of bubble then terminate search
+// if ( compare( this.elements[child],
+// element ) >= 0 ) {
+// break;
+// }
+//
+// setElement( hole,
+// this.elements[child] );
+// hole = child;
+// }
+//
+// setElement( hole,
+// element );
+// }
+//
+// /**
+// * Percolates Queueable up heap from the position given by the index.
+// * <p/>
+// * Assumes it is a minimum heap.
+// *
+// * @param index the index of the Queueable to be percolated up
+// */
+// private void percolateUpMinHeap(final int index) {
+// int hole = index;
+// final Queueable element = this.elements[hole];
+// while ( hole > 1 && compare( element,
+// this.elements[hole / 2] ) < 0 ) {
+// // save Queueable that is being pushed down
+// // as the Queueable "bubble" is percolated up
+// final int next = hole / 2;
+// setElement( hole,
+// this.elements[next] );
+// hole = next;
+// }
+// setElement( hole,
+// element );
+// }
+//
+// /**
+// * Percolates a new Queueable up heap from the bottom.
+// * <p/>
+// * Assumes it is a minimum heap.
+// *
+// * @param element the Queueable
+// */
+// private void percolateUpMinHeap(final Queueable element) {
+// setElement( ++this.size,
+// element );
+// percolateUpMinHeap( this.size );
+// }
+
/**
- * Percolates Queueable down heap from the position given by the index.
- * <p/>
- * Assumes it is a minimum heap.
+ * Percolates element down heap from the position given by the index.
+ * <p>
+ * Assumes it is a maximum heap.
*
- * @param index the index for the Queueable
+ * @param index the index of the element
*/
- private void percolateDownMinHeap(final int index) {
- final Queueable element = this.elements[index];
+ protected void percolateDownMaxHeap(final int index) {
+ final Queueable element = elements[index];
int hole = index;
- while ( (hole * 2) <= this.size ) {
+ while ((hole * 2) <= size) {
int child = hole * 2;
// if we have a right child and that child can not be percolated
// up then move onto other child
- if ( child != this.size && compare( this.elements[child + 1],
- this.elements[child] ) < 0 ) {
+ if (child != size && compare(elements[child + 1], elements[child]) > 0) {
child++;
}
// if we found resting place of bubble then terminate search
- if ( compare( this.elements[child],
- element ) >= 0 ) {
+ if (compare(elements[child], element) <= 0) {
break;
}
- setElement( hole,
- this.elements[child] );
+ setElement( hole, elements[child] );
hole = child;
}
- setElement( hole,
- element );
+ setElement( hole, element);
}
-
+
+
/**
- * Percolates Queueable up heap from the position given by the index.
- * <p/>
- * Assumes it is a minimum heap.
+ * Percolates element up heap from from the position given by the index.
+ * <p>
+ * Assume it is a maximum heap.
*
- * @param index the index of the Queueable to be percolated up
+ * @param index the index of the element to be percolated up
*/
- private void percolateUpMinHeap(final int index) {
+ protected void percolateUpMaxHeap(final int index) {
int hole = index;
- final Queueable element = this.elements[hole];
- while ( hole > 1 && compare( element,
- this.elements[hole / 2] ) < 0 ) {
- // save Queueable that is being pushed down
- // as the Queueable "bubble" is percolated up
+ Queueable element = elements[hole];
+
+ while (hole > 1 && compare(element, elements[hole / 2]) > 0) {
+ // save element that is being pushed down
+ // as the element "bubble" is percolated up
final int next = hole / 2;
- setElement( hole,
- this.elements[next] );
+ setElement( hole, elements[next] );
hole = next;
}
- setElement( hole,
- element );
+
+ setElement( hole, element );
}
/**
- * Percolates a new Queueable up heap from the bottom.
- * <p/>
- * Assumes it is a minimum heap.
+ * Percolates a new element up heap from the bottom.
+ * <p>
+ * Assume it is a maximum heap.
*
- * @param element the Queueable
+ * @param element the element
*/
- private void percolateUpMinHeap(final Queueable element) {
- setElement( ++this.size,
- element );
- percolateUpMinHeap( this.size );
+ protected void percolateUpMaxHeap(final Queueable element) {
+ setElement( ++size, element );
+ percolateUpMaxHeap(size);
}
+
/**
* Compares two objects using the comparator if specified, or the
@@ -302,8 +370,7 @@
private void setElement(final int index,
final Queueable element) {
this.elements[index] = element;
- element.enqueued( this,
- index );
+ element.enqueued( index );
}
public Queueable[] getQueueable() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LeftTupleList.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LeftTupleList.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/LeftTupleList.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -18,6 +18,7 @@
public Entry next;
public LeftTuple first;
+ public LeftTuple last;
private int hashCode;
private Index index;
@@ -41,15 +42,21 @@
public LeftTuple getFirst(RightTuple rightTuple) {
return this.first;
}
+
+ public LeftTuple getLast(RightTuple lastTuple) {
+ return this.first;
+ }
public void add(final LeftTuple leftTuple) {
- if ( this.first != null ) {
- leftTuple.setNext( this.first );
- this.first.setPrevious( leftTuple );
+ if ( this.last != null ) {
+ this.last.setNext( leftTuple );
+ leftTuple.setPrevious( this.last );
+ this.last = leftTuple;
+ } else {
+ this.first = leftTuple;
+ this.last = leftTuple;;
}
- this.first = leftTuple;
-
this.size++;
}
@@ -58,20 +65,23 @@
LeftTuple next = (LeftTuple) leftTuple.getNext();
if ( previous != null && next != null ) {
- //remove from middle
+ // remove from middle
previous.setNext( next );
next.setPrevious( previous );
} else if ( next != null ) {
- //remove from first
+ // remove from first
this.first = next;
next.setPrevious( null );
} else if ( previous != null ) {
- //remove from end
+ // remove from end
+ this.last = previous;
previous.setNext( null );
} else {
+ // remove everything
+ this.last = null;
this.first = null;
}
-
+
leftTuple.setPrevious( null );
leftTuple.setNext( null );
@@ -178,14 +188,6 @@
this.next = next;
}
- public Entry getPrevious() {
- return null;
- }
-
- public void setPrevious(Entry previous) {
- // this.previous = previous;
- }
-
public String toString() {
StringBuilder builder = new StringBuilder();
Iterator it = iterator();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/Queueable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/Queueable.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/Queueable.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -19,8 +19,7 @@
*/
public interface Queueable extends Activation {
- public void enqueued(Queue queue,
- int index);
+ public void enqueued(int index);
public void dequeue();
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/RightTupleList.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/RightTupleList.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/RightTupleList.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -47,10 +47,10 @@
}
public void add(final RightTuple rightTuple) {
- if ( this.first != null ) {
- this.first.setPrevious( rightTuple );
- rightTuple.setNext( this.first );
- this.first = rightTuple;
+ if ( this.last != null ) {
+ this.last.setNext( rightTuple );
+ rightTuple.setPrevious( this.last );
+ this.last = rightTuple;
} else {
this.first = rightTuple;
this.last = rightTuple;;
@@ -81,6 +81,9 @@
this.last = null;
this.first = null;
}
+
+ rightTuple.setPrevious( null );
+ rightTuple.setNext( null );
}
public RightTuple get(final InternalFactHandle handle) {
@@ -177,15 +180,6 @@
return this.hashCode == other.hashCode && this.index == other.index;
}
- public Entry getPrevious() {
- return null;
- // return this.previous;
- }
-
- public void setPrevious(Entry previous) {
- // this.previous = previous;
- }
-
public Entry getNext() {
return this.next;
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -138,10 +138,10 @@
this.pkg.addRule( getAssignFirstSeatRule() );
this.pkg.addRule( getFindSeating() );
+ this.pkg.addRule( getMakePath() );
this.pkg.addRule( getPathDone() );
- this.pkg.addRule( getMakePath() );
- this.pkg.addRule( getContinueProcessing() );
- this.pkg.addRule( getAreWeDone() );
+ this.pkg.addRule( getContinueProcessing() );
+ this.pkg.addRule( getAreWeDone() );
this.pkg.addRule( getAllDone() );
}
@@ -549,7 +549,7 @@
drools.update( tuple.get( contextDeclaration ),
context );
- // System.err.println( "find seating : " + seating + " : " + path + " : " + chosen );
+ System.err.println( "find seating : " + seating + " : " + path + " : " + chosen );
} catch ( Exception e ) {
e.printStackTrace();
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -56,6 +56,7 @@
import org.drools.spi.KnowledgeHelper;
import org.drools.spi.PropagationContext;
import org.drools.spi.RuleFlowGroup;
+import org.drools.spi.Salience;
/**
* @author mproctor
@@ -751,6 +752,7 @@
null );
final Rule rule2 = new Rule( "test-rule2" );
+ rule2.setSalience( new SalienceInteger( -5 ) );
final RuleTerminalNode node2 = new RuleTerminalNode( 7,
new MockTupleSource( 6 ),
rule2,
@@ -765,6 +767,7 @@
final Rule rule3 = new Rule( "test-rule3",
"agendaGroup3" );
+ rule3.setSalience( new SalienceInteger( -10 ) );
rule3.setActivationGroup( "activation-group-3" );
final RuleTerminalNode node3 = new RuleTerminalNode( 9,
new MockTupleSource( 8 ),
@@ -825,7 +828,7 @@
// List should only have a single item, "rule0"
assertEquals( 1,
list.size() );
- assertSame( rule0,
+ assertSame( rule1,
list.get( 0 ) );
list.clear();
@@ -877,7 +880,7 @@
assertEquals( 2,
list.size() );
- assertEquals( rule0,
+ assertEquals( rule1,
list.get( 0 ) );
assertEquals( rule2,
list.get( 1 ) );
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -220,9 +220,9 @@
this.memory.getLeftTupleMemory().size() );
LeftTuple leftTuple = this.memory.getLeftTupleMemory().getFirst( null );
+ assertEquals( tuple0,
+ leftTuple );
assertEquals( tuple1,
- leftTuple );
- assertEquals( tuple0,
leftTuple.getNext() );
}
@@ -330,8 +330,8 @@
this.node,
true ) );
- final InternalFactHandle rf1 = rightTuple.getFactHandle();
- final InternalFactHandle rf0 = ((RightTuple) rightTuple.getNext()).getFactHandle();
+ final InternalFactHandle rf0 = rightTuple.getFactHandle();
+ final InternalFactHandle rf1 = ((RightTuple) rightTuple.getNext()).getFactHandle();
assertEquals( f0,
rf0 );
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -191,13 +191,13 @@
QueryResult result = results.get( 0 );
assertEquals( 1,
result.size() );
- assertEquals( stilton2,
+ assertEquals( stilton1,
result.get( 0 ) );
result = results.get( 1 );
assertEquals( 1,
result.size() );
- assertEquals( stilton1,
+ assertEquals( stilton2,
result.get( 0 ) );
int i = 0;
@@ -206,10 +206,10 @@
assertEquals( 1,
result.size() );
if ( i == 1 ) {
- assertSame( stilton1,
+ assertSame( stilton2,
result.get( 0 ) );
} else {
- assertSame( stilton2,
+ assertSame( stilton1,
result.get( 0 ) );
}
i++;
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BaseQueueable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BaseQueueable.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BaseQueueable.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -4,7 +4,7 @@
import org.drools.common.ActivationGroupNode;
import org.drools.common.LogicalDependency;
-import org.drools.common.RuleFlowGroupNode;
+import org.drools.common.ActivationNode;
import org.drools.rule.GroupElement;
import org.drools.rule.Rule;
import org.drools.FactHandle;
@@ -33,10 +33,12 @@
Queueable {
private Queue queue;
private int index;
+
+ public BaseQueueable(Queue queue) {
+ this.queue = queue;
+ }
- public void enqueued(final Queue queue,
- final int index) {
- this.queue = queue;
+ public void enqueued(final int index) {
this.index = index;
}
@@ -79,7 +81,7 @@
return null;
}
- public RuleFlowGroupNode getRuleFlowGroupNode() {
+ public ActivationNode getActivationNode() {
// TODO Auto-generated method stub
return null;
}
@@ -124,7 +126,7 @@
}
- public void setRuleFlowGroupNode(RuleFlowGroupNode ruleFlowGroupNode) {
+ public void setActivationNode(ActivationNode ruleFlowGroupNode) {
// TODO Auto-generated method stub
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BinaryHeapPriorityQueueTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BinaryHeapPriorityQueueTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/BinaryHeapPriorityQueueTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -32,7 +32,7 @@
100000 );
for ( int i = 0; i < 100000; ++i ) {
- items.add( new LongQueueable( random.nextLong() ) );
+ items.add( new LongQueueable( queue, random.nextLong() ) );
}
final long startEnqueue = System.currentTimeMillis();
@@ -67,7 +67,7 @@
100000 );
for ( int i = 0; i < 100000; ++i ) {
- items.add( new LongQueueable( random.nextLong() ) );
+ items.add( new LongQueueable( queue, random.nextLong() ) );
}
final long startEnqueue = System.currentTimeMillis();
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -98,9 +98,9 @@
// test add
index.add( h1RightTuple );
index.add( h2RightTuple );
+ assertEquals( h1,
+ index.first.getFactHandle() );
assertEquals( h2,
- index.first.getFactHandle() );
- assertEquals( h1,
((RightTuple) index.first.getNext()).getFactHandle() );
// test get
@@ -159,11 +159,11 @@
index.add( h1RightTuple );
index.add( h2RightTuple );
index.add( h3RightTuple );
- assertEquals( h3,
+ assertEquals( h1,
index.first.getFactHandle() );
assertEquals( h2,
((RightTuple) index.first.getNext()).getFactHandle() );
- assertEquals( h1,
+ assertEquals( h3,
((RightTuple) index.first.getNext().getNext()).getFactHandle() );
// test get
@@ -177,23 +177,23 @@
// test removal for combinations
//remove first
index.remove( h3RightTuple );
+ assertEquals( h1,
+ index.first.getFactHandle() );
assertEquals( h2,
- index.first.getFactHandle() );
- assertEquals( h1,
((RightTuple) index.first.getNext()).getFactHandle() );
index.add( h3RightTuple );
index.remove( h2RightTuple );
+ assertEquals( h1,
+ index.first.getFactHandle() );
assertEquals( h3,
- index.first.getFactHandle() );
- assertEquals( h1,
((RightTuple) index.first.getNext()).getFactHandle() );
index.add( h2RightTuple );
index.remove( h1RightTuple );
+ assertEquals( h3,
+ index.first.getFactHandle() );
assertEquals( h2,
- index.first.getFactHandle() );
- assertEquals( h3,
((RightTuple) index.first.getNext()).getFactHandle() );
index.remove( index.first );
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/LongQueueable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/LongQueueable.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/LongQueueable.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -21,7 +21,9 @@
Comparable {
private final Long value;
- public LongQueueable(final long value) {
+ public LongQueueable(Queue queue,
+ final long value) {
+ super( queue );
this.value = new Long( value );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/RightTupleIndexHashTableTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/RightTupleIndexHashTableTest.java 2009-08-10 17:16:19 UTC (rev 28892)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/RightTupleIndexHashTableTest.java 2009-08-11 00:41:16 UTC (rev 28893)
@@ -209,9 +209,9 @@
final RightTupleList list = map.get( new LeftTuple( stiltonHandle3,
null,
true ) );
+ assertSame( stiltonHandle1,
+ list.first.getFactHandle() );
assertSame( stiltonHandle2,
- list.first.getFactHandle() );
- assertSame( stiltonHandle1,
((RightTuple) list.first.getNext()).getFactHandle() );
}
More information about the jboss-svn-commits
mailing list