[jboss-svn-commits] JBL Code SVN: r21414 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: base/evaluators and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Aug 8 18:37:55 EDT 2008
Author: tirelli
Date: 2008-08-08 18:37:55 -0400 (Fri, 08 Aug 2008)
New Revision: 21414
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleBasePartitionId.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BaseNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/ReteooRuleBuilder.java
Log:
Labeling nodes to enable partitioning
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2008-08-08 15:36:16 UTC (rev 21413)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2008-08-08 22:37:55 UTC (rev 21414)
@@ -115,6 +115,11 @@
private ConsequenceExceptionHandler consequenceExceptionHandler;
private String ruleBaseUpdateHandler;
+ // if "true", rulebase builder will try to split
+ // the rulebase into multiple partitions that can be evaluated
+ // in parallel by using multiple internal threads
+ private boolean partitionsEnabled;
+
private ConflictResolver conflictResolver;
private static final String STAR = "*";
@@ -149,6 +154,7 @@
out.writeObject( conflictResolver );
out.writeObject( processNodeInstanceFactoryRegistry );
out.writeBoolean( advancedProcessRuleIntegration );
+ out.writeBoolean( partitionsEnabled );
}
public void readExternal(ObjectInput in) throws IOException,
@@ -173,6 +179,7 @@
conflictResolver = (ConflictResolver) in.readObject();
processNodeInstanceFactoryRegistry = (NodeInstanceFactoryRegistry) in.readObject();
advancedProcessRuleIntegration = in.readBoolean();
+ partitionsEnabled = in.readBoolean();
}
/**
@@ -258,7 +265,7 @@
setRemoveIdentities( Boolean.valueOf( this.chainedProperties.getProperty( "drools.removeIdentities",
"false" ) ).booleanValue() );
-
+
setShareAlphaNodes( Boolean.valueOf( this.chainedProperties.getProperty( "drools.shareAlphaNodes",
"true" ) ).booleanValue() );
@@ -292,9 +299,12 @@
setConflictResolver( RuleBaseConfiguration.determineConflictResolver( this.chainedProperties.getProperty( "drools.conflictResolver",
"org.drools.conflict.DepthConflictResolver" ) ) );
-
+
setAdvancedProcessRuleIntegration( Boolean.valueOf( this.chainedProperties.getProperty( "drools.advancedProcessRuleIntegration",
- "false" ) ).booleanValue() );
+ "false" ) ).booleanValue() );
+
+ setPartitionsEnabled( Boolean.valueOf( this.chainedProperties.getProperty( "drools.enablePartitioning",
+ "false" ) ).booleanValue() );
}
/**
@@ -480,6 +490,30 @@
}
+ /**
+ * Defines if the RuleBase should try to split the rules into
+ * multiple independent partitions that can work in parallel
+ * using multiple threads ("true"), of if the rulebase should
+ * work in classic single partition mode ("false").
+ *
+ * @param enablePartitioning true for multi-partition or
+ * false for single-partition. Default is false.
+ */
+ public void setPartitionsEnabled(boolean enablePartitioning) {
+ checkCanChange();
+ this.partitionsEnabled = enablePartitioning;
+ }
+
+ /**
+ * Returns true if the partitioning of the rulebase is enabled
+ * and false otherwise. Default is false.
+ *
+ * @return
+ */
+ public boolean isPartitionsEnabled() {
+ return this.partitionsEnabled;
+ }
+
private void initProcessNodeInstanceFactoryRegistry() {
this.processNodeInstanceFactoryRegistry = new NodeInstanceFactoryRegistry();
@@ -560,10 +594,10 @@
RuleBaseConfiguration.class ) );
Map<Class< ? extends Process>, ProcessInstanceFactory> map = (Map<Class< ? extends Process>, ProcessInstanceFactory>) MVEL.eval( content,
- new HashMap() );
+ new HashMap() );
if ( map != null ) {
- for ( Entry<Class<? extends Process>, ProcessInstanceFactory> entry : map.entrySet() ) {
+ for ( Entry<Class< ? extends Process>, ProcessInstanceFactory> entry : map.entrySet() ) {
this.processInstanceFactoryRegistry.register( entry.getKey(),
entry.getValue() );
}
@@ -606,30 +640,34 @@
String content = ConfFileUtils.URLContentsToString( ConfFileUtils.getURL( location,
null,
RuleBaseConfiguration.class ) );
- List<Map<String, Object>> workDefinitionsMap = (List<Map<String, Object>>) MVEL.eval(content, new HashMap());
- for (Map<String, Object> workDefinitionMap: workDefinitionsMap) {
+ List<Map<String, Object>> workDefinitionsMap = (List<Map<String, Object>>) MVEL.eval( content,
+ new HashMap() );
+ for ( Map<String, Object> workDefinitionMap : workDefinitionsMap ) {
WorkDefinitionExtensionImpl workDefinition = new WorkDefinitionExtensionImpl();
- workDefinition.setName((String) workDefinitionMap.get("name"));
- workDefinition.setDisplayName((String) workDefinitionMap.get("displayName"));
- workDefinition.setIcon((String) workDefinitionMap.get("icon"));
- workDefinition.setCustomEditor((String) workDefinitionMap.get("customEditor"));
+ workDefinition.setName( (String) workDefinitionMap.get( "name" ) );
+ workDefinition.setDisplayName( (String) workDefinitionMap.get( "displayName" ) );
+ workDefinition.setIcon( (String) workDefinitionMap.get( "icon" ) );
+ workDefinition.setCustomEditor( (String) workDefinitionMap.get( "customEditor" ) );
Set<ParameterDefinition> parameters = new HashSet<ParameterDefinition>();
- Map<String, DataType> parameterMap = (Map<String, DataType>) workDefinitionMap.get("parameters");
- if (parameterMap != null) {
- for (Map.Entry<String, DataType> entry: parameterMap.entrySet()) {
- parameters.add(new ParameterDefinitionImpl(entry.getKey(), entry.getValue()));
+ Map<String, DataType> parameterMap = (Map<String, DataType>) workDefinitionMap.get( "parameters" );
+ if ( parameterMap != null ) {
+ for ( Map.Entry<String, DataType> entry : parameterMap.entrySet() ) {
+ parameters.add( new ParameterDefinitionImpl( entry.getKey(),
+ entry.getValue() ) );
}
}
- workDefinition.setParameters(parameters);
+ workDefinition.setParameters( parameters );
Set<ParameterDefinition> results = new HashSet<ParameterDefinition>();
- Map<String, DataType> resultMap = (Map<String, DataType>) workDefinitionMap.get("results");
- if (resultMap != null) {
- for (Map.Entry<String, DataType> entry: resultMap.entrySet()) {
- results.add(new ParameterDefinitionImpl(entry.getKey(), entry.getValue()));
+ Map<String, DataType> resultMap = (Map<String, DataType>) workDefinitionMap.get( "results" );
+ if ( resultMap != null ) {
+ for ( Map.Entry<String, DataType> entry : resultMap.entrySet() ) {
+ results.add( new ParameterDefinitionImpl( entry.getKey(),
+ entry.getValue() ) );
}
}
- workDefinition.setResults(results);
- this.workDefinitions.put(workDefinition.getName(), workDefinition);
+ workDefinition.setResults( results );
+ this.workDefinitions.put( workDefinition.getName(),
+ workDefinition );
}
}
@@ -670,9 +708,10 @@
String content = ConfFileUtils.URLContentsToString( ConfFileUtils.getURL( factoryLocation,
null,
RuleBaseConfiguration.class ) );
-
- Map<Class< ? extends Context>, ContextInstanceFactory> map = (Map<Class< ? extends Context>, ContextInstanceFactory>) MVEL.eval( content, new HashMap() );
+ Map<Class< ? extends Context>, ContextInstanceFactory> map = (Map<Class< ? extends Context>, ContextInstanceFactory>) MVEL.eval( content,
+ new HashMap() );
+
if ( map != null ) {
for ( Entry<Class< ? extends Context>, ContextInstanceFactory> entry : map.entrySet() ) {
this.processContextInstanceFactoryRegistry.register( entry.getKey(),
@@ -689,8 +728,8 @@
}
private void initProcessInstanceManager() {
- String className = this.chainedProperties.getProperty(
- "processInstanceManager", "org.drools.process.instance.impl.DefaultProcessInstanceManager");
+ String className = this.chainedProperties.getProperty( "processInstanceManager",
+ "org.drools.process.instance.impl.DefaultProcessInstanceManager" );
Class clazz = null;
try {
clazz = Thread.currentThread().getContextClassLoader().loadClass( className );
@@ -714,11 +753,11 @@
throw new IllegalArgumentException( "Process instance manager '" + className + "' not found" );
}
}
-
+
public boolean isAdvancedProcessRuleIntegration() {
return advancedProcessRuleIntegration;
}
-
+
public void setAdvancedProcessRuleIntegration(boolean advancedProcessRuleIntegration) {
this.advancedProcessRuleIntegration = advancedProcessRuleIntegration;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java 2008-08-08 15:36:16 UTC (rev 21413)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/evaluators/EqualityEvaluatorsDefinition.java 2008-08-08 22:37:55 UTC (rev 21414)
@@ -23,7 +23,6 @@
import java.util.Date;
import org.drools.base.BaseEvaluator;
-import org.drools.base.ShadowProxy;
import org.drools.base.ValueType;
import org.drools.common.InternalWorkingMemory;
import org.drools.rule.VariableRestriction.BooleanVariableContextEntry;
@@ -33,8 +32,8 @@
import org.drools.rule.VariableRestriction.ObjectVariableContextEntry;
import org.drools.rule.VariableRestriction.VariableContextEntry;
import org.drools.spi.Evaluator;
-import org.drools.spi.InternalReadAccessor;
import org.drools.spi.FieldValue;
+import org.drools.spi.InternalReadAccessor;
import org.drools.util.DateUtils;
/**
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-08-08 15:36:16 UTC (rev 21413)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-08-08 22:37:55 UTC (rev 21414)
@@ -23,6 +23,7 @@
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -43,7 +44,6 @@
import org.drools.marshalling.Marshaller;
import org.drools.process.core.Process;
import org.drools.rule.CompositePackageClassLoader;
-import org.drools.rule.DialectRuntimeData;
import org.drools.rule.DialectRuntimeRegistry;
import org.drools.rule.FactType;
import org.drools.rule.Function;
@@ -116,6 +116,8 @@
private transient Map<Class< ? >, TypeDeclaration> classTypeDeclaration;
+ private List<RuleBasePartitionId> partitionIDs;
+
/**
* Default constructor - for Externalizable. This should never be used by a user, as it
* will result in an invalid state for the instance.
@@ -159,6 +161,7 @@
this.statefulSessions = new ObjectHashSet();
this.classTypeDeclaration = new HashMap<Class< ? >, TypeDeclaration>();
+ this.partitionIDs = new ArrayList<RuleBasePartitionId>();
}
// ------------------------------------------------------------
@@ -428,19 +431,19 @@
this.eventSupport.fireBeforePackageAdded( newPkg );
-// // create new base package if it doesn't exist, as we always merge the newPkg into the existing one,
-// // to isolate the base package from further possible changes to newPkg.
-// if ( pkg == null ) {
-// // create a new package, use the same parent classloader as the incoming new package
-// pkg = new Package( newPkg.getName(),
-// new MapBackedClassLoader( newPkg.getPackageScopeClassLoader().getParent() ) );
-// //newPkg.getPackageScopeClassLoader() );
-// pkgs.put( pkg.getName(),
-// pkg );
-// // add the dialect registry composite classloader (which uses the above classloader as it's parent)
-// this.packageClassLoader.addClassLoader( pkg.getDialectRuntimeRegistry().getClassLoader() );
-// }
-
+ // // create new base package if it doesn't exist, as we always merge the newPkg into the existing one,
+ // // to isolate the base package from further possible changes to newPkg.
+ // if ( pkg == null ) {
+ // // create a new package, use the same parent classloader as the incoming new package
+ // pkg = new Package( newPkg.getName(),
+ // new MapBackedClassLoader( newPkg.getPackageScopeClassLoader().getParent() ) );
+ // //newPkg.getPackageScopeClassLoader() );
+ // pkgs.put( pkg.getName(),
+ // pkg );
+ // // add the dialect registry composite classloader (which uses the above classloader as it's parent)
+ // this.packageClassLoader.addClassLoader( pkg.getDialectRuntimeRegistry().getClassLoader() );
+ // }
+
if ( pkg == null ) {
pkg = new Package( newPkg.getName(),
newPkg.getPackageScopeClassLoader() );
@@ -451,9 +454,7 @@
pkg.getPackageScopeClassLoader().getStore().putAll( newPkg.getPackageScopeClassLoader().getStore() );
this.packageClassLoader.addClassLoader( newPkg.getDialectRuntimeRegistry().getClassLoader() );
}
-
-
// now merge the new package into the existing one
mergePackage( pkg,
newPkg );
@@ -806,6 +807,15 @@
}
}
+ public RuleBasePartitionId createNewPartitionId() {
+ RuleBasePartitionId p = null;
+ synchronized ( this.partitionIDs ) {
+ p = new RuleBasePartitionId("P-" + this.partitionIDs.size());
+ this.partitionIDs.add( p );
+ }
+ return p;
+ }
+
public void addEventListener(final RuleBaseEventListener listener) {
// since the event support is thread-safe, no need for locks... right?
this.eventSupport.addEventListener( listener );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BaseNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BaseNode.java 2008-08-08 15:36:16 UTC (rev 21413)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/BaseNode.java 2008-08-08 22:37:55 UTC (rev 21414)
@@ -16,14 +16,13 @@
package org.drools.common;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
import org.drools.reteoo.ReteooBuilder;
import org.drools.reteoo.RuleRemovalContext;
-import java.io.Externalizable;
-import java.io.ObjectInput;
-import java.io.IOException;
-import java.io.ObjectOutput;
-
/**
* The base class for all Rete nodes.
*
@@ -34,7 +33,9 @@
public abstract class BaseNode
implements
NetworkNode {
+
protected int id;
+ protected RuleBasePartitionId partitionId;
public BaseNode() {
@@ -119,4 +120,22 @@
public String toString() {
return "[" + this.getClass().getSimpleName() + "(" + this.id + ")]";
}
+
+ /**
+ * Returns the partition ID for which this node belongs to
+ *
+ * @return
+ */
+ public RuleBasePartitionId getPartitionId() {
+ return this.partitionId;
+ }
+
+ /**
+ * Sets the partition this node belongs to
+ *
+ * @param partitionId
+ */
+ public void setPartitionId( final RuleBasePartitionId partitionId ) {
+ this.partitionId = partitionId;
+ }
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java 2008-08-08 15:36:16 UTC (rev 21413)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java 2008-08-08 22:37:55 UTC (rev 21414)
@@ -24,8 +24,6 @@
import org.drools.RuleBase;
import org.drools.RuleBaseConfiguration;
import org.drools.StatefulSession;
-import org.drools.audit.WorkingMemoryInMemoryLogger;
-import org.drools.marshalling.MarshallerReaderContext;
import org.drools.process.core.Process;
import org.drools.reteoo.Rete;
import org.drools.reteoo.ReteooWorkingMemory;
@@ -116,7 +114,7 @@
* @param clazz
* @return
*/
- public boolean isEvent( Class clazz );
+ public boolean isEvent( Class<?> clazz );
public int getNodeCount();
@@ -127,4 +125,11 @@
* @return
*/
public TypeDeclaration getTypeDeclaration(Class<?> clazz);
+
+ /**
+ * Creates and allocates a new partition ID for this rulebase
+ *
+ * @return
+ */
+ public RuleBasePartitionId createNewPartitionId();
}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleBasePartitionId.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleBasePartitionId.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleBasePartitionId.java 2008-08-08 22:37:55 UTC (rev 21414)
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2008 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.
+ */
+package org.drools.common;
+
+import java.io.Serializable;
+
+/**
+ * A class to identify RuleBase partitions
+ *
+ * @author etirelli
+ */
+public final class RuleBasePartitionId implements Serializable {
+
+ private static final long serialVersionUID = 6646903702672295085L;
+
+ public static final RuleBasePartitionId MAIN_PARTITION = new RuleBasePartitionId( "P-MAIN" );
+
+ private final String id;
+
+ public RuleBasePartitionId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( getClass() != obj.getClass() ) return false;
+ final RuleBasePartitionId other = (RuleBasePartitionId) obj;
+ if ( id == null ) {
+ if ( other.id != null ) return false;
+ } else if ( !id.equals( other.id ) ) return false;
+ return true;
+ }
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java 2008-08-08 15:36:16 UTC (rev 21413)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java 2008-08-08 22:37:55 UTC (rev 21414)
@@ -23,10 +23,8 @@
import java.io.OutputStream;
import java.util.Iterator;
-import org.drools.ClockType;
import org.drools.FactException;
import org.drools.FactHandle;
-import org.drools.RuleBase;
import org.drools.RuleBaseConfiguration;
import org.drools.SessionConfiguration;
import org.drools.StatefulSession;
@@ -90,6 +88,7 @@
this( id,
null,
new ReteooFactHandleFactory() );
+
}
/**
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java 2008-08-08 15:36:16 UTC (rev 21413)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java 2008-08-08 22:37:55 UTC (rev 21414)
@@ -16,19 +16,18 @@
package org.drools.reteoo.builder;
-import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
-import java.util.Map;
-import org.drools.common.BetaConstraints;
+import org.drools.common.BaseNode;
import org.drools.common.InternalRuleBase;
import org.drools.common.InternalWorkingMemory;
+import org.drools.common.RuleBasePartitionId;
+import org.drools.reteoo.LeftTupleSource;
import org.drools.reteoo.ObjectSource;
import org.drools.reteoo.ReteooBuilder;
-import org.drools.reteoo.ReteooRuleBase;
-import org.drools.reteoo.LeftTupleSource;
+import org.drools.rule.Behavior;
import org.drools.rule.EntryPoint;
import org.drools.rule.RuleConditionElement;
@@ -40,7 +39,7 @@
public class BuildContext {
// tuple source to attach next node to
- private LeftTupleSource tupleSource;
+ private LeftTupleSource tupleSource;
// object source to attach next node to
private ObjectSource objectSource;
@@ -68,28 +67,34 @@
// alpha constraints from the last pattern attached
private List alphaConstraints;
-
+
// behaviors from the last pattern attached
- private List behaviors;
-
+ private List<Behavior> behaviors;
+
// the current entry point
private EntryPoint currentEntryPoint;
-
+
private boolean tupleMemoryEnabled;
-
- private boolean objectTypeNodeMemoryEnabled;
-
+
+ private boolean objectTypeNodeMemoryEnabled;
+
private boolean terminalNodeMemoryEnabled;
-
+
/** This one is slightly different as alphaMemory can be adaptive, only turning on for new rule attachments */
private boolean alphaNodeMemoryAllowed;
+ /** Stores the list of nodes being added that require partitionIds */
+ private List<BaseNode> nodes;
+
+ /** Stores the id of the partition this rule will be added to */
+ private RuleBasePartitionId partitionId;
+
public BuildContext(final InternalRuleBase rulebase,
final ReteooBuilder.IdGenerator idGenerator) {
this.rulebase = rulebase;
this.idGenerator = idGenerator;
-
+
this.workingMemories = null;
this.objectType = null;
@@ -99,12 +104,14 @@
this.objectSource = null;
this.currentPatternOffset = 0;
-
+
this.tupleMemoryEnabled = true;
-
+
this.objectTypeNodeMemoryEnabled = true;
+
+ this.currentEntryPoint = EntryPoint.DEFAULT;
- this.currentEntryPoint = EntryPoint.DEFAULT;
+ this.nodes = new LinkedList<BaseNode>();
}
/**
@@ -123,7 +130,7 @@
}
public void syncObjectTypesWithPatternOffset() {
- if (this.objectType == null ) {
+ if ( this.objectType == null ) {
this.objectType = new LinkedList();
}
while ( this.objectType.size() > this.currentPatternOffset ) {
@@ -149,9 +156,9 @@
* @return the objectType
*/
public LinkedList getObjectType() {
- if (this.objectType == null ) {
+ if ( this.objectType == null ) {
this.objectType = new LinkedList();
- }
+ }
return this.objectType;
}
@@ -159,9 +166,9 @@
* @param objectType the objectType to set
*/
public void setObjectType(final LinkedList objectType) {
- if (this.objectType == null ) {
+ if ( this.objectType == null ) {
this.objectType = new LinkedList();
- }
+ }
this.objectType = objectType;
}
@@ -220,7 +227,7 @@
/**
* Method used to undo previous id assignment
*/
- public void releaseId( int id ) {
+ public void releaseId(int id) {
this.idGenerator.releaseId( id );
}
@@ -230,8 +237,8 @@
*/
public void push(final RuleConditionElement rce) {
if ( this.buildstack == null ) {
- this.buildstack = new LinkedList();
- }
+ this.buildstack = new LinkedList();
+ }
this.buildstack.addLast( rce );
}
@@ -241,7 +248,7 @@
*/
public RuleConditionElement pop() {
if ( this.buildstack == null ) {
- this.buildstack = new LinkedList();
+ this.buildstack = new LinkedList();
}
return (RuleConditionElement) this.buildstack.removeLast();
}
@@ -252,8 +259,8 @@
*/
public RuleConditionElement peek() {
if ( this.buildstack == null ) {
- this.buildstack = new LinkedList();
- }
+ this.buildstack = new LinkedList();
+ }
return (RuleConditionElement) this.buildstack.getLast();
}
@@ -263,8 +270,8 @@
*/
public ListIterator stackIterator() {
if ( this.buildstack == null ) {
- this.buildstack = new LinkedList();
- }
+ this.buildstack = new LinkedList();
+ }
return this.buildstack.listIterator();
}
@@ -280,18 +287,19 @@
*/
public void setBetaconstraints(final List betaconstraints) {
this.betaconstraints = betaconstraints;
- }
-
+ }
+
public int getNextSequence(String groupName) {
//List list = new ArrayList();
-
- Integer seq = ( Integer ) this.rulebase.getAgendaGroupRuleTotals().get( groupName );
+
+ Integer seq = (Integer) this.rulebase.getAgendaGroupRuleTotals().get( groupName );
if ( seq == null ) {
- seq = new Integer( 0 );
+ seq = new Integer( 0 );
}
Integer newSeq = new Integer( seq.intValue() + 1 );
- this.rulebase.getAgendaGroupRuleTotals().put( groupName, newSeq );
-
+ this.rulebase.getAgendaGroupRuleTotals().put( groupName,
+ newSeq );
+
return newSeq.intValue();
}
@@ -328,12 +336,12 @@
public void setTerminalNodeMemoryEnabled(boolean hasTerminalNodeMemory) {
this.terminalNodeMemoryEnabled = hasTerminalNodeMemory;
- }
-
+ }
+
public void setAlphaNodeMemoryAllowed(boolean alphaMemoryAllowed) {
this.alphaNodeMemoryAllowed = alphaMemoryAllowed;
}
-
+
public boolean isAlphaMemoryAllowed() {
return this.alphaNodeMemoryAllowed;
}
@@ -353,17 +361,45 @@
}
/**
- * @return the behaviors
+ * @return the behaviours
*/
- public List getBehaviors() {
+ public List<Behavior> getBehaviors() {
return behaviors;
}
/**
- * @param behaviors the behaviors to set
+ * @param behaviors the behaviours to set
*/
- public void setBehaviors(List behaviors) {
+ public void setBehaviors(List<Behavior> behaviors) {
this.behaviors = behaviors;
}
-
+
+ /**
+ * @return the nodes
+ */
+ public List<BaseNode> getNodes() {
+ return nodes;
+ }
+
+ /**
+ * @param nodes the nodes to set
+ */
+ public void setNodes(List<BaseNode> nodes) {
+ this.nodes = nodes;
+ }
+
+ /**
+ * @return the partitionId
+ */
+ public RuleBasePartitionId getPartitionId() {
+ return partitionId;
+ }
+
+ /**
+ * @param partitionId the partitionId to set
+ */
+ public void setPartitionId(RuleBasePartitionId partitionId) {
+ this.partitionId = partitionId;
+ }
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java 2008-08-08 15:36:16 UTC (rev 21413)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java 2008-08-08 22:37:55 UTC (rev 21414)
@@ -29,14 +29,15 @@
import org.drools.common.DoubleBetaConstraints;
import org.drools.common.EmptyBetaConstraints;
import org.drools.common.QuadroupleBetaConstraints;
+import org.drools.common.RuleBasePartitionId;
import org.drools.common.SingleBetaConstraints;
import org.drools.common.TripleBetaConstraints;
import org.drools.reteoo.EntryPointNode;
+import org.drools.reteoo.LeftTupleSink;
+import org.drools.reteoo.LeftTupleSource;
import org.drools.reteoo.ObjectSink;
import org.drools.reteoo.ObjectSource;
import org.drools.reteoo.ObjectTypeNode;
-import org.drools.reteoo.LeftTupleSink;
-import org.drools.reteoo.LeftTupleSource;
import org.drools.rule.Declaration;
import org.drools.rule.InvalidPatternException;
import org.drools.rule.RuleConditionElement;
@@ -94,6 +95,9 @@
EntryPointNode epn = context.getRuleBase().getRete().getEntryPointNode( ((EntryPointNode)candidate).getEntryPoint() );
if( epn != null ) {
node = epn;
+ } else {
+ // all EntryPointNodes belong to the main partition
+ candidate.setPartitionId( RuleBasePartitionId.MAIN_PARTITION );
}
} else if( candidate instanceof ObjectTypeNode ) {
// object type nodes are always shared
@@ -103,7 +107,13 @@
otn = map.get( otn.getObjectType() );
if ( otn != null ) {
node = otn;
+ } else {
+ // all OTNs belong to the main partition
+ candidate.setPartitionId( RuleBasePartitionId.MAIN_PARTITION );
}
+ } else {
+ // all OTNs belong to the main partition
+ candidate.setPartitionId( RuleBasePartitionId.MAIN_PARTITION );
}
} else if( isSharingEnabledForNode( context, candidate ) ) {
if ( (context.getTupleSource() != null) && ( candidate instanceof LeftTupleSink ) ) {
@@ -115,8 +125,19 @@
}
if( node != null ) {
// shared node found
+
// undo previous id assignment
context.releaseId( candidate.getId() );
+
+ // if partitions are enabled
+ if( context.getRuleBase().getConfiguration().isPartitionsEnabled() ) {
+ // check what partition it belongs to
+ if( context.getPartitionId() == null ) {
+ context.setPartitionId( node.getPartitionId() );
+ } else if( ! context.getPartitionId().equals( node.getPartitionId() ) ) {
+ assert false : "Needs to implement support for partitions merge";
+ }
+ }
}
}
@@ -129,6 +150,8 @@
} else {
node.attach( context.getWorkingMemories() );
}
+ // adds the node to the context list to track all added nodes
+ context.getNodes().add( node );
}
return node;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/ReteooRuleBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/ReteooRuleBuilder.java 2008-08-08 15:36:16 UTC (rev 21413)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/ReteooRuleBuilder.java 2008-08-08 22:37:55 UTC (rev 21414)
@@ -18,36 +18,27 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import org.drools.InitialFact;
import org.drools.RuleIntegrationException;
-import org.drools.base.ClassFieldReader;
import org.drools.base.ClassObjectType;
-import org.drools.base.DroolsQuery;
-import org.drools.base.FieldFactory;
-import org.drools.base.ValueType;
-import org.drools.base.evaluators.Operator;
import org.drools.common.BaseNode;
import org.drools.common.InternalRuleBase;
import org.drools.reteoo.QueryTerminalNode;
import org.drools.reteoo.ReteooBuilder;
-import org.drools.reteoo.ReteooRuleBase;
import org.drools.reteoo.RuleTerminalNode;
import org.drools.reteoo.TerminalNode;
import org.drools.rule.Accumulate;
import org.drools.rule.Collect;
import org.drools.rule.EntryPoint;
-import org.drools.rule.Pattern;
import org.drools.rule.EvalCondition;
import org.drools.rule.Forall;
import org.drools.rule.From;
import org.drools.rule.GroupElement;
import org.drools.rule.InvalidPatternException;
-import org.drools.rule.LiteralConstraint;
+import org.drools.rule.Pattern;
import org.drools.rule.Query;
import org.drools.rule.Rule;
-import org.drools.spi.FieldValue;
/**
* @author etirelli
@@ -183,6 +174,25 @@
((BaseNode) terminal).networkUpdated();
+ // adds the terminal no to the list of nodes created/added by this sub-rule
+ context.getNodes().add((BaseNode) terminal );
+
+ if( context.getRuleBase().getConfiguration().isPartitionsEnabled() ) {
+ org.drools.common.RuleBasePartitionId partitionId = null;
+ if( context.getPartitionId() != null ) {
+ // it means it shares nodes with an existing partition, so
+ // assign the first id to the newly added nodes
+ partitionId = context.getPartitionId();
+ } else {
+ // nodes are independent of existing nodes, so create a new
+ // partition ID for them
+ partitionId = context.getRuleBase().createNewPartitionId();
+ }
+ for( BaseNode node : context.getNodes() ) {
+ node.setPartitionId( partitionId );
+ }
+ }
+
return terminal;
}
More information about the jboss-svn-commits
mailing list