[jboss-svn-commits] JBL Code SVN: r12993 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/common and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Jul 2 00:33:18 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-07-02 00:33:18 -0400 (Mon, 02 Jul 2007)
New Revision: 12993
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSession.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/AbstractWorkingMemory.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/InternalRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/RuleFlowEventSupport.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/WorkingMemoryEventSupport.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/ReteooStatelessSession.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/RuleFlowProcessInstance.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java
Log:
JBRULES-963 Allows Stateless Sessions to be re-usable
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSession.java 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSession.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -4,6 +4,8 @@
import java.util.List;
import org.drools.event.AgendaEventListener;
+import org.drools.event.RuleFlowEventListener;
+import org.drools.event.WorkingMemoryEventListener;
import org.drools.spi.AgendaFilter;
import org.drools.spi.GlobalResolver;
@@ -18,28 +20,23 @@
* the specific information.
*/
public interface StatelessSession {
- /**
- * Returns all event listeners.
- *
- * @return listeners The listeners.
- */
+ public void addEventListener(final WorkingMemoryEventListener listener);
+
+ public void removeEventListener(final WorkingMemoryEventListener listener);
+
public List getWorkingMemoryEventListeners();
- /**
- * Add an event listener.
- *
- * @param listener
- * The listener to add.
- */
- public void addEventListener(AgendaEventListener listener);
+ public void addEventListener(final AgendaEventListener listener);
- /**
- * Remove an event listener.
- *
- * @param listener
- * The listener to remove.
- */
- public void removeEventListener(AgendaEventListener listener);
+ public void removeEventListener(final AgendaEventListener listener);
+
+ public List getAgendaEventListeners();
+
+ public void addEventListener(final RuleFlowEventListener listener);
+
+ public void removeEventListener(final RuleFlowEventListener listener);
+
+ public List getRuleFlowEventListeners();
void setAgendaFilter(AgendaFilter agendaFilter);
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 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -98,6 +98,10 @@
public AbstractRuleBase() {
}
+
+ public synchronized int nextWorkingMemoryCounter() {
+ return this.workingMemoryCounter++;
+ }
/**
* Construct.
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 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -99,7 +99,7 @@
8 );
/** Global values which are associated with this memory. */
- protected final Map globals = new HashMap();
+ protected Map globals = new HashMap();
/** Object-to-handle mapping. */
private final ObjectHashMap assertMap;
@@ -113,11 +113,11 @@
};
/** The eventSupport */
- protected final WorkingMemoryEventSupport workingMemoryEventSupport = new WorkingMemoryEventSupport( this );
+ protected WorkingMemoryEventSupport workingMemoryEventSupport = new WorkingMemoryEventSupport( );
- protected final AgendaEventSupport agendaEventSupport = new AgendaEventSupport( this );
+ protected AgendaEventSupport agendaEventSupport = new AgendaEventSupport( );
- protected final RuleFlowEventSupport ruleFlowEventSupport = new RuleFlowEventSupport( this );
+ protected RuleFlowEventSupport ruleFlowEventSupport = new RuleFlowEventSupport( );
/** The <code>RuleBase</code> with which this memory is associated. */
protected transient InternalRuleBase ruleBase;
@@ -138,14 +138,14 @@
protected long propagationIdCounter;
private final boolean maintainTms;
-
+
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 halt;
// ------------------------------------------------------------
@@ -194,15 +194,27 @@
// ------------------------------------------------------------
// Instance methods
// ------------------------------------------------------------
-
+
void setRuleBase(final InternalRuleBase ruleBase) {
this.ruleBase = ruleBase;
}
+ public void setWorkingMemoryEventSupport(WorkingMemoryEventSupport workingMemoryEventSupport) {
+ this.workingMemoryEventSupport = workingMemoryEventSupport;
+ }
+
+ public void setAgendaEventSupport(AgendaEventSupport agendaEventSupport) {
+ this.agendaEventSupport = agendaEventSupport;
+ }
+
+ public void setRuleFlowEventSupport(RuleFlowEventSupport ruleFlowEventSupport) {
+ this.ruleFlowEventSupport = ruleFlowEventSupport;
+ }
+
public boolean isSequential() {
return this.sequential;
}
-
+
public void addLIANodePropagation(LIANodePropagation liaNodePropagation) {
if ( this.liaPropagations == Collections.EMPTY_LIST ) {
this.liaPropagations = new ArrayList();
@@ -295,6 +307,10 @@
return this.handleFactory;
}
+ public void setGlobals(Map globals) {
+ this.globals = globals;
+ }
+
/**
* @see WorkingMemory
*/
@@ -399,23 +415,27 @@
public void halt() {
this.halt = true;
}
-
+
/**
* @see WorkingMemory
*/
public synchronized void fireAllRules() throws FactException {
- fireAllRules( null, -1 );
+ fireAllRules( null,
+ -1 );
}
- public synchronized void fireAllRules( int fireLimit ) throws FactException {
- fireAllRules( null, fireLimit );
+ public synchronized void fireAllRules(int fireLimit) throws FactException {
+ fireAllRules( null,
+ fireLimit );
}
- public synchronized void fireAllRules( final AgendaFilter agendaFilter ) throws FactException {
- fireAllRules( agendaFilter, -1 );
+ public synchronized void fireAllRules(final AgendaFilter agendaFilter) throws FactException {
+ fireAllRules( agendaFilter,
+ -1 );
}
- public synchronized void fireAllRules(final AgendaFilter agendaFilter, int fireLimit ) throws FactException {
+ public synchronized void fireAllRules(final AgendaFilter agendaFilter,
+ int fireLimit) throws FactException {
// If we're already firing a rule, then it'll pick up
// the firing for any other assertObject(..) that get
// nested inside, avoiding concurrent-modification
@@ -424,10 +444,10 @@
if ( isSequential() ) {
for ( Iterator it = this.liaPropagations.iterator(); it.hasNext(); ) {
- (( LIANodePropagation ) it.next()).doPropagation( this );
+ ((LIANodePropagation) it.next()).doPropagation( this );
}
}
-
+
if ( !this.actionQueue.isEmpty() ) {
executeQueuedActions();
}
@@ -448,19 +468,20 @@
} finally {
this.firing = false;
if ( noneFired ) {
- doOtherwise( agendaFilter, fireLimit );
+ doOtherwise( agendaFilter,
+ fireLimit );
}
}
}
}
-
- private final boolean continueFiring( final int fireLimit ) {
- return (!halt) && (fireLimit != 0 );
+
+ private final boolean continueFiring(final int fireLimit) {
+ return (!halt) && (fireLimit != 0);
}
-
- private final int updateFireLimit( final int fireLimit ) {
- return fireLimit > 0 ? fireLimit-1 : fireLimit;
+
+ private final int updateFireLimit(final int fireLimit) {
+ return fireLimit > 0 ? fireLimit - 1 : fireLimit;
}
/**
@@ -468,7 +489,8 @@
* If no items are fired, then it will assert a temporary "Otherwise"
* fact and allow any rules to fire to handle "otherwise" cases.
*/
- private void doOtherwise(final AgendaFilter agendaFilter, int fireLimit ) {
+ private void doOtherwise(final AgendaFilter agendaFilter,
+ int fireLimit) {
final FactHandle handle = this.insert( new Otherwise() );
if ( !this.actionQueue.isEmpty() ) {
executeQueuedActions();
@@ -673,16 +695,21 @@
// you cannot assert a null object
return null;
}
-
+
InternalFactHandle handle = null;
-
+
if ( isSequential() ) {
handle = this.handleFactory.newFactHandle( object );
- this.assertMap.put( handle, handle, false );
- insert(handle, object, rule, activation);
+ this.assertMap.put( handle,
+ handle,
+ false );
+ insert( handle,
+ object,
+ rule,
+ activation );
return handle;
}
-
+
try {
this.lock.lock();
// check if the object already exists in the WM
@@ -817,17 +844,22 @@
if ( dynamic ) {
addPropertyChangeListener( object );
}
-
- insert(handle, object, rule, activation);
+ insert( handle,
+ object,
+ rule,
+ activation );
} finally {
this.lock.unlock();
}
return handle;
}
-
- private void insert( InternalFactHandle handle, Object object, Rule rule, Activation activation) {
+
+ private void insert(InternalFactHandle handle,
+ Object object,
+ Rule rule,
+ Activation activation) {
final PropagationContext propagationContext = new PropagationContextImpl( this.propagationIdCounter++,
PropagationContext.ASSERTION,
rule,
@@ -841,11 +873,12 @@
this.workingMemoryEventSupport.fireObjectInserted( propagationContext,
handle,
- object );
+ object,
+ this );
if ( !this.actionQueue.isEmpty() ) {
executeQueuedActions();
- }
+ }
}
protected void addPropertyChangeListener(final Object object) {
@@ -968,7 +1001,8 @@
this.workingMemoryEventSupport.fireObjectRetracted( propagationContext,
handle,
- object );
+ object,
+ this );
this.assertMap.remove( handle );
@@ -1077,7 +1111,8 @@
this.workingMemoryEventSupport.fireObjectUpdated( propagationContext,
factHandle,
originalObject,
- object );
+ object,
+ this );
propagationContext.clearRetractedTuples();
@@ -1178,7 +1213,8 @@
this.workingMemoryEventSupport.fireObjectUpdated( propagationContext,
factHandle,
originalObject,
- object );
+ object,
+ this );
propagationContext.clearRetractedTuples();
@@ -1310,7 +1346,7 @@
processInstance.setProcess( process );
processInstance.start();
- getRuleFlowEventSupport().fireRuleFlowProcessStarted( processInstance );
+ getRuleFlowEventSupport().fireRuleFlowProcessStarted( processInstance, this );
return processInstance;
} else {
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 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -183,7 +183,7 @@
this.focusStack.add( agendaGroup );
((InternalAgendaGroup) agendaGroup).setActive( true );
final EventSupport eventsupport = (EventSupport) this.workingMemory;
- eventsupport.getAgendaEventSupport().fireAgendaGroupPushed( agendaGroup );
+ eventsupport.getAgendaEventSupport().fireAgendaGroupPushed( agendaGroup, this.workingMemory );
return true;
} else {
return false;
@@ -221,7 +221,7 @@
agendaGroup.setActive( false );
this.focusStack.removeLast();
final EventSupport eventsupport = (EventSupport) this.workingMemory;
- eventsupport.getAgendaEventSupport().fireAgendaGroupPopped( agendaGroup );
+ eventsupport.getAgendaEventSupport().fireAgendaGroupPopped( agendaGroup, this.workingMemory );
} else {
agendaGroup = (empty) ? null : agendaGroup;
break;
@@ -523,7 +523,7 @@
ruleFlowGroup.removeActivation( activation );
}
- eventsupport.getAgendaEventSupport().fireAfterActivationFired( activation );
+ eventsupport.getAgendaEventSupport().fireAfterActivationFired( activation, this.workingMemory );
}
public void increaseActiveActivations() {
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 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -40,6 +40,8 @@
* @return the id
*/
public String getId();
+
+ public int nextWorkingMemoryCounter();
public FactHandleFactory newFactHandleFactory();
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 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -1,8 +1,13 @@
package org.drools.common;
+import java.util.Map;
+
import org.drools.FactException;
import org.drools.FactHandle;
import org.drools.WorkingMemory;
+import org.drools.event.AgendaEventSupport;
+import org.drools.event.RuleFlowEventSupport;
+import org.drools.event.WorkingMemoryEventSupport;
import org.drools.reteoo.LIANodePropagation;
import org.drools.rule.Rule;
import org.drools.spi.Activation;
@@ -13,9 +18,17 @@
public interface InternalWorkingMemory
extends
- WorkingMemory {
+ WorkingMemory {
public long getId();
+
+ public void setGlobals(Map globals);
+
+ public void setWorkingMemoryEventSupport(WorkingMemoryEventSupport workingMemoryEventSupport);
+ public void setAgendaEventSupport(AgendaEventSupport agendaEventSupport);
+
+ public void setRuleFlowEventSupport(RuleFlowEventSupport ruleFlowEventSupport);
+
public Object getNodeMemory(NodeMemory node);
public void clearNodeMemory(NodeMemory node);
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 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/RuleFlowGroupImpl.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -89,7 +89,7 @@
triggerActivations();
}
((EventSupport) this.workingMemory).getRuleFlowEventSupport()
- .fireRuleFlowGroupActivated(this);
+ .fireRuleFlowGroupActivated(this, this.workingMemory);
} else {
final Iterator it = this.list.iterator();
for ( RuleFlowGroupNode node = (RuleFlowGroupNode) it.next(); node != null; node = (RuleFlowGroupNode) it.next() ) {
@@ -100,7 +100,7 @@
}
}
((EventSupport) this.workingMemory).getRuleFlowEventSupport()
- .fireRuleFlowGroupDeactivated(this);
+ .fireRuleFlowGroupDeactivated(this, this.workingMemory);
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/AgendaEventSupport.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -22,6 +22,7 @@
import java.util.List;
import org.drools.WorkingMemory;
+import org.drools.common.InternalWorkingMemory;
import org.drools.spi.Activation;
import org.drools.spi.AgendaGroup;
@@ -36,10 +37,8 @@
*/
private static final long serialVersionUID = 320L;
private final List listeners = Collections.synchronizedList( new ArrayList() );
- private final WorkingMemory workingMemory;
- public AgendaEventSupport(final WorkingMemory workingMemory) {
- this.workingMemory = workingMemory;
+ public AgendaEventSupport() {
}
public void addEventListener(final AgendaEventListener listener) {
@@ -106,7 +105,7 @@
}
}
- public void fireAfterActivationFired(final Activation activation) {
+ public void fireAfterActivationFired(final Activation activation, final InternalWorkingMemory workingMemory) {
if ( this.listeners.isEmpty() ) {
return;
}
@@ -115,11 +114,11 @@
for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
((AgendaEventListener) this.listeners.get( i )).afterActivationFired( event,
- this.workingMemory );
+ workingMemory );
}
}
- public void fireAgendaGroupPopped(final AgendaGroup agendaGroup) {
+ public void fireAgendaGroupPopped(final AgendaGroup agendaGroup, final InternalWorkingMemory workingMemory) {
if ( this.listeners.isEmpty() ) {
return;
}
@@ -128,11 +127,11 @@
for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
((AgendaEventListener) this.listeners.get( i )).agendaGroupPopped( event,
- this.workingMemory );
+ workingMemory );
}
}
- public void fireAgendaGroupPushed(final AgendaGroup agendaGroup) {
+ public void fireAgendaGroupPushed(final AgendaGroup agendaGroup, final InternalWorkingMemory workingMemory) {
if ( this.listeners.isEmpty() ) {
return;
}
@@ -141,7 +140,7 @@
for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
((AgendaEventListener) this.listeners.get( i )).agendaGroupPushed( event,
- this.workingMemory );
+ workingMemory );
}
}
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/RuleFlowEventSupport.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/RuleFlowEventSupport.java 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/RuleFlowEventSupport.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -22,6 +22,7 @@
import java.util.List;
import org.drools.WorkingMemory;
+import org.drools.common.InternalWorkingMemory;
import org.drools.ruleflow.instance.RuleFlowProcessInstance;
import org.drools.spi.RuleFlowGroup;
@@ -32,10 +33,8 @@
private static final long serialVersionUID = -4300367587017885998L;
private final List listeners = Collections.synchronizedList( new ArrayList() );
- private final WorkingMemory workingMemory;
- public RuleFlowEventSupport(final WorkingMemory workingMemory) {
- this.workingMemory = workingMemory;
+ public RuleFlowEventSupport() {
}
public void addEventListener(final RuleFlowEventListener listener) {
@@ -60,7 +59,7 @@
return this.listeners.isEmpty();
}
- public void fireRuleFlowProcessStarted(final RuleFlowProcessInstance instance) {
+ public void fireRuleFlowProcessStarted(final RuleFlowProcessInstance instance, final InternalWorkingMemory workingMemory) {
if ( this.listeners.isEmpty() ) {
return;
}
@@ -69,11 +68,11 @@
for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
((RuleFlowEventListener) this.listeners.get( i ))
- .ruleFlowStarted( event, this.workingMemory );
+ .ruleFlowStarted( event, workingMemory );
}
}
- public void fireRuleFlowProcessCompleted(final RuleFlowProcessInstance instance) {
+ public void fireRuleFlowProcessCompleted(final RuleFlowProcessInstance instance, final InternalWorkingMemory workingMemory) {
if ( this.listeners.isEmpty() ) {
return;
}
@@ -82,11 +81,11 @@
for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
((RuleFlowEventListener) this.listeners.get( i ))
- .ruleFlowCompleted( event, this.workingMemory );
+ .ruleFlowCompleted( event, workingMemory );
}
}
- public void fireRuleFlowGroupActivated(final RuleFlowGroup ruleFlowGroup) {
+ public void fireRuleFlowGroupActivated(final RuleFlowGroup ruleFlowGroup, final InternalWorkingMemory workingMemory) {
if ( this.listeners.isEmpty() ) {
return;
}
@@ -95,11 +94,11 @@
for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
((RuleFlowEventListener) this.listeners.get( i ))
- .ruleFlowGroupActivated( event, this.workingMemory );
+ .ruleFlowGroupActivated( event, workingMemory );
}
}
- public void fireRuleFlowGroupDeactivated(final RuleFlowGroup ruleFlowGroup) {
+ public void fireRuleFlowGroupDeactivated(final RuleFlowGroup ruleFlowGroup, final InternalWorkingMemory workingMemory) {
if ( this.listeners.isEmpty() ) {
return;
}
@@ -108,7 +107,7 @@
for ( int i = 0, size = this.listeners.size(); i < size; i++ ) {
((RuleFlowEventListener) this.listeners.get( i ))
- .ruleFlowGroupDeactivated( event, this.workingMemory );
+ .ruleFlowGroupDeactivated( event, workingMemory );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/WorkingMemoryEventSupport.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/WorkingMemoryEventSupport.java 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/WorkingMemoryEventSupport.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -23,6 +23,7 @@
import org.drools.FactHandle;
import org.drools.WorkingMemory;
+import org.drools.common.InternalWorkingMemory;
import org.drools.spi.PropagationContext;
/**
@@ -36,10 +37,8 @@
*/
private static final long serialVersionUID = -7572714148615479288L;
private final List listeners = Collections.synchronizedList( new ArrayList() );
- private final WorkingMemory workingMemory;
- public WorkingMemoryEventSupport(final WorkingMemory workingMemory) {
- this.workingMemory = workingMemory;
+ public WorkingMemoryEventSupport() {
}
public void addEventListener(final WorkingMemoryEventListener listener) {
@@ -66,12 +65,13 @@
public void fireObjectInserted(final PropagationContext propagationContext,
final FactHandle handle,
- final Object object) {
+ final Object object,
+ final InternalWorkingMemory workingMemory) {
if ( this.listeners.isEmpty() ) {
return;
}
- final ObjectInsertedEvent event = new ObjectInsertedEvent( this.workingMemory,
+ final ObjectInsertedEvent event = new ObjectInsertedEvent( workingMemory,
propagationContext,
handle,
object );
@@ -84,12 +84,13 @@
public void fireObjectUpdated(final PropagationContext propagationContext,
final FactHandle handle,
final Object oldObject,
- final Object object) {
+ final Object object,
+ final InternalWorkingMemory workingMemory) {
if ( this.listeners.isEmpty() ) {
return;
}
- final ObjectUpdatedEvent event = new ObjectUpdatedEvent( this.workingMemory,
+ final ObjectUpdatedEvent event = new ObjectUpdatedEvent( workingMemory,
propagationContext,
handle,
oldObject,
@@ -102,12 +103,13 @@
public void fireObjectRetracted(final PropagationContext propagationContext,
final FactHandle handle,
- final Object oldObject) {
+ final Object oldObject,
+ final InternalWorkingMemory workingMemory ) {
if ( this.listeners.isEmpty() ) {
return;
}
- final ObjectRetractedEvent event = new ObjectRetractedEvent( this.workingMemory,
+ final ObjectRetractedEvent event = new ObjectRetractedEvent( workingMemory,
propagationContext,
handle,
oldObject );
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 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -222,7 +222,7 @@
}
ExecutorService executor = this.config.getExecutorService();
- final ReteooStatefulSession session = new ReteooStatefulSession( this.workingMemoryCounter++,
+ final ReteooStatefulSession session = new ReteooStatefulSession( nextWorkingMemoryCounter(),
this,
executor );
@@ -245,19 +245,13 @@
}
public StatelessSession newStatelessSession() {
- ExecutorService executor = this.config.getExecutorService();
-
+
//orders the rules
if ( this.config.isSequential() ) {
this.reteooBuilder.order();
- }
+ }
- ReteooWorkingMemory wm = new ReteooWorkingMemory( this.workingMemoryCounter++,
- this );
-
- executor.setCommandExecutor( new CommandExecutor( wm ) );
-
- return new ReteooStatelessSession( wm, executor );
+ return new ReteooStatelessSession( this );
}
protected synchronized void addRule(final Rule rule) throws InvalidPatternException {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -1,115 +1,198 @@
package org.drools.reteoo;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.drools.ObjectFilter;
import org.drools.StatelessSession;
import org.drools.StatelessSessionResult;
import org.drools.WorkingMemory;
import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
import org.drools.concurrent.AssertObject;
import org.drools.concurrent.AssertObjects;
+import org.drools.concurrent.CommandExecutor;
import org.drools.concurrent.ExecutorService;
import org.drools.concurrent.FireAllRules;
import org.drools.concurrent.Future;
import org.drools.event.AgendaEventListener;
+import org.drools.event.AgendaEventSupport;
+import org.drools.event.RuleFlowEventListener;
+import org.drools.event.RuleFlowEventSupport;
+import org.drools.event.WorkingMemoryEventListener;
+import org.drools.event.WorkingMemoryEventSupport;
import org.drools.spi.AgendaFilter;
import org.drools.spi.GlobalResolver;
-public class ReteooStatelessSession implements StatelessSession {
- private WorkingMemory workingMemory;
- private final ExecutorService executor;
- private AgendaFilter agendaFilter;
+public class ReteooStatelessSession
+ implements
+ StatelessSession {
+ //private WorkingMemory workingMemory;
- public ReteooStatelessSession(final WorkingMemory workingMemory,
- final ExecutorService executorService) {
- this.workingMemory = workingMemory;
- this.executor = executorService;
- }
+ private InternalRuleBase ruleBase;
+ private AgendaFilter agendaFilter;
+ private Map globals = new HashMap();
+ private GlobalResolver globalResolver;
- public void addEventListener(AgendaEventListener listener) {
- this.workingMemory.addEventListener( listener );
+ /** The eventSupport */
+ protected WorkingMemoryEventSupport workingMemoryEventSupport = new WorkingMemoryEventSupport();
+
+ protected AgendaEventSupport agendaEventSupport = new AgendaEventSupport();
+
+ protected RuleFlowEventSupport ruleFlowEventSupport = new RuleFlowEventSupport();
+
+ public ReteooStatelessSession(final InternalRuleBase ruleBase) {
+ this.ruleBase = ruleBase;
}
+ public InternalWorkingMemory newWorkingMemory() {
+ InternalWorkingMemory wm = new ReteooWorkingMemory( this.ruleBase.nextWorkingMemoryCounter(),
+ this.ruleBase );
+
+ wm.setGlobals( globals );
+ if ( globalResolver != null ) {
+ wm.setGlobalResolver( this.globalResolver );
+ }
+ wm.setWorkingMemoryEventSupport( this.workingMemoryEventSupport );
+ wm.setAgendaEventSupport( this.agendaEventSupport );
+ wm.setRuleFlowEventSupport( ruleFlowEventSupport );
+
+ return wm;
+ }
+
+ public void addEventListener(final WorkingMemoryEventListener listener) {
+ this.workingMemoryEventSupport.addEventListener( listener );
+ }
+
+ public void removeEventListener(final WorkingMemoryEventListener listener) {
+ this.workingMemoryEventSupport.removeEventListener( listener );
+ }
+
public List getWorkingMemoryEventListeners() {
- return this.workingMemory.getWorkingMemoryEventListeners();
+ return this.workingMemoryEventSupport.getEventListeners();
}
- public void removeEventListener(AgendaEventListener listener) {
- this.removeEventListener( listener );
+ public void addEventListener(final AgendaEventListener listener) {
+ this.agendaEventSupport.addEventListener( listener );
}
+ public void removeEventListener(final AgendaEventListener listener) {
+ this.agendaEventSupport.removeEventListener( listener );
+ }
+
+ public List getAgendaEventListeners() {
+ return this.agendaEventSupport.getEventListeners();
+ }
+
+ public void addEventListener(final RuleFlowEventListener listener) {
+ this.ruleFlowEventSupport.addEventListener( listener );
+ }
+
+ public void removeEventListener(final RuleFlowEventListener listener) {
+ this.ruleFlowEventSupport.removeEventListener( listener );
+ }
+
+ public List getRuleFlowEventListeners() {
+ return this.ruleFlowEventSupport.getEventListeners();
+ }
+
public void setAgendaFilter(AgendaFilter agendaFilter) {
this.agendaFilter = agendaFilter;
}
-
+
public void setGlobal(String identifier,
Object value) {
- this.workingMemory.setGlobal( identifier, value );
+ this.globals.put( identifier,
+ value );
}
public void setGlobalResolver(GlobalResolver globalResolver) {
- this.workingMemory.setGlobalResolver( globalResolver );
+ this.globalResolver = globalResolver;
}
- public void execute(Object object) {
- this.workingMemory.insert( object );
- this.workingMemory.fireAllRules( this.agendaFilter );
+ public void execute(Object object) {
+ InternalWorkingMemory wm = newWorkingMemory();
+
+ wm.insert( object );
+ wm.fireAllRules( this.agendaFilter );
}
public void execute(Object[] array) {
+ InternalWorkingMemory wm = newWorkingMemory();
+
for ( int i = 0, length = array.length; i < length; i++ ) {
- this.workingMemory.insert( array[i] );
+ wm.insert( array[i] );
}
- this.workingMemory.fireAllRules( this.agendaFilter );
+ wm.fireAllRules( this.agendaFilter );
}
public void execute(Collection collection) {
- for( Iterator it = collection.iterator(); it.hasNext(); ) {
- this.workingMemory.insert( it.next() );
+ InternalWorkingMemory wm = newWorkingMemory();
+
+ for ( Iterator it = collection.iterator(); it.hasNext(); ) {
+ wm.insert( it.next() );
}
- this.workingMemory.fireAllRules( this.agendaFilter );
+ wm.fireAllRules( this.agendaFilter );
}
-
+
public void asyncExecute(final Object object) {
+ InternalWorkingMemory wm = newWorkingMemory();
+
final AssertObject assertObject = new AssertObject( object );
- this.executor.submit( assertObject );
- this.executor.submit( new FireAllRules( this.agendaFilter ) );
- }
-
+ ExecutorService executor = this.ruleBase.getConfiguration().getExecutorService();
+ executor.setCommandExecutor( new CommandExecutor( wm ) );
+ executor.submit( assertObject );
+ executor.submit( new FireAllRules( this.agendaFilter ) );
+ }
+
public void asyncExecute(final Object[] array) {
+ InternalWorkingMemory wm = newWorkingMemory();
+
final AssertObjects assertObjects = new AssertObjects( array );
- this.executor.submit( assertObjects );
- this.executor.submit( new FireAllRules( this.agendaFilter ) );
+ ExecutorService executor = this.ruleBase.getConfiguration().getExecutorService();
+ executor.setCommandExecutor( new CommandExecutor( wm ) );
+ executor.submit( assertObjects );
+ executor.submit( new FireAllRules( this.agendaFilter ) );
}
-
+
public void asyncExecute(final Collection collection) {
+ InternalWorkingMemory wm = newWorkingMemory();
+
final AssertObjects assertObjects = new AssertObjects( collection );
- this.executor.submit( assertObjects );
- this.executor.submit( new FireAllRules( this.agendaFilter ) );
- }
-
+ ExecutorService executor = this.ruleBase.getConfiguration().getExecutorService();
+ executor.setCommandExecutor( new CommandExecutor( wm ) );
+ executor.submit( assertObjects );
+ executor.submit( new FireAllRules( this.agendaFilter ) );
+ }
+
public StatelessSessionResult executeWithResults(Object object) {
- this.workingMemory.insert( object );
- this.workingMemory.fireAllRules( this.agendaFilter );
- return new ReteStatelessSessionResult( this.workingMemory );
+ InternalWorkingMemory wm = newWorkingMemory();
+
+ wm.insert( object );
+ wm.fireAllRules( this.agendaFilter );
+ return new ReteStatelessSessionResult( wm );
}
public StatelessSessionResult executeWithResults(Object[] array) {
+ InternalWorkingMemory wm = newWorkingMemory();
+
for ( int i = 0, length = array.length; i < length; i++ ) {
- this.workingMemory.insert( array[i] );
+ wm.insert( array[i] );
}
- this.workingMemory.fireAllRules( this.agendaFilter );
- return new ReteStatelessSessionResult( this.workingMemory );
+ wm.fireAllRules( this.agendaFilter );
+ return new ReteStatelessSessionResult( wm );
}
public StatelessSessionResult executeWithResults(Collection collection) {
- for( Iterator it = collection.iterator(); it.hasNext(); ) {
- this.workingMemory.insert( it.next() );
+ InternalWorkingMemory wm = newWorkingMemory();
+
+ for ( Iterator it = collection.iterator(); it.hasNext(); ) {
+ wm.insert( it.next() );
}
- this.workingMemory.fireAllRules( this.agendaFilter );
- return new ReteStatelessSessionResult( this.workingMemory );
- }
+ wm.fireAllRules( this.agendaFilter );
+ return new ReteStatelessSessionResult( wm );
+ }
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/RuleFlowProcessInstance.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/RuleFlowProcessInstance.java 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/RuleFlowProcessInstance.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -20,6 +20,7 @@
import org.drools.Agenda;
import org.drools.WorkingMemory;
+import org.drools.common.InternalWorkingMemory;
import org.drools.ruleflow.common.instance.ProcessInstance;
import org.drools.ruleflow.core.Node;
import org.drools.ruleflow.core.RuleFlowProcess;
@@ -45,7 +46,7 @@
RuleFlowNodeInstance getFirstNodeInstance(long nodeId);
- void setWorkingMemory(WorkingMemory workingMemory);
+ void setWorkingMemory(InternalWorkingMemory workingMemory);
WorkingMemory getWorkingMemory();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ruleflow/instance/impl/RuleFlowProcessInstanceImpl.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -25,6 +25,7 @@
import org.drools.Agenda;
import org.drools.WorkingMemory;
import org.drools.common.EventSupport;
+import org.drools.common.InternalWorkingMemory;
import org.drools.ruleflow.common.instance.impl.ProcessInstanceImpl;
import org.drools.ruleflow.core.EndNode;
import org.drools.ruleflow.core.Join;
@@ -47,7 +48,7 @@
private static final long serialVersionUID = -6760756665603399413L;
- private WorkingMemory workingMemory;
+ private InternalWorkingMemory workingMemory;
private final List nodeInstances = new ArrayList();
public RuleFlowProcess getRuleFlowProcess() {
@@ -84,7 +85,7 @@
return this.workingMemory.getAgenda();
}
- public void setWorkingMemory(final WorkingMemory workingMemory) {
+ public void setWorkingMemory(final InternalWorkingMemory workingMemory) {
if (this.workingMemory != null) {
throw new IllegalArgumentException("A working memory can only be set once.");
}
@@ -143,7 +144,7 @@
super.setState(state);
if (state == ProcessInstanceImpl.STATE_COMPLETED) {
((EventSupport) this.workingMemory).getRuleFlowEventSupport()
- .fireRuleFlowProcessCompleted(this);
+ .fireRuleFlowProcessCompleted(this, this.workingMemory);
}
}
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 2007-07-02 03:38:46 UTC (rev 12992)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java 2007-07-02 04:33:18 UTC (rev 12993)
@@ -34,6 +34,7 @@
import org.drools.common.InternalAgenda;
import org.drools.common.InternalAgendaGroup;
import org.drools.common.InternalRuleBase;
+import org.drools.common.InternalWorkingMemory;
import org.drools.common.PropagationContextImpl;
import org.drools.common.RuleFlowGroupImpl;
import org.drools.conflict.DepthConflictResolver;
@@ -1456,7 +1457,7 @@
ruleBase.getAgendaGroupRuleTotals().put( "agendaGroup1", new Integer( 10 ) );
ruleBase.getAgendaGroupRuleTotals().put( "agendaGroup2", new Integer( 1 ) );
- final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+ InternalWorkingMemory workingMemory = new ReteooWorkingMemory(0, ruleBase);
final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
More information about the jboss-svn-commits
mailing list