[jboss-svn-commits] JBL Code SVN: r18815 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: reteoo and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Mar 10 21:20:43 EDT 2008
Author: mark.proctor at jboss.com
Date: 2008-03-10 21:20:43 -0400 (Mon, 10 Mar 2008)
New Revision: 18815
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/AbstractWorkingMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
Log:
JBRULES-1498 Thead safe partitioning of WorkingMemory entry points
-Made ObjectTypeConfigurationRegistry and EntryPointNode transient on AbstractWorkingMemory
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-03-11 01:20:37 UTC (rev 18814)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-03-11 01:20:43 UTC (rev 18815)
@@ -48,6 +48,7 @@
import org.drools.process.core.Process;
import org.drools.rule.CompositePackageClassLoader;
import org.drools.rule.DialectDatas;
+import org.drools.rule.EntryPoint;
import org.drools.rule.ImportDeclaration;
import org.drools.rule.InvalidPatternException;
import org.drools.rule.MapBackedClassLoader;
@@ -754,18 +755,17 @@
this.packageClassLoader );
streamWithLoader.setRuleBase( this );
- final StatefulSession session = (StatefulSession) streamWithLoader.readObject();
+ final StatefulSession session = (StatefulSession) streamWithLoader.readObject();
synchronized ( this.pkgs ) {
((InternalWorkingMemory) session).setRuleBase( this );
((InternalWorkingMemory) session).setId( (nextWorkingMemoryCounter()) );
+
ExecutorService executor = ExecutorServiceFactory.createExecutorService( this.config.getExecutorService() );
+ executor.setCommandExecutor( new CommandExecutor( session ) );
+ ((InternalWorkingMemory) session).setExecutorService( executor );
- executor.setCommandExecutor( new CommandExecutor( session ) );
-
- ((InternalWorkingMemory) session).setExecutorService( executor );
-
if ( keepReference ) {
addStatefulSession( session );
for ( Iterator it = session.getRuleBaseUpdateListeners().iterator(); it.hasNext(); ) {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2008-03-11 01:20:37 UTC (rev 18814)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2008-03-11 01:20:43 UTC (rev 18815)
@@ -18,6 +18,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -94,86 +95,86 @@
// ------------------------------------------------------------
// Constants
// ------------------------------------------------------------
- protected static final Class[] ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES = new Class[]{PropertyChangeListener.class};
- private static final int NODE_MEMORIES_ARRAY_GROWTH = 32;
+ protected static final Class[] ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES = new Class[]{PropertyChangeListener.class};
+ private static final int NODE_MEMORIES_ARRAY_GROWTH = 32;
// ------------------------------------------------------------
// Instance members
// ------------------------------------------------------------
- protected long id;
+ protected long id;
/** The arguments used when adding/removing a property change listener. */
- protected final Object[] addRemovePropertyChangeListenerArgs = new Object[]{this};
+ protected final Object[] addRemovePropertyChangeListenerArgs = new Object[]{this};
/** The actual memory for the <code>JoinNode</code>s. */
- protected final NodeMemories nodeMemories;
+ protected final NodeMemories nodeMemories;
- protected final ObjectStore objectStore;
+ protected final ObjectStore objectStore;
- protected Map queryResults = Collections.EMPTY_MAP;
+ protected Map queryResults = Collections.EMPTY_MAP;
/** Global values which are associated with this memory. */
- protected GlobalResolver globalResolver;
+ protected GlobalResolver globalResolver;
/** The eventSupport */
- protected WorkingMemoryEventSupport workingMemoryEventSupport = new WorkingMemoryEventSupport();
+ protected WorkingMemoryEventSupport workingMemoryEventSupport = new WorkingMemoryEventSupport();
- protected AgendaEventSupport agendaEventSupport = new AgendaEventSupport();
+ protected AgendaEventSupport agendaEventSupport = new AgendaEventSupport();
- protected RuleFlowEventSupport workflowEventSupport = new RuleFlowEventSupport();
+ protected RuleFlowEventSupport workflowEventSupport = new RuleFlowEventSupport();
- protected List __ruleBaseEventListeners = new LinkedList();
+ protected List __ruleBaseEventListeners = new LinkedList();
/** The <code>RuleBase</code> with which this memory is associated. */
- protected transient InternalRuleBase ruleBase;
+ protected transient InternalRuleBase ruleBase;
- protected final FactHandleFactory handleFactory;
+ protected final FactHandleFactory handleFactory;
- protected final TruthMaintenanceSystem tms;
+ protected final TruthMaintenanceSystem tms;
/** Rule-firing agenda. */
- protected DefaultAgenda agenda;
+ protected DefaultAgenda agenda;
- protected final Queue<WorkingMemoryAction> actionQueue = new LinkedList<WorkingMemoryAction>();
+ protected final Queue<WorkingMemoryAction> actionQueue = new LinkedList<WorkingMemoryAction>();
- protected boolean evaluatingActionQueue;
+ protected boolean evaluatingActionQueue;
- protected final ReentrantLock lock = new ReentrantLock();
+ protected final ReentrantLock lock = new ReentrantLock();
- protected final boolean discardOnLogicalOverride;
+ protected final boolean discardOnLogicalOverride;
/**
* This must be thread safe as it is incremented and read via different EntryPoints
*/
- protected AtomicLong propagationIdCounter;
+ protected AtomicLong propagationIdCounter;
- private final boolean maintainTms;
+ private final boolean maintainTms;
- private final boolean sequential;
+ private final boolean sequential;
- private List liaPropagations = Collections.EMPTY_LIST;
+ private List liaPropagations = Collections.EMPTY_LIST;
/** Flag to determine if a rule is currently being fired. */
- protected boolean firing;
+ protected boolean firing;
- protected boolean halt;
+ protected boolean halt;
- private Map processInstances = new HashMap();
+ private Map processInstances = new HashMap();
- private int processCounter;
+ private int processCounter;
- private WorkItemManager workItemManager;
+ private WorkItemManager workItemManager;
- private Map<String, ProcessInstanceFactory> processInstanceFactories = new HashMap();
+ private Map<String, ProcessInstanceFactory> processInstanceFactories = new HashMap();
- private TimeMachine timeMachine = new TimeMachine();
+ private TimeMachine timeMachine = new TimeMachine();
- protected ObjectTypeConfigurationRegistry typeConfReg;
+ protected transient ObjectTypeConfigurationRegistry typeConfReg;
- protected EntryPoint entryPoint;
- protected EntryPointNode entryPointNode;
+ protected EntryPoint entryPoint;
+ protected transient EntryPointNode entryPointNode;
- protected Map<String, WorkingMemoryEntryPoint> entryPoints;
+ protected Map<String, WorkingMemoryEntryPoint> entryPoints;
// ------------------------------------------------------------
// Constructors
@@ -204,7 +205,7 @@
}
final RuleBaseConfiguration conf = this.ruleBase.getConfiguration();
-
+
this.propagationIdCounter = new AtomicLong();
this.objectStore = new SingleThreadedObjectStore( conf,
@@ -219,27 +220,28 @@
this.workItemManager = new WorkItemManager( this );
this.processInstanceFactories.put( RuleFlowProcess.RULEFLOW_TYPE,
- new RuleFlowProcessInstanceFactory() );
-
- this.typeConfReg = new ObjectTypeConfigurationRegistry( this.ruleBase );
-
- this.entryPoint = EntryPoint.DEFAULT;
- this.entryPointNode = this.ruleBase.getRete().getEntryPointNode( this.entryPoint );
-
+ new RuleFlowProcessInstanceFactory() );
this.entryPoints = new ConcurrentHashMap();
this.entryPoints.put( "DEFAULT",
this );
- }
-
- // ------------------------------------------------------------
- // Instance methods
- // ------------------------------------------------------------
-
+
+ this.entryPoint = EntryPoint.DEFAULT;
+ initTransient();
+ }
+
public void setRuleBase(final InternalRuleBase ruleBase) {
this.ruleBase = ruleBase;
this.nodeMemories.setRuleBaseReference( this.ruleBase );
+ initTransient();
}
+
+ private void initTransient() {
+ this.entryPointNode = this.ruleBase.getRete().getEntryPointNode( this.entryPoint );
+ this.typeConfReg = new ObjectTypeConfigurationRegistry( this.ruleBase );
+ }
+
+
public void setWorkingMemoryEventSupport(WorkingMemoryEventSupport workingMemoryEventSupport) {
this.workingMemoryEventSupport = workingMemoryEventSupport;
}
@@ -1192,10 +1194,10 @@
this.agenda.getActiveActivations(),
this.agenda.getDormantActivations(),
entryPoint );
-
- ObjectTypeConf typeConf = this.typeConfReg.getObjectTypeConf( this.entryPoint,
- object );
-
+
+ ObjectTypeConf typeConf = this.typeConfReg.getObjectTypeConf( this.entryPoint,
+ object );
+
this.entryPointNode.retractObject( handle,
propagationContext,
typeConf,
@@ -1469,14 +1471,14 @@
public void setTimeMachine(TimeMachine timeMachine) {
this.timeMachine = timeMachine;
}
-
+
public ExecutorService getExecutorService() {
return null; // no executor service
}
public void setExecutorService(ExecutorService executor) {
// no executor service, so nothing to set
- }
+ }
public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String name) {
WorkingMemoryEntryPoint wmEntryPoint = this.entryPoints.get( name );
@@ -1484,7 +1486,6 @@
EntryPoint entryPoint = new EntryPoint( name );
EntryPointNode entryPointNode = this.ruleBase.getRete().getEntryPointNode( entryPoint );
-
if ( entryPointNode != null ) {
wmEntryPoint = new NamedEntryPoint( entryPoint,
entryPointNode,
@@ -1568,9 +1569,9 @@
// }
//
// }
-
+
public ObjectTypeConfigurationRegistry getObjectTypeConfigurationRegistry() {
return this.typeConfReg;
- }
+ }
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java 2008-03-11 01:20:37 UTC (rev 18814)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java 2008-03-11 01:20:43 UTC (rev 18815)
@@ -12,6 +12,7 @@
import org.drools.event.WorkingMemoryEventSupport;
import org.drools.process.instance.ProcessInstance;
import org.drools.process.instance.ProcessInstanceFactory;
+import org.drools.reteoo.EntryPointNode;
import org.drools.reteoo.LIANodePropagation;
import org.drools.reteoo.ObjectTypeConf;
import org.drools.rule.EntryPoint;
@@ -93,5 +94,5 @@
public ExecutorService getExecutorService();
- public void setExecutorService(ExecutorService executor);
+ public void setExecutorService(ExecutorService executor);
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java 2008-03-11 01:20:37 UTC (rev 18814)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java 2008-03-11 01:20:43 UTC (rev 18815)
@@ -29,6 +29,7 @@
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalRuleBase;
import org.drools.common.InternalWorkingMemory;
+import org.drools.common.ObjectTypeConfigurationRegistry;
import org.drools.common.PropagationContextImpl;
import org.drools.common.WorkingMemoryAction;
import org.drools.event.RuleBaseEventListener;
@@ -64,7 +65,7 @@
ruleBase,
ruleBase.newFactHandleFactory() );
this.agenda = new DefaultAgenda( this );
- }
+ }
public QueryResults getQueryResults(final String query) {
return getQueryResults( query, null );
More information about the jboss-svn-commits
mailing list