[jboss-svn-commits] JBL Code SVN: r6641 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: reteoo spi util
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Oct 6 07:22:44 EDT 2006
Author: mark.proctor at jboss.com
Date: 2006-10-06 07:22:41 -0400 (Fri, 06 Oct 2006)
New Revision: 6641
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TerminalNode.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/ObjectHashMap.java
Log:
JBRULES-498 Optimised HashMap implementations
-TerminalNode now works, notice there is no test for it though?
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java 2006-10-06 11:20:37 UTC (rev 6640)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java 2006-10-06 11:22:41 UTC (rev 6641)
@@ -149,20 +149,20 @@
public void remove(final BaseNode node,
final InternalWorkingMemory[] workingMemories) {
- // if( !node.isInUse()) {
- // getTupleSinks().remove( node );
- // }
- // removeShare();
- //
- // if ( ! this.isInUse() ) {
- // for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
- // workingMemories[i].clearNodeMemory( this );
- // }
- // }
- // this.rightInput.remove( this,
- // workingMemories );
- // this.leftInput.remove( this,
- // workingMemories );
+ if( !node.isInUse()) {
+ removeTupleSink( ( TupleSink) node );
+ }
+ removeShare();
+
+ if ( ! this.isInUse() ) {
+ for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
+ workingMemories[i].clearNodeMemory( this );
+ }
+ }
+ this.rightInput.remove( this,
+ workingMemories );
+ this.leftInput.remove( this,
+ workingMemories );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-10-06 11:20:37 UTC (rev 6640)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-10-06 11:22:41 UTC (rev 6641)
@@ -21,8 +21,6 @@
private ReteTuple parent;
- private Activation activation;
-
private long recency;
private int hashCode;
@@ -91,10 +89,6 @@
return get( declaration.getColumn().getIndex() );
}
- public Activation getActivation() {
- return this.activation;
- }
-
public InternalFactHandle[] getFactHandles() {
List list = new ArrayList();
ReteTuple entry = this;
@@ -108,12 +102,7 @@
public long getRecency() {
return this.recency;
- }
-
- public void setActivation(Activation activation) {
- this.activation = activation;
- }
-
+ }
public int hashCode() {
return this.handle.hashCode();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TerminalNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TerminalNode.java 2006-10-06 11:20:37 UTC (rev 6640)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/TerminalNode.java 2006-10-06 11:22:41 UTC (rev 6641)
@@ -17,7 +17,6 @@
*/
import java.io.Serializable;
-import java.util.Iterator;
import org.drools.RuleBaseConfiguration;
import org.drools.common.AgendaGroupImpl;
@@ -34,6 +33,9 @@
import org.drools.spi.AgendaGroup;
import org.drools.spi.Duration;
import org.drools.spi.PropagationContext;
+import org.drools.util.Iterator;
+import org.drools.util.ObjectHashMap;
+import org.drools.util.ObjectHashMap.ObjectEntry;
/**
* Leaf Rete-OO node responsible for enacting <code>Action</code> s on a
@@ -142,9 +144,8 @@
agenda,
context,
this.rule );
-
- if ( this.rule.getActivationGroup() != null ) {
- final TerminalNodeMemory memory = (TerminalNodeMemory) workingMemory.getNodeMemory( this );
+ final TerminalNodeMemory memory = (TerminalNodeMemory) workingMemory.getNodeMemory( this );
+ if ( this.rule.getActivationGroup() != null ) {
// Lazy cache activationGroup
if ( memory.getActivationGroup() == null ) {
memory.setActivationGroup( workingMemory.getAgenda().getActivationGroup( this.rule.getActivationGroup() ) );
@@ -153,7 +154,8 @@
}
agenda.scheduleItem( item );
- tuple.setActivation( item );
+ memory.getTupleMemory().put( tuple, item, false );
+
item.setActivated( true );
workingMemory.getAgendaEventSupport().fireActivationCreated( item );
} else {
@@ -206,7 +208,7 @@
// If the AgendaGroup is already in the priority queue it just
// returns.
agendaGroup.add( item );
- tuple.setActivation( item );
+ memory.getTupleMemory().put( tuple, item, false );
item.setActivated( true );
// We only want to fire an event on a truly new Activation and not on an Activation as a result of a modify
@@ -219,7 +221,8 @@
public void retractTuple(final ReteTuple tuple,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
- final Activation activation = tuple.getActivation();
+ final TerminalNodeMemory memory = (TerminalNodeMemory) workingMemory.getNodeMemory( this );
+ final Activation activation = ( Activation ) memory.getTupleMemory().remove( tuple );
if ( activation.isActivated() ) {
activation.remove();
workingMemory.getAgendaEventSupport().fireActivationCancelled( activation );
@@ -230,24 +233,6 @@
this.rule );
}
- public void modifyTuple(final ReteTuple tuple,
- final PropagationContext context,
- final InternalWorkingMemory workingMemory) {
- // We have to remove and assert the new tuple as it has modified facts and thus its tuple is newer
- boolean fireActivation = true;
- Activation activation = tuple.getActivation();
-
- if ( activation.isActivated() ) {
- activation.remove();
- fireActivation = false;
- }
-
- assertTuple( tuple,
- context,
- workingMemory,
- fireActivation );
- }
-
public String toString() {
return "[TerminalNode: rule=" + this.rule.getName() + "]";
}
@@ -270,8 +255,9 @@
PropagationContext.RULE_ADDITION,
null,
null );
- this.tupleSource.updateNewNode( workingMemory,
- propagationContext );
+ this.tupleSource.updateSink( this,
+ propagationContext,
+ workingMemory );
}
}
@@ -280,10 +266,10 @@
for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
final InternalWorkingMemory workingMemory = workingMemories[i];
- for ( final Iterator it = this.tupleSource.getPropagatedTuples( workingMemory,
- this ).iterator(); it.hasNext(); ) {
- final ReteTuple tuple = (ReteTuple) it.next();
- final Activation activation = tuple.getActivation();
+ final TerminalNodeMemory memory = (TerminalNodeMemory) workingMemory.getNodeMemory( this );
+ Iterator it = memory.getTupleMemory().iterator();
+ for ( ObjectEntry entry = (ObjectEntry)it.next(); entry != null; entry = ( ObjectEntry ) it.next() ) {
+ final Activation activation = (Activation) entry.getValue();
if ( activation.isActivated() ) {
activation.remove();
@@ -296,8 +282,9 @@
null );
workingMemory.getTruthMaintenanceSystem().removeLogicalDependencies( activation,
propagationContext,
- this.rule );
+ this.rule );
}
+
workingMemory.propagateQueuedActions();
}
@@ -305,11 +292,6 @@
workingMemories );
}
- public void updateNewNode(final InternalWorkingMemory workingMemory,
- final PropagationContext context) {
- // There are no child nodes to update, do nothing.
- }
-
public Object createMemory(final RuleBaseConfiguration config) {
return new TerminalNodeMemory();
}
@@ -368,11 +350,17 @@
}
class TerminalNodeMemory implements Serializable {
- private static final long serialVersionUID = -2770066307284050292L;
+ private static final long serialVersionUID = 320L;
private AgendaGroupImpl agendaGroup;
private ActivationGroup activationGroup;
+
+ private ObjectHashMap tupleMemory;
+
+ public TerminalNodeMemory() {
+ this.tupleMemory = new ObjectHashMap();
+ }
public AgendaGroupImpl getAgendaGroup() {
return this.agendaGroup;
@@ -389,6 +377,9 @@
public void setActivationGroup(final ActivationGroup activationGroup) {
this.activationGroup = activationGroup;
}
-
+
+ public ObjectHashMap getTupleMemory() {
+ return this.tupleMemory;
+ }
}
}
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 2006-10-06 11:20:37 UTC (rev 6640)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Tuple.java 2006-10-06 11:22:41 UTC (rev 6641)
@@ -58,6 +58,4 @@
long getRecency();
- void setActivation(Activation activation);
-
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashMap.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashMap.java 2006-10-06 11:20:37 UTC (rev 6640)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashMap.java 2006-10-06 11:22:41 UTC (rev 6641)
@@ -89,7 +89,7 @@
}
current.setNext( null );
this.size--;
- return current.getValue();
+ return current.value;
}
previous = current;
current = next;
More information about the jboss-svn-commits
mailing list