[jboss-svn-commits] JBL Code SVN: r9605 - in labs/jbossrules/trunk/drools-jsr94: src/main/java/org/drools/jsr94/rules and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Feb 19 11:32:29 EST 2007


Author: mark.proctor at jboss.com
Date: 2007-02-19 11:32:28 -0500 (Mon, 19 Feb 2007)
New Revision: 9605

Modified:
   labs/jbossrules/trunk/drools-jsr94/.classpath
   labs/jbossrules/trunk/drools-jsr94/.project
   labs/jbossrules/trunk/drools-jsr94/pom.xml
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/AbstractRuleSessionImpl.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatefulRuleSessionImpl.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatelessRuleSessionImpl.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetImpl.java
Log:
JBRULES-607 Working memory is not disposed when releasing the RuleSession
-WorkingMemories now dispose() correctly, and stateless sessions no longer request to keep references
-Minor refactor for more code reuse

Modified: labs/jbossrules/trunk/drools-jsr94/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/.classpath	2007-02-19 15:58:17 UTC (rev 9604)
+++ labs/jbossrules/trunk/drools-jsr94/.classpath	2007-02-19 16:32:28 UTC (rev 9605)
@@ -1,23 +1,29 @@
 <classpath>
   <classpathentry kind="src" path="src/main/java"/>
-  <classpathentry kind="src" path="src/main/resources"/>
+  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
   <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
-  <classpathentry kind="src" path="src/test/resources" output="target/test-classes"/>
+  <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
   <classpathentry kind="output" path="target/classes"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/commons/commons-jci-janino/2.4.3/commons-jci-janino-2.4.3.jar"/>
   <classpathentry kind="var" path="M2_REPO/jsr94/jsr94/1.1/jsr94-1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/commons/commons-jci-eclipse/3.2.0.666/commons-jci-eclipse-3.2.0.666.jar"/>
+  <classpathentry kind="var" path="M2_REPO/commons-lang/commons-lang/2.1/commons-lang-2.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/antlr/antlr/3.0ea8/antlr-3.0ea8.jar"/>
+  <classpathentry kind="var" path="M2_REPO/commons-io/commons-io/1.1/commons-io-1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/commons/commons-jci-core/1.0-406301/commons-jci-core-1.0-406301.jar"/>
+  <classpathentry kind="var" path="M2_REPO/commons-collections/commons-collections/3.1/commons-collections-3.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"/>
+  <classpathentry kind="src" path="/drools-compiler"/>
   <classpathentry kind="var" path="M2_REPO/jsr94/jsr94-tck/1.0.3/jsr94-tck-1.0.3.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.0.666/core-3.2.0.666.jar"/>
+  <classpathentry kind="var" path="M2_REPO/janino/janino/2.4.3/janino-2.4.3.jar"/>
+  <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar"/>
+  <classpathentry kind="src" path="/drools-core"/>
+  <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
   <classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
+  <classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jar"/>
   <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
-  <classpathentry kind="src" path="/drools-core"/>
-  <classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.1.v_677_R32x/core-3.2.1.v_677_R32x.jar"/>
-  <classpathentry kind="src" path="/drools-compiler"/>
-  <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta6/mvel14-1.2beta6.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/antlr/antlr/3.0b5/antlr-3.0b5.jar"/>
-  <classpathentry kind="var" path="M2_REPO/antlr/stringtemplate/3.0/stringtemplate-3.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
-  <classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.7/antlr-2.7.7.jar"/>
   <classpathentry kind="var" path="M2_REPO/jsr94/jsr94-sigtest/1.1/jsr94-sigtest-1.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.5/janino-2.5.5.jar"/>
+  <classpathentry kind="var" path="M2_REPO/antlr/stringtemplate/2.3b6/stringtemplate-2.3b6.jar"/>
 </classpath>
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-jsr94/.project
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/.project	2007-02-19 15:58:17 UTC (rev 9604)
+++ labs/jbossrules/trunk/drools-jsr94/.project	2007-02-19 16:32:28 UTC (rev 9605)
@@ -1,14 +1,13 @@
 <projectDescription>
   <name>drools-jsr94</name>
-  <comment>A rule production system</comment>
+  <comment/>
   <projects>
-    <project>drools-core</project>
     <project>drools-compiler</project>
+    <project>drools-core</project>
   </projects>
   <buildSpec>
     <buildCommand>
       <name>org.eclipse.jdt.core.javabuilder</name>
-      <arguments/>
     </buildCommand>
   </buildSpec>
   <natures>

Modified: labs/jbossrules/trunk/drools-jsr94/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/pom.xml	2007-02-19 15:58:17 UTC (rev 9604)
+++ labs/jbossrules/trunk/drools-jsr94/pom.xml	2007-02-19 16:32:28 UTC (rev 9605)
@@ -1,77 +1,107 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
-    <artifactId>drools</artifactId>
-    <groupId>org.drools</groupId>
-	<version>3.1.0-M1</version>
-  </parent>
-
-  <artifactId>drools-jsr94</artifactId>
-  <packaging>jar</packaging>
-  <name>Drools :: JSR-94 API Module</name>
-  
-  <repositories>
-    <repository>
-      <id>basedir</id>
-      <url>file://${basedir}/../repository</url>
-    </repository>
-  </repositories>
-
-  <build>
-    <plugins>
-	  <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <systemProperties>
-            <property>
-              <name>jsr94.tck.configuration</name>
-              <value>${basedir}/target/test-classes/org/drools/jsr94/tck</value>
-            </property>
-          </systemProperties>
-          <includes>
-            <include>**/*Tests.java</include>
-            <include>**/*Test.java</include>
-          </includes>
-          <excludes>
-            <exclude>**/ClassLoaderTest.java</exclude>
-            <exclude>**/RuleExecutionSetProviderTest.java</exclude>
-          </excludes>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-  
-  <dependencies>
-    <!-- Internal dependencies -->
-    <dependency>
-      <groupId>org.drools</groupId>
-      <artifactId>drools-core</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.drools</groupId>
-      <artifactId>drools-compiler</artifactId>
-    </dependency>
-
-    <!-- External dependencies -->
-    <dependency>
-      <groupId>jsr94</groupId>
-      <artifactId>jsr94</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>jsr94</groupId>
-      <artifactId>jsr94-tck</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>jsr94</groupId>
-      <artifactId>jsr94-sigtest</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>xml-apis</groupId>
-      <artifactId>xml-apis</artifactId>
-    </dependency>
-  </dependencies>
-
-</project>
+<project>
+  <parent>
+    <artifactId>drools</artifactId>
+    <groupId>org.drools</groupId>
+    <version>3.0.5</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>drools-jsr94</artifactId>
+
+  <name>Drools :: JSR-94 API Module</name>
+  <version>3.0.5</version>
+  
+  <repositories>
+    <repository>
+      <id>basedir</id>
+      <url>file://${basedir}/../repository</url>
+    </repository>
+  </repositories>  
+  
+  <dependencies>  
+        <dependency>
+            <groupId>org.drools</groupId>
+            <artifactId>drools-compiler</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>jsr94</groupId>
+            <artifactId>jsr94</artifactId>
+            <version>1.1</version>
+        </dependency>
+		
+        <dependency>
+            <groupId>jsr94</groupId>
+            <artifactId>jsr94-tck</artifactId>
+            <version>1.0.3</version>
+        </dependency>
+
+        <dependency>
+            <groupId>jsr94</groupId>
+            <artifactId>jsr94-sigtest</artifactId>
+            <version>1.1</version>
+        </dependency>  
+        
+        <dependency>
+            <groupId>xml-apis</groupId>
+            <artifactId>xml-apis</artifactId>
+            <version>1.0.b2</version>
+        </dependency>          
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <executions>
+            <execution>
+                <id>package</id>
+                <phase>package</phase>
+                <configuration>
+                    <tasks>
+                        <echo message="Copying file ${project.build.directory}/${project.artifactId}-${project.version}.${project.packaging} to ../drools-ide/lib/${project.artifactId}.${project.packaging}" />
+                        <copy file="${project.build.directory}/${project.artifactId}-${project.version}.${project.packaging}" tofile="../drools-ide/lib/${project.artifactId}.${project.packaging}" />
+                    </tasks>
+                </configuration>
+                <goals>
+                    <goal>run</goal>
+                </goals>
+            </execution>
+        </executions>
+        <dependencies>
+	        <dependency>
+                <groupId>ant</groupId>
+                <artifactId>ant-antlr</artifactId>
+                <version>1.6.5</version>
+	        </dependency>
+        </dependencies>
+      </plugin>      
+      
+	    <plugin>
+	      <groupId>org.apache.maven.plugins</groupId>
+	      <artifactId>maven-surefire-plugin</artifactId>
+	      <configuration>
+	      <systemProperties>
+          <property>
+            <name>jsr94.tck.configuration</name>
+            <value>${basedir}/target/test-classes/org/drools/jsr94/tck</value>
+          </property>
+        </systemProperties>p
+	        <includes>
+	          <include>**/*Tests.java</include>
+	          <include>**/*Test.java</include>	          
+	        </includes>
+	        <excludes>
+	          <exclude>**/ClassLoaderTest.java</exclude>
+              <exclude>**/RuleExecutionSetProviderTest.java</exclude>
+            </excludes>
+	      </configuration>
+	    </plugin>      
+    </plugins>
+  </build>
+
+
+</project>
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/AbstractRuleSessionImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/AbstractRuleSessionImpl.java	2007-02-19 15:58:17 UTC (rev 9604)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/AbstractRuleSessionImpl.java	2007-02-19 16:32:28 UTC (rev 9605)
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -65,7 +66,7 @@
      * The Drools <code>WorkingMemory</code> associated
      * with this <code>RuleSession</code>.
      */
-    private WorkingMemory        workingMemory;
+    protected WorkingMemory        workingMemory;
 
     /**
      * The Drools <code>RuleExecutionSet</code> associated
@@ -82,28 +83,10 @@
     /**
      * Initialize this <code>RuleSession</code>
      * with a new <code>WorkingMemory</code>.
-     *
-     * @see #newWorkingMemory()
      */
-    protected void initWorkingMemory() {
-        this.setWorkingMemory( newWorkingMemory() );
-    }
+    protected void initWorkingMemory(boolean keepReference) {        
+        final WorkingMemory newWorkingMemory = this.getRuleExecutionSet().newWorkingMemory(keepReference);
 
-    /**
-     * Creates a new <code>WorkingMemory</code> for this
-     * <code>RuleSession</code>. All properties set prior to calling this method
-     * are added as application data to the new <code>WorkingMemory</code>.
-     * The created <code>WorkingMemory</code> uses the default conflict
-     * resolution strategy.
-     *
-     * @return the new <code>WorkingMemory</code>.
-     *
-     * @see #setProperties(Map)
-     * @see WorkingMemory#setApplicationData(String, Object)
-     */
-    protected WorkingMemory newWorkingMemory() {
-        final WorkingMemory newWorkingMemory = this.getRuleExecutionSet().newWorkingMemory();
-
         final Map props = this.getProperties();
         if ( props != null ) {
             for ( final Iterator iterator = props.entrySet().iterator(); iterator.hasNext(); ) {
@@ -112,8 +95,8 @@
                                             entry.getValue() );
             }
         }
-
-        return newWorkingMemory;
+        
+        this.setWorkingMemory( newWorkingMemory );
     }
 
     /**
@@ -145,6 +128,10 @@
      *        with this <code>RuleSession</code>.
      */
     protected void setWorkingMemory(final WorkingMemory workingMemory) {
+        // first dispose any existing working memories
+        if ( this.workingMemory != null ) {
+            this.workingMemory.dispose();
+        }        
         this.workingMemory = workingMemory;
     }
 
@@ -192,27 +179,71 @@
             throw new InvalidRuleSessionException( "invalid rule session" );
         }
     }
+    
+    /**
+     * Returns a List of all objects in the rule session state of this rule
+     * session. The objects should pass the default filter test of the default
+     * <code>RuleExecutionSet</code> filter (if present). <p/> This may not
+     * neccessarily include all objects added by calls to <code>addObject</code>,
+     * and may include <code>Object</code>s created by side-effects. The
+     * execution of a <code>RuleExecutionSet</code> can add, remove and update
+     * objects as part of the rule session state. Therefore the rule session
+     * state is dependent on the rules that are part of the executed
+     * <code>RuleExecutionSet</code> as well as the rule vendor's specific
+     * rule engine behavior.
+     * 
+     * @return a <code>List</code> of all objects part of the rule session
+     *         state.
+     * 
+     * @throws InvalidRuleSessionException
+     *             on illegal rule session state.
+     */
+    public List getObjects() throws InvalidRuleSessionException {
+        checkRuleSessionValidity();
 
+        return getObjects( getRuleExecutionSet().getObjectFilter() );
+    }    
+    
     /**
-     * Applies the given <code>ObjectFilter</code> to the <code>List</code> of
-     * <code>Object</code>s, removing all <code>Object</code>s from the given
-     * <code>List</code> that do not pass the filter.
-     *
-     * @param objects <code>List</code> of <code>Object</code>s to be filtered
-     * @param objectFilter the <code>ObjectFilter</code> to be applied
+     * Returns a <code>List</code> over the objects in rule session state of
+     * this rule session. The objects should pass the filter test on the
+     * specified <code>ObjectFilter</code>. <p/> This may not neccessarily
+     * include all objects added by calls to <code>addObject</code>, and may
+     * include <code>Object</code>s created by side-effects. The execution of
+     * a <code>RuleExecutionSet</code> can add, remove and update objects as
+     * part of the rule session state. Therefore the rule session state is
+     * dependent on the rules that are part of the executed
+     * <code>RuleExecutionSet</code> as well as the rule vendor's specific
+     * rule engine behavior.
+     * 
+     * @param filter
+     *            the object filter.
+     * 
+     * @return a <code>List</code> of all the objects in the rule session
+     *         state of this rule session based upon the given object filter.
+     * 
+     * @throws InvalidRuleSessionException
+     *             on illegal rule session state.
      */
-    protected void applyFilter(final List objects,
-                               final ObjectFilter objectFilter) {
-        if ( objectFilter != null ) {
+    public List getObjects(final ObjectFilter filter) throws InvalidRuleSessionException {
+        checkRuleSessionValidity();
+
+        final List objects = new ArrayList();
+
+        objects.addAll( getWorkingMemory().getObjects() );
+
+        if ( filter != null ) {
             for ( final Iterator objectIter = objects.iterator(); objectIter.hasNext(); ) {
                 final Object object = objectIter.next();
-                if ( objectFilter.filter( object ) == null ) {
+                if ( filter.filter( object ) == null ) {
                     objectIter.remove();
                 }
             }
         }
-    }
 
+        return objects;
+    }    
+
     // JSR94 interface methods start here -------------------------------------
 
     /**
@@ -238,48 +269,16 @@
     }
 
     /**
-     * Returns the type identifier for this <code>RuleSession</code>. The
-     * type identifiers are defined in the <code>RuleRuntime</code> interface.
-     *
-     * @return the type identifier for this <code>RuleSession</code>
-     *
-     * @throws InvalidRuleSessionException on illegal rule session state.
-     *
-     * @see RuleRuntime#STATEFUL_SESSION_TYPE
-     * @see RuleRuntime#STATELESS_SESSION_TYPE
-     */
-    public int getType() throws InvalidRuleSessionException {
-        if ( this instanceof StatelessRuleSession ) {
-            return RuleRuntime.STATELESS_SESSION_TYPE;
-        }
-
-        if ( this instanceof StatefulRuleSession ) {
-            return RuleRuntime.STATEFUL_SESSION_TYPE;
-        }
-
-        throw new InvalidRuleSessionException( "unknown type" );
-    }
-
-    /**
      * Releases all resources used by this rule session.
      * This method renders this rule session unusable until
      * it is reacquired through the <code>RuleRuntime</code>.
      */
     public void release() {
+        if ( this.workingMemory != null ) {
+            this.workingMemory.dispose();
+        }
         setProperties( null );
         setWorkingMemory( null );
         setRuleExecutionSet( null );
     }
-
-    /**
-     * Resets this rule session. Calling this method will bring the rule session
-     * state to its initial state for this rule session and will reset any other
-     * state associated with this rule session.
-     * <p/>
-     * A reset will not reset the state on the default object filter for a
-     * <code>RuleExecutionSet</code>.
-     */
-    public void reset() {
-        initWorkingMemory();
-    }
 }

Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatefulRuleSessionImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatefulRuleSessionImpl.java	2007-02-19 15:58:17 UTC (rev 9604)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatefulRuleSessionImpl.java	2007-02-19 16:32:28 UTC (rev 9605)
@@ -27,6 +27,7 @@
 import javax.rules.InvalidRuleSessionException;
 import javax.rules.ObjectFilter;
 import javax.rules.RuleExecutionSetNotFoundException;
+import javax.rules.RuleRuntime;
 import javax.rules.StatefulRuleSession;
 
 import org.drools.FactException;
@@ -85,7 +86,7 @@
                             final Map properties,
                             final RuleExecutionSetRepository repository) throws RuleExecutionSetNotFoundException {
         super( repository );
-        this.setProperties( properties );
+        setProperties( properties );
 
         final RuleExecutionSetImpl ruleSet = (RuleExecutionSetImpl) repository.getRuleExecutionSet( bindUri );
 
@@ -95,7 +96,7 @@
 
         this.setRuleExecutionSet( ruleSet );
 
-        this.initWorkingMemory();
+        initWorkingMemory( true );
     }
 
     // ----------------------------------------------------------------------
@@ -114,7 +115,7 @@
      */
     public boolean containsObject(final Handle objectHandle) {
         if ( objectHandle instanceof FactHandle ) {
-            return this.getWorkingMemory().getObject( (FactHandle) objectHandle ) != null;
+            return getWorkingMemory().getObject( (FactHandle) objectHandle ) != null;
         }
 
         return false;
@@ -136,14 +137,8 @@
      *             on illegal rule session state.
      */
     public Handle addObject(final Object object) throws InvalidRuleSessionException {
-        this.checkRuleSessionValidity();
-
-        try {
-            return (Handle) this.getWorkingMemory().assertObject( object );
-        } catch ( final FactException e ) {
-            throw new InvalidRuleSessionException( "cannot assert object",
-                                                   e );
-        }
+        checkRuleSessionValidity();
+        return (Handle) getWorkingMemory().assertObject( object );
     }
 
     /**
@@ -161,12 +156,12 @@
      *             on illegal rule session state.
      */
     public List addObjects(final List objList) throws InvalidRuleSessionException {
-        this.checkRuleSessionValidity();
+        checkRuleSessionValidity();
 
         final List handles = new ArrayList();
 
         for ( final Iterator objectIter = objList.iterator(); objectIter.hasNext(); ) {
-            handles.add( this.addObject( objectIter.next() ) );
+            handles.add( addObject( objectIter.next() ) );
         }
         return handles;
     }
@@ -191,16 +186,11 @@
     public void updateObject(final Handle objectHandle,
                              final Object newObject) throws InvalidRuleSessionException,
                                                     InvalidHandleException {
-        this.checkRuleSessionValidity();
+        checkRuleSessionValidity();
 
         if ( objectHandle instanceof FactHandle ) {
-            try {
-                this.getWorkingMemory().modifyObject( (FactHandle) objectHandle,
-                                                      newObject );
-            } catch ( final FactException e ) {
-                throw new InvalidRuleSessionException( "cannot update object",
-                                                       e );
-            }
+            getWorkingMemory().modifyObject( (FactHandle) objectHandle,
+                                             newObject );
         } else {
             throw new InvalidHandleException( "invalid handle" );
 
@@ -221,79 +211,16 @@
      */
     public void removeObject(final Handle handleObject) throws InvalidRuleSessionException,
                                                        InvalidHandleException {
-        this.checkRuleSessionValidity();
+        checkRuleSessionValidity();
 
         if ( handleObject instanceof FactHandle ) {
-            try {
-                this.getWorkingMemory().retractObject( (FactHandle) handleObject );
-            } catch ( final FactException e ) {
-                throw new InvalidRuleSessionException( "cannot remove object",
-                                                       e );
-            }
+            getWorkingMemory().retractObject( (FactHandle) handleObject );
         } else {
             throw new InvalidHandleException( "invalid handle" );
         }
     }
 
     /**
-     * Returns a List of all objects in the rule session state of this rule
-     * session. The objects should pass the default filter test of the default
-     * <code>RuleExecutionSet</code> filter (if present). <p/> This may not
-     * neccessarily include all objects added by calls to <code>addObject</code>,
-     * and may include <code>Object</code>s created by side-effects. The
-     * execution of a <code>RuleExecutionSet</code> can add, remove and update
-     * objects as part of the rule session state. Therefore the rule session
-     * state is dependent on the rules that are part of the executed
-     * <code>RuleExecutionSet</code> as well as the rule vendor's specific
-     * rule engine behavior.
-     * 
-     * @return a <code>List</code> of all objects part of the rule session
-     *         state.
-     * 
-     * @throws InvalidRuleSessionException
-     *             on illegal rule session state.
-     */
-    public List getObjects() throws InvalidRuleSessionException {
-        this.checkRuleSessionValidity();
-
-        return this.getObjects( this.getRuleExecutionSet().getObjectFilter() );
-    }
-
-    /**
-     * Returns a <code>List</code> over the objects in rule session state of
-     * this rule session. The objects should pass the filter test on the
-     * specified <code>ObjectFilter</code>. <p/> This may not neccessarily
-     * include all objects added by calls to <code>addObject</code>, and may
-     * include <code>Object</code>s created by side-effects. The execution of
-     * a <code>RuleExecutionSet</code> can add, remove and update objects as
-     * part of the rule session state. Therefore the rule session state is
-     * dependent on the rules that are part of the executed
-     * <code>RuleExecutionSet</code> as well as the rule vendor's specific
-     * rule engine behavior.
-     * 
-     * @param filter
-     *            the object filter.
-     * 
-     * @return a <code>List</code> of all the objects in the rule session
-     *         state of this rule session based upon the given object filter.
-     * 
-     * @throws InvalidRuleSessionException
-     *             on illegal rule session state.
-     */
-    public List getObjects(final ObjectFilter filter) throws InvalidRuleSessionException {
-        this.checkRuleSessionValidity();
-
-        final List objects = new ArrayList();
-
-        objects.addAll( this.getWorkingMemory().getObjects() );
-
-        this.applyFilter( objects,
-                          filter );
-
-        return objects;
-    }
-
-    /**
      * Executes the rules in the bound rule execution set using the objects
      * present in the rule session state. This will typically modify the rule
      * session state - and may add, remove or update <code>Object</code>s
@@ -303,13 +230,8 @@
      *             on illegal rule session state.
      */
     public void executeRules() throws InvalidRuleSessionException {
-        this.checkRuleSessionValidity();
-
-        //		try {
-        this.getWorkingMemory().fireAllRules();
-        //		} catch (DroolsException e) {
-        //			throw new InvalidRuleSessionException("cannot execute rules", e);
-        //		}
+        checkRuleSessionValidity();
+        getWorkingMemory().fireAllRules();
     }
 
     /**
@@ -317,15 +239,10 @@
      */
     public Object getObject(final Handle handle) throws InvalidRuleSessionException,
                                                 InvalidHandleException {
-        this.checkRuleSessionValidity();
+       checkRuleSessionValidity();
 
         if ( handle instanceof FactHandle ) {
-            try {
-                return this.getWorkingMemory().getObject( (FactHandle) handle );
-            } catch ( final NoSuchFactObjectException e ) {
-                throw new InvalidHandleException( "invalid handle",
-                                                  e );
-            }
+            return getWorkingMemory().getObject( (FactHandle) handle );
         } else {
             throw new InvalidHandleException( "invalid handle" );
         }
@@ -340,7 +257,7 @@
      */
     public List getHandles() {
         final List handles = new LinkedList();
-        for ( final Iterator i = this.getWorkingMemory().getFactHandles().iterator(); i.hasNext(); ) {
+        for ( final Iterator i = getWorkingMemory().getFactHandles().iterator(); i.hasNext(); ) {
             final Object object = i.next();
             if ( object instanceof Handle ) {
                 handles.add( object );
@@ -348,4 +265,21 @@
         }
         return handles;
     }
+
+    /**
+     * Resets this rule session. Calling this method will bring the rule session
+     * state to its initial state for this rule session and will reset any other
+     * state associated with this rule session.
+     * <p/>
+     * A reset will not reset the state on the default object filter for a
+     * <code>RuleExecutionSet</code>.
+     */
+    public void reset() {
+        // stateful rule sessions should not be high load, thus safe to keep references
+        initWorkingMemory( true );
+    }
+
+    public int getType() throws InvalidRuleSessionException {
+        return RuleRuntime.STATEFUL_SESSION_TYPE;
+    }
 }

Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatelessRuleSessionImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatelessRuleSessionImpl.java	2007-02-19 15:58:17 UTC (rev 9604)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatelessRuleSessionImpl.java	2007-02-19 16:32:28 UTC (rev 9605)
@@ -22,6 +22,7 @@
 import javax.rules.InvalidRuleSessionException;
 import javax.rules.ObjectFilter;
 import javax.rules.RuleExecutionSetNotFoundException;
+import javax.rules.RuleRuntime;
 import javax.rules.StatelessRuleSession;
 
 import org.drools.FactException;
@@ -59,7 +60,7 @@
                              final Map properties,
                              final RuleExecutionSetRepository repository) throws RuleExecutionSetNotFoundException {
         super( repository );
-        this.setProperties( properties );
+        setProperties( properties );
 
         final RuleExecutionSetImpl ruleSet = (RuleExecutionSetImpl) repository.getRuleExecutionSet( bindUri );
 
@@ -67,7 +68,7 @@
             throw new RuleExecutionSetNotFoundException( "RuleExecutionSet unbound: " + bindUri );
         }
 
-        this.setRuleExecutionSet( ruleSet );
+        setRuleExecutionSet( ruleSet );
     }
 
     /**
@@ -94,8 +95,8 @@
      *             on illegal rule session state.
      */
     public List executeRules(final List objects) throws InvalidRuleSessionException {
-        return this.executeRules( objects,
-                                  this.getRuleExecutionSet().getObjectFilter() );
+        return executeRules( objects,
+                             this.getRuleExecutionSet().getObjectFilter() );
     }
 
     /**
@@ -124,24 +125,21 @@
      */
     public List executeRules(final List objects,
                              final ObjectFilter filter) throws InvalidRuleSessionException {
-        final WorkingMemory workingMemory = this.newWorkingMemory();
+        // get a new working memory with no references kept (i.e. it doesn't need to be disposed)
+        initWorkingMemory( false );
 
-        try {
-            for ( final Iterator objectIter = objects.iterator(); objectIter.hasNext(); ) {
-                workingMemory.assertObject( objectIter.next() );
-            }
-
-            workingMemory.fireAllRules();
-        } catch ( final FactException e ) {
-            throw new InvalidRuleSessionException( e.getMessage(),
-                                                   e );
+        WorkingMemory workingMemory = getWorkingMemory();
+        for ( final Iterator objectIter = objects.iterator(); objectIter.hasNext(); ) {
+            workingMemory.assertObject( objectIter.next() );
         }
+        workingMemory.fireAllRules();            
 
-        final List results = workingMemory.getObjects();
+        final List results = getObjects(filter);
 
-        this.applyFilter( results,
-                          filter );
-
         return results;
     }
+    
+    public int getType() throws InvalidRuleSessionException {
+        return RuleRuntime.STATELESS_SESSION_TYPE;
+    }
 }

Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetImpl.java	2007-02-19 15:58:17 UTC (rev 9604)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetImpl.java	2007-02-19 16:32:28 UTC (rev 9605)
@@ -31,7 +31,6 @@
 import org.drools.jsr94.rules.Jsr94FactHandleFactory;
 import org.drools.rule.Package;
 import org.drools.rule.Rule;
-import org.drools.util.UUIDGenerator;
 
 /**
  * The Drools implementation of the <code>RuleExecutionSet</code> interface
@@ -114,8 +113,7 @@
         this.pkg = pkg;
         this.description = pkg.getName();//..getDocumentation( );
 
-        final org.drools.reteoo.ReteooRuleBase ruleBase = new org.drools.reteoo.ReteooRuleBase( UUIDGenerator.getInstance().generateRandomBasedUUID().toString(),
-                                                                                                new Jsr94FactHandleFactory() );
+        final org.drools.reteoo.ReteooRuleBase ruleBase = new org.drools.reteoo.ReteooRuleBase( new Jsr94FactHandleFactory() );
         ruleBase.addPackage( pkg );
 
         this.ruleBase = ruleBase;
@@ -158,8 +156,8 @@
      *
      * @return A new WorkingMemory object.
      */
-    public WorkingMemory newWorkingMemory() {
-        return this.ruleBase.newWorkingMemory();
+    public WorkingMemory newWorkingMemory(boolean keepReference) {
+        return this.ruleBase.newWorkingMemory(keepReference);
     }
 
     // JSR94 interface methods start here -------------------------------------




More information about the jboss-svn-commits mailing list