[jboss-svn-commits] JBL Code SVN: r11274 - in labs/jbossrules/trunk: drools-compiler and 31 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Apr 23 18:54:04 EDT 2007


Author: mark.proctor at jboss.com
Date: 2007-04-23 18:54:04 -0400 (Mon, 23 Apr 2007)
New Revision: 11274

Added:
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IteratorToList.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ConcurrentStatelessSession.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ObjectFilter.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ReteConcurrentStatelessSession.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatefulSession.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSession.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSessionResult.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassObjectFilter.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/AssertObject.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/AssertObjects.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/Command.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/CommandExecutor.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/DefaultExecutorService.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/ExecutorService.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/FireAllRules.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/Future.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/InternalFuture.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/ModifyObject.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/RetractObject.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteStatelessSessionResult.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/JavaIteratorAdapter.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashSet.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ThreadSafeJavaIteratorAdapter.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/AbstractCollection.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/AbstractQueue.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Arrays.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/BlockingQueue.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/LinkedBlockingQueue.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/NanoTimer.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Queue.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/TimeUnit.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Utils.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/IteratorToList.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/ObjectFilterAdapter.java
Removed:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SynchronizedWorkingMemory.java
Modified:
   labs/jbossrules/trunk/drools-clips/pom.xml
   labs/jbossrules/trunk/drools-compiler/.classpath
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DslTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ExecutionFlowControlTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/TruthMaintenanceTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/waltz/Waltz.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilderTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilderTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilderTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilderTest.java
   labs/jbossrules/trunk/drools-core/.classpath
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBase.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/WorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.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/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/TruthMaintenanceSystem.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.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/util/AbstractHashTable.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashMap.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/DroolsTestCase.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/DelegateJavaFactHandlerTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AddRemoveTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CrossProductTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/OtherwiseTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooRuleBaseTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooWorkingMemoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java
   labs/jbossrules/trunk/drools-decisiontables/.classpath
   labs/jbossrules/trunk/drools-decisiontables/.project
   labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/DefaultTemplateRuleBase.java
   labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/ExternalSheetListener.java
   labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/TemplateRuleBase.java
   labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/acme/insurance/launcher/PricingRuleLauncher.java
   labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/ExternalSpreadsheetCompilerIntegrationTest.java
   labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/SpreadsheetIntegrationTest.java
   labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/DefaultTemplateRuleBaseTest.java
   labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath
   labs/jbossrules/trunk/drools-jbrms/.classpath
   labs/jbossrules/trunk/drools-jbrms/.project
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/modeldriven/ui/RuleModeller.java
   labs/jbossrules/trunk/drools-jsr94/.classpath
   labs/jbossrules/trunk/drools-jsr94/.project
   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
   labs/jbossrules/trunk/drools-repository/.classpath
Log:
JBRULES-814 Seperate the interfaces into Stateless and Stateful

JBRULES-541 Avoid WeakHashmap for tracking working memories in a RuleBase.
-WeakHashMap is now gone

JBRULES-144 async assert
-StatelessSession and StatefulSession now both support async methods

Modified: labs/jbossrules/trunk/drools-clips/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-clips/pom.xml	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-clips/pom.xml	2007-04-23 22:54:04 UTC (rev 11274)
@@ -15,7 +15,7 @@
   <repositories>
     <repository>
       <id>basedir</id>
-      <url>file://${basedir}/../repository</url>
+      <url>file://${basedir}/../m2_repo</url>
     </repository>
   </repositories>
 

Modified: labs/jbossrules/trunk/drools-compiler/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-compiler/.classpath	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/.classpath	2007-04-23 22:54:04 UTC (rev 11274)
@@ -5,16 +5,16 @@
   <classpathentry kind="src" path="src/test/resources" output="target/test-classes"/>
   <classpathentry kind="output" path="target/classes"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+  <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="var" path="M2_REPO/antlr/antlr/2.7.7/antlr-2.7.7.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta15/mvel14-1.2beta15.jar"/>
+  <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/antlr/antlr/3.0b5/antlr-3.0b5.jar"/>
+  <classpathentry kind="src" path="/drools-core"/>
   <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.5/janino-2.5.5.jar"/>
+  <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/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta15/mvel14-1.2beta15.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/antlr/antlr/3.0b5/antlr-3.0b5.jar"/>
   <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.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/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="var" path="M2_REPO/antlr/stringtemplate/3.0/stringtemplate-3.0.jar"/>
-  <classpathentry kind="src" path="/drools-core"/>
 </classpath>
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -154,7 +154,7 @@
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         ruleBase.getGlobals().put( "map",
                                    Map.class );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final HashMap map = new HashMap();
         workingMemory.setGlobal( "map",
@@ -231,7 +231,7 @@
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         ruleBase.getGlobals().put( "map",
                                    Map.class );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final HashMap map = new HashMap();
 
@@ -348,7 +348,7 @@
         } catch ( final Exception e ) {
             e.printStackTrace();
         }
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final Fact stilton = pkg.getFactTemplate( "Cheese" ).createFact( 1 );
         stilton.setFieldValue( "name",
                                "stilton" );

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DslTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DslTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DslTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -53,7 +53,7 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
         wm.assertObject( new Person( "Bob",
                                      "http://foo.bar" ) );
         wm.assertObject( new Cheese( "stilton",
@@ -92,7 +92,7 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
         wm.assertObject( new Person( "rage" ) );
         wm.assertObject( new Cheese( "cheddar",
                                      15 ) );

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -43,7 +43,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg1 );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         workingMemory.setGlobal( "total",
                                  new Integer( 0 ) );
 
@@ -154,7 +154,7 @@
         builder2.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic2.drl" ) ) );
         ruleBase.addPackage( builder2.getPackage() );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -254,7 +254,7 @@
         }
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         if ( reteooRuleBase != null ) {
             assertEquals( 1,
@@ -304,7 +304,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -371,7 +371,7 @@
         final String packageName = builder.getPackage().getName();
         ruleBase.addPackage( builder.getPackage() );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         workingMemory.assertObject( new Precondition( "genericcode",
                                                       "genericvalue" ) );
@@ -393,7 +393,7 @@
     
     public void testDynamicRules() throws Exception {
         final RuleBase ruleBase = getRuleBase();
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final Cheese a = new Cheese( "stilton",
                                      10 );
         final Cheese b = new Cheese( "stilton",
@@ -414,7 +414,7 @@
 
     public void testDynamicRules2() throws Exception {
         final RuleBase ruleBase = getRuleBase();
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         // Assert some simple facts
         final FactA a = new FactA( "hello",

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ExecutionFlowControlTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ExecutionFlowControlTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ExecutionFlowControlTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -56,7 +56,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -87,7 +87,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -112,7 +112,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -157,7 +157,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         wm.setGlobal( "list",
@@ -217,7 +217,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -263,7 +263,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -316,7 +316,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -346,7 +346,7 @@
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_Assert_Retract_Noloop.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
 
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
         wm.assertObject( new Cheese( "stilton",
                                      15 ) );
 
@@ -360,7 +360,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -391,7 +391,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -423,7 +423,7 @@
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_ModifyNoloop.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
 
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
         wm.assertObject( new Cheese( "stilton",
                                      15 ) );
 
@@ -435,7 +435,7 @@
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_ModifyActivationCreationNoLoop.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
 
-        final InternalWorkingMemoryActions wm = (InternalWorkingMemoryActions) ruleBase.newWorkingMemory();
+        final InternalWorkingMemoryActions wm = (InternalWorkingMemoryActions) ruleBase.newStatefulSession();
         final List created = new ArrayList();
         final List cancelled = new ArrayList();
         final AgendaEventListener l = new DefaultAgendaEventListener() {
@@ -497,7 +497,7 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
                                  list );
@@ -525,7 +525,7 @@
         ruleBase.addPackage( pkg );
         ruleBase.addProcess( processBuilder.getProcesses()[0] );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
                                  list );
@@ -577,7 +577,7 @@
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_EffectiveDate.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/FirstOrderLogicTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -45,7 +45,7 @@
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateModify.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
 
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
         final List results = new ArrayList();
 
         wm.setGlobal( "results",
@@ -114,7 +114,7 @@
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_Collect.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
 
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
         final List results = new ArrayList();
 
         wm.setGlobal( "results",
@@ -152,7 +152,7 @@
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_Collect.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
 
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
         final List results = new ArrayList();
 
         wm.setGlobal( "results",
@@ -223,7 +223,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "results",
@@ -249,7 +249,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -290,7 +290,7 @@
                       builder.getErrors().length );
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -327,7 +327,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -365,7 +365,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -409,7 +409,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "results",
@@ -442,7 +442,7 @@
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_Accumulate.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
 
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
         final List results = new ArrayList();
 
         wm.setGlobal( "results",

Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IteratorToList.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IteratorToList.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IteratorToList.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,15 @@
+package org.drools.integrationtests;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class IteratorToList {
+    public static List convert(Iterator it) {
+        List list = new ArrayList();
+        while ( it.hasNext() ) {
+            list.add( it.next() );
+        }
+        return list;
+    }
+}

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -115,7 +115,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -153,7 +153,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         wm.setGlobal( "list",
@@ -178,7 +178,7 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List events = new ArrayList();
         final WorkingMemoryEventListener listener = new DefaultWorkingMemoryEventListener() {
@@ -224,7 +224,7 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -260,7 +260,7 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -300,7 +300,7 @@
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_ExplicitAnd.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
                                  list );
@@ -324,7 +324,7 @@
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "HelloWorld.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -351,7 +351,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -374,7 +374,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -398,7 +398,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -432,7 +432,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -469,7 +469,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -503,7 +503,7 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( builder.getPackage() );
 
-        final WorkingMemory memory = ruleBase.newWorkingMemory();
+        final WorkingMemory memory = ruleBase.newStatefulSession();
         memory.assertObject( cell1 );
         memory.assertObject( cell );
         memory.fireAllRules();
@@ -518,7 +518,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
                                  list );
@@ -559,7 +559,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final Cheese stilton = new Cheese( "stinky",
                                            5 );
@@ -576,7 +576,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         workingMemory.setGlobal( "five",
                                  new Integer( 5 ) );
@@ -603,7 +603,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         workingMemory.setGlobal( "five",
                                  new Integer( 5 ) );
@@ -628,7 +628,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -649,7 +649,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         workingMemory.setGlobal( "two",
                                  new Integer( 2 ) );
@@ -682,7 +682,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         workingMemory.setGlobal( "two",
                                  new Integer( 2 ) );
@@ -715,7 +715,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final PersonInterface p1 = new Person( "michael",
                                                "food",
@@ -737,7 +737,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final List foo = new ArrayList();
         workingMemory.setGlobal( "messages",
                                  foo );
@@ -764,7 +764,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final Cheese cheese = new Cheese( "stilton",
                                           15 );
         workingMemory.assertObject( cheese );
@@ -794,7 +794,7 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final List list1 = new ArrayList();
         workingMemory.setGlobal( "list1",
                                  list1 );
@@ -849,7 +849,7 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final List list = new ArrayList();
         final Object globalObject = new Object();
         workingMemory.setGlobal( "list",
@@ -989,7 +989,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -1013,7 +1013,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -1043,7 +1043,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final Cheese mussarela = new Cheese( "Mussarela",
                                              35 );
@@ -1070,7 +1070,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final Cheese brie = new Cheese( "brie",
                                         12 );
@@ -1092,7 +1092,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final Cheese brie = new Cheese( "brie",
                                         12 );
@@ -1114,7 +1114,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final Cheese brie = new Cheese( "brie",
                                         12 );
@@ -1136,7 +1136,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final Cheese brie = new Cheese( "brie",
                                         12 );
@@ -1158,7 +1158,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final Cheese brie = new Cheese( "brie",
                                         12 );
@@ -1179,7 +1179,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list1 = new ArrayList();
         workingMemory.setGlobal( "list1",
@@ -1256,7 +1256,7 @@
 
         RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( builder.getPackage() );
-        WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -1284,7 +1284,7 @@
 
         ruleBase = getRuleBase();
         ruleBase.addPackage( builder.getPackage() );
-        workingMemory = ruleBase.newWorkingMemory();
+        workingMemory = ruleBase.newStatefulSession();
 
         list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -1313,7 +1313,7 @@
 
         ruleBase = getRuleBase();
         ruleBase.addPackage( builder.getPackage() );
-        workingMemory = ruleBase.newWorkingMemory();
+        workingMemory = ruleBase.newStatefulSession();
 
         list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -1341,7 +1341,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -1371,7 +1371,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -1424,7 +1424,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg1 );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         // Adding person with null name and likes attributes
         final PersonInterface bob = new Person( null,
@@ -1477,7 +1477,7 @@
         assertEquals( "match Integer",
                       rules[3].getName() );
 
-        WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         workingMemory.setGlobal( "list",
                                  new ArrayList() );
@@ -1487,12 +1487,12 @@
 
         final byte[] wm = serializeOut( workingMemory );
 
-        workingMemory = ruleBase.newWorkingMemory( new ByteArrayInputStream( wm ) );
+        workingMemory = ruleBase.newStatefulSession( new ByteArrayInputStream( wm ) );
 
         assertEquals( 1,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
         assertEquals( bob,
-                      workingMemory.getObjects().get( 0 ) );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).get( 0 ) );
 
         assertEquals( 2,
                       workingMemory.getAgenda().agendaSize() );
@@ -1508,11 +1508,11 @@
                       list.get( 0 ) );
 
         assertEquals( 2,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
         assertEquals( bob,
-                      workingMemory.getObjects().get( 0 ) );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).get( 0 ) );
         assertEquals( new Person( "help" ),
-                      workingMemory.getObjects().get( 1 ) );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).get( 1 ) );
     }
 
 
@@ -1523,7 +1523,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -1542,7 +1542,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -1562,7 +1562,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "results",
@@ -1614,7 +1614,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg1 );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List orderedFacts = new ArrayList();
         final List errors = new ArrayList();
@@ -1650,7 +1650,7 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( builder.getPackage() );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         workingMemory.fireAllRules();
 
         final QueryResults results = workingMemory.getQueryResults( "assertedobjquery" );
@@ -1682,7 +1682,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final Cheese stilton = new Cheese( "stinky",
                                            5 );
@@ -1711,7 +1711,7 @@
     public void testInsurancePricingExample() throws Exception {
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "insurance_pricing_example.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
 
         // now create some test data
         final Driver driver = new Driver();
@@ -1732,7 +1732,7 @@
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_JoinNodeModifyTuple.drl" ) );
         final RuleBase ruleBase = loadRuleBase( reader );
 
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
 
         // 1st time
         org.drools.Target tgt = new org.drools.Target();
@@ -1826,7 +1826,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final Person p1 = new Person( "p1",
                                       "stilton",
@@ -1911,7 +1911,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -1935,7 +1935,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List matchlist = new ArrayList();
         workingMemory.setGlobal( "matchingList",
@@ -1976,7 +1976,7 @@
 
         final RuleBase ruleBase = getRuleBase( config );
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List sensors = new ArrayList();
 
@@ -2024,7 +2024,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "results",
@@ -2078,7 +2078,7 @@
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
 
         wm.assertObject( new Cheese( "a",
                                      10 ) );
@@ -2115,7 +2115,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final List result = new ArrayList();
         workingMemory.setGlobal( "result",
                                  result );
@@ -2145,7 +2145,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final List result = new ArrayList();
         workingMemory.setGlobal( "results",
                                  result );
@@ -2169,7 +2169,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final Map result = new HashMap();
         workingMemory.setGlobal( "results",
                                  result );
@@ -2225,7 +2225,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         workingMemory.assertObject( new Child( "gp" ) );
 
@@ -2239,7 +2239,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List results = new ArrayList();
         workingMemory.setGlobal( "results",
@@ -2275,7 +2275,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "results",
@@ -2332,7 +2332,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List results = new ArrayList();
         workingMemory.setGlobal( "results",
@@ -2361,7 +2361,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
 
         final List agendaList = new ArrayList();
         final AgendaEventListener agendaEventListener = new AgendaEventListener() {
@@ -2450,7 +2450,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List results = new ArrayList();
         workingMemory.setGlobal( "results",
@@ -2474,7 +2474,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         workingMemory.setGlobal( "value",
                                  new Integer( 20 ) );

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/TruthMaintenanceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/TruthMaintenanceTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/TruthMaintenanceTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -17,6 +17,7 @@
 import org.drools.Sensor;
 import org.drools.WorkingMemory;
 import org.drools.audit.WorkingMemoryFileLogger;
+import org.drools.base.ClassObjectFilter;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.TruthMaintenanceSystem;
 import org.drools.compiler.PackageBuilder;
@@ -54,7 +55,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
@@ -74,17 +75,17 @@
                       list.size() );
 
         assertEquals( 3,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
 
         workingMemory.retractObject( brieHandle );
 
         assertEquals( 2,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
 
         workingMemory.retractObject( provoloneHandle );
 
         assertEquals( 0,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
     }
 
     public void testLogicalAssertionsBacking() throws Exception {
@@ -94,7 +95,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final Cheese cheese1 = new Cheese( "c",
                                            1 );
@@ -104,7 +105,7 @@
 
         final FactHandle h1 = workingMemory.assertObject( cheese1 );
         workingMemory.fireAllRules();
-        list = workingMemory.getObjects( cheese1.getType().getClass() );
+        list = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( cheese1.getType().getClass() ) ) );
         assertEquals( 1,
                       list.size() );
         // probably dangerous, as contains works with equals, not identity
@@ -114,17 +115,17 @@
 
         final FactHandle h2 = workingMemory.assertObject( cheese2 );
         workingMemory.fireAllRules();
-        list = workingMemory.getObjects( cheese1.getType().getClass() );
+        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( cheese1.getType().getClass() ) ) );
         assertEquals( 1,
                       list.size() );
         assertEquals( cheese1.getType(),
                       list.get( 0 ) );
         
-        assertEquals( 3, workingMemory.getObjects().size() );
+        assertEquals( 3, IteratorToList.convert( workingMemory.iterateObjects() ).size() );
 
         workingMemory.retractObject( h1 );
         workingMemory.fireAllRules();
-        list = workingMemory.getObjects( cheese1.getType().getClass() );
+        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( cheese1.getType().getClass() ) ) );
         assertEquals( "cheese-type " + cheese1.getType() + " was retracted, but should not. Backed by cheese2 => type.",
                       1,
                       list.size() );
@@ -134,7 +135,7 @@
 
         workingMemory.retractObject( h2 );
         workingMemory.fireAllRules();
-        list = workingMemory.getObjects( cheese1.getType().getClass() );
+        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( cheese1.getType().getClass() ) ) );
         assertEquals( "cheese-type " + cheese1.getType() + " was not retracted, but should have. Neither  cheese1 => type nor cheese2 => type is true.",
                       0,
                       list.size() );
@@ -147,7 +148,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         List list;
 
@@ -159,7 +160,7 @@
 
         FactHandle h1 = workingMemory.assertObject( a );
         workingMemory.fireAllRules();
-        list = workingMemory.getObjects( a.getClass() );
+        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( a.getClass() ) ) );
         assertEquals( 2,
                       list.size() );
         assertTrue( list.contains( a ) );
@@ -167,7 +168,7 @@
 
         workingMemory.retractObject( h1 );
         workingMemory.fireAllRules();
-        list = workingMemory.getObjects( a.getClass() );
+        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( a.getClass() ) ) );
         assertEquals( "b was retracted, but it should not have. Is backed by b => b being true.",
                       1,
                       list.size() );
@@ -178,7 +179,7 @@
         h1 = workingMemory.getFactHandle( b );
         workingMemory.retractObject( h1 );
         workingMemory.fireAllRules();
-        list = workingMemory.getObjects( a.getClass() );
+        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( a.getClass() ) ) );
         assertEquals( 0,
                       list.size() );
     }
@@ -190,7 +191,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         List list;
 
@@ -202,7 +203,7 @@
                                  l );
 
         workingMemory.fireAllRules();
-        list = workingMemory.getObjects( a.getClass() );
+        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( a.getClass() ) ) );
         assertEquals( "a still asserted.",
                       0,
                       list.size() );
@@ -218,7 +219,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         List list;
 
@@ -230,7 +231,7 @@
                                  l );
 
         workingMemory.fireAllRules();
-        list = workingMemory.getObjects( a.getClass() );
+        list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( a.getClass() ) ) );
         assertEquals( "a still in WM",
                       0,
                       list.size() );
@@ -246,7 +247,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         
         final WorkingMemoryEventListener l2 = new DefaultWorkingMemoryEventListener() {
             public void objectAsserted(ObjectAssertedEvent event) {
@@ -269,12 +270,13 @@
         p.setAge( 2 );
         final FactHandle h = workingMemory.assertObject( p );
         assertEquals( 1,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
 
         workingMemory.fireAllRules();
         assertEquals( 2,
-                      workingMemory.getObjects().size() );
-        l = workingMemory.getObjects( CheeseEqual.class );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
+        
+        l = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( CheeseEqual.class ) ) );
         assertEquals( 1,
                       l.size() );
         assertEquals( 2,
@@ -282,7 +284,7 @@
 
         workingMemory.retractObject( h );
         assertEquals( 0,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
 
         TruthMaintenanceSystem tms = ((InternalWorkingMemory) workingMemory).getTruthMaintenanceSystem();
 
@@ -302,7 +304,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final WorkingMemoryFileLogger logger = new WorkingMemoryFileLogger( workingMemory );
         logger.setFileName( "logical" );
@@ -319,7 +321,7 @@
         // everything should be normal
         workingMemory.fireAllRules();
 
-        final List list = workingMemory.getObjects();
+        final List list = IteratorToList.convert( workingMemory.iterateObjects() );
 
         assertEquals( "Only sensor is there",
                       1,
@@ -352,7 +354,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         List list;
 
@@ -363,7 +365,7 @@
                                  cheese );
 
         workingMemory.fireAllRules();
-        list = workingMemory.getObjects();
+        list = IteratorToList.convert( workingMemory.iterateObjects() );
         assertEquals( "i was not asserted by not a => i.",
                       1,
                       list.size() );
@@ -375,7 +377,7 @@
         // no need to fire rules, assertion alone removes justification for i,
         // so it should be retracted.
         // workingMemory.fireAllRules();
-        list = workingMemory.getObjects();
+        list = IteratorToList.convert( workingMemory.iterateObjects() );
         assertEquals( "a was not asserted or i not retracted.",
                       1,
                       list.size() );
@@ -393,7 +395,7 @@
 
         workingMemory.retractObject( h );
         workingMemory.fireAllRules();
-        list = workingMemory.getObjects();
+        list = IteratorToList.convert( workingMemory.iterateObjects() );
         assertEquals( "i was not asserted by not a => i.",
                       1,
                       list.size() );
@@ -409,7 +411,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         // workingMemory.addEventListener(new DebugAgendaEventListener());
         // workingMemory.addEventListener(new
@@ -450,7 +452,7 @@
             // leapsRuleBase = (org.drools.leaps.LeapsRuleBase) ruleBase;
         }
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         // workingMemory.addEventListener(new
         // org.drools.event.DebugAgendaEventListener());
@@ -471,7 +473,7 @@
         workingMemory.fireAllRules();
 
         // Check logical assertions where made for c2 and c3
-        list = workingMemory.getObjects( Person.class );
+        list = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Person.class) ) );
         assertEquals( 2,
                       list.size() );
         assertFalse( list.contains( new Person( c1.getType() ) ) );
@@ -488,7 +490,7 @@
         workingMemory.fireAllRules();
 
         // check all now have just one logical assertion each
-        list = workingMemory.getObjects( Person.class );
+        list = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Person.class) ) );
         assertEquals( 3,
                       list.size() );
         assertTrue( list.contains( new Person( c1.getType() ) ) );
@@ -524,7 +526,7 @@
         assertEquals( "rule2",
                       ruleBase.getPackages()[1].getRules()[0].getName() );
 
-        list = workingMemory.getObjects( Person.class );
+        list = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Person.class) ) );
         assertEquals( "removal of the rule should result in retraction of c3's logical assertion",
                       2,
                       list.size() );
@@ -538,7 +540,7 @@
         c2.setPrice( 3 );
         workingMemory.modifyObject( h,
                                     c2 );
-        list = workingMemory.getObjects( Person.class );
+        list = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Person.class) ) );
         assertEquals( "c2 now has a higher price, its logical assertion should  be cancelled",
                       1,
                       list.size() );
@@ -558,7 +560,7 @@
                       ruleBase.getPackages()[0].getRules().length );
         assertEquals( 0,
                       ruleBase.getPackages()[1].getRules().length );
-        list = workingMemory.getObjects( Person.class );
+        list = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Person.class) ) );
         assertEquals( 0,
                       list.size() );
     }
@@ -570,19 +572,19 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         List l;
         final Person p = new Person( "person" );
         p.setAge( 2 );
         final FactHandle h = workingMemory.assertObject( p );
         assertEquals( 1,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
 
         workingMemory.fireAllRules();
         assertEquals( 2,
-                      workingMemory.getObjects().size() );
-        l = workingMemory.getObjects( CheeseEqual.class );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
+        l = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( CheeseEqual.class) ) );
         assertEquals( 1,
                       l.size() );
         assertEquals( 3,
@@ -590,7 +592,7 @@
 
         workingMemory.retractObject( h );
         assertEquals( 0,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
 
         TruthMaintenanceSystem tms = ((InternalWorkingMemory) workingMemory).getTruthMaintenanceSystem();
 
@@ -610,7 +612,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final Person p1 = new Person( "p1",
                                       "stilton",
@@ -630,7 +632,7 @@
         workingMemory.fireAllRules();
 
         // all 3 in europe, so, 2 cheese
-        List cheeseList = workingMemory.getObjects( Cheese.class );
+        List cheeseList = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( Cheese.class) ) );
         assertEquals( 2,
                       cheeseList.size() );
 
@@ -639,7 +641,7 @@
         workingMemory.modifyObject( c3FactHandle,
                                     p3 );
         workingMemory.fireAllRules();
-        cheeseList = workingMemory.getObjects( Cheese.class );
+        cheeseList = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( Cheese.class) ) );
         assertEquals( 1,
                       cheeseList.size() );
 
@@ -648,7 +650,7 @@
         workingMemory.modifyObject( c2FactHandle,
                                     p2 );
         workingMemory.fireAllRules();
-        cheeseList = workingMemory.getObjects( Cheese.class );
+        cheeseList = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( Cheese.class) ) );
         assertEquals( 1,
                       cheeseList.size() );
 
@@ -657,7 +659,7 @@
         workingMemory.modifyObject( c1FactHandle,
                                     p1 );
         workingMemory.fireAllRules();
-        cheeseList = workingMemory.getObjects( Cheese.class );
+        cheeseList = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( Cheese.class) ) );
         assertEquals( 2,
                       cheeseList.size() );
 
@@ -666,7 +668,7 @@
         workingMemory.modifyObject( c2FactHandle,
                                     p2 );
         workingMemory.fireAllRules();
-        cheeseList = workingMemory.getObjects( Cheese.class );
+        cheeseList = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( Cheese.class) ) );
         assertEquals( 1,
                       cheeseList.size() );
 
@@ -675,7 +677,7 @@
         workingMemory.modifyObject( c1FactHandle,
                                     p1 );
         workingMemory.fireAllRules();
-        cheeseList = workingMemory.getObjects( Cheese.class );
+        cheeseList = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( Cheese.class) ) );
         assertEquals( 1,
                       cheeseList.size() );
 
@@ -684,7 +686,7 @@
         workingMemory.modifyObject( c3FactHandle,
                                     p3 );
         workingMemory.fireAllRules();
-        cheeseList = workingMemory.getObjects( Cheese.class );
+        cheeseList = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( Cheese.class) ) );
         assertEquals( 2,
                       cheeseList.size() );
     }
@@ -696,7 +698,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "events",
@@ -713,7 +715,7 @@
         assertEquals( 2,
                       list.size() );
         assertEquals( 2,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
 
         // modifying sensor
         sensor.setTemperature( 125 );
@@ -725,7 +727,7 @@
         assertEquals( 3,
                       list.size() );
         assertEquals( 2,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
 
         // modifying sensor
         sensor.setTemperature( 80 );
@@ -737,7 +739,7 @@
         assertEquals( 3,
                       list.size() );
         assertEquals( 1,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
     }
     
     public void testLogicalAssertionsAccumulatorPattern() throws Exception {
@@ -748,7 +750,7 @@
 
         final RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         workingMemory.setGlobal( "ga", "a");
         workingMemory.setGlobal( "gb", "b");
@@ -759,23 +761,23 @@
         List l;
         final FactHandle h = workingMemory.assertObject( new Integer( 6 ) );
         assertEquals( 1,
-                      workingMemory.getObjects().size() );
+                      IteratorToList.convert( workingMemory.iterateObjects() ).size() );
 
         workingMemory.fireAllRules();
-        l = workingMemory.getObjects( CheeseEqual.class );
+        l = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( CheeseEqual.class) ) );
         assertEquals( "There should be 2 CheeseEqual in Working Memory, 1 justified, 1 stated", 2, l.size() );
-        assertEquals( 6, workingMemory.getObjects().size() );
+        assertEquals( 6, IteratorToList.convert( workingMemory.iterateObjects() ).size() );
 
         workingMemory.retractObject( h );
-        l = workingMemory.getObjects( CheeseEqual.class );
+        l = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( CheeseEqual.class) ) );
         assertEquals( "There should be only 1 CheeseEqual in Working Memory, 1 stated (the justified should have been retracted). Check TruthMaintenanceSystem justifiedMap", 1, l.size() );
-        l = workingMemory.getObjects( Short.class );
+        l = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( Short.class) ) );
         assertEquals( 1, l.size() );
-        assertEquals( 2, workingMemory.getObjects().size() );
+        assertEquals( 2, IteratorToList.convert( workingMemory.iterateObjects() ).size() );
         
         //clean-up
         workingMemory.fireAllRules();
-        assertEquals( 0, workingMemory.getObjects().size() );
+        assertEquals( 0, IteratorToList.convert( workingMemory.iterateObjects() ).size() );
     }    
     
 

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/waltz/Waltz.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/waltz/Waltz.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/waltz/Waltz.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -48,7 +48,7 @@
 
             //load up the rulebase
             final RuleBase ruleBase = readRule();
-            final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+            final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
             workingMemory.setGlobal( "sysout",
                                      System.out );

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilderTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilderTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -60,7 +60,7 @@
                        ruleDescr );
 
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
 
         final Cheese cheddar = new Cheese( "cheddar",
                                      10 );

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilderTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilderTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -59,7 +59,7 @@
                                                             evalDescr );
 
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-        final WorkingMemory wm = ruleBase.newWorkingMemory();
+        final WorkingMemory wm = ruleBase.newStatefulSession();
 
         final Cheese cheddar = new Cheese( "cheddar",
                                      10 );

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilderTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilderTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -96,7 +96,7 @@
                        predicateDescr );
 
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-        final InternalWorkingMemory wm = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        final InternalWorkingMemory wm = (InternalWorkingMemory) ruleBase.newStatefulSession();
 
         final Cheese stilton = new Cheese( "stilton",
                                      10 );

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilderTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilderTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -102,7 +102,7 @@
                        returnValueDescr );
 
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-        final InternalWorkingMemory wm = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        final InternalWorkingMemory wm = (InternalWorkingMemory) ruleBase.newStatefulSession();
 
         final Cheese stilton = new Cheese( "stilton",
                                      10 );

Modified: labs/jbossrules/trunk/drools-core/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-core/.classpath	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/.classpath	2007-04-23 22:54:04 UTC (rev 11274)
@@ -5,8 +5,8 @@
   <classpathentry kind="src" path="src/test/resources" output="target/test-classes"/>
   <classpathentry kind="output" path="target/classes"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+  <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/junit/junit/3.8.1/junit-3.8.1.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/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta15/mvel14-1.2beta15.jar"/>
 </classpath>
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ConcurrentStatelessSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ConcurrentStatelessSession.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ConcurrentStatelessSession.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,14 @@
+package org.drools;
+
+import java.util.List;
+
+import org.drools.event.AgendaEventListener;
+import org.drools.spi.AgendaFilter;
+import org.drools.spi.GlobalResolver;
+
+public interface ConcurrentStatelessSession {    
+    
+    void asyncExecute(Object object);
+    void asyncExecute(Object[] list);
+    void asyncExecute(List list);
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ObjectFilter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ObjectFilter.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ObjectFilter.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,5 @@
+package org.drools;
+
+public interface ObjectFilter {
+    boolean accept(Object object);
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ReteConcurrentStatelessSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ReteConcurrentStatelessSession.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/ReteConcurrentStatelessSession.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,63 @@
+package org.drools;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.event.AgendaEventListener;
+import org.drools.spi.AgendaFilter;
+import org.drools.spi.GlobalResolver;
+import org.drools.util.concurrent.locks.BlockingQueue;
+import org.drools.util.concurrent.locks.LinkedBlockingQueue;
+import org.drools.util.concurrent.locks.Queue;
+
+public class ReteConcurrentStatelessSession implements ConcurrentStatelessSession {    
+    private BlockingQueue queue;
+    
+    public void asyncExecute(Object object) {
+        this.queue.offer( object );
+    }
+    
+    public void asyncExecute(Object[] list) {
+        this.queue.offer( list );
+    }
+    
+    public void asyncExecute(List list) {
+        this.queue.offer( list );
+    }
+    
+ 
+    public class ProducerConsumer implements Runnable {
+        private WorkingMemory workingMemory;
+        private BlockingQueue queue;
+        
+        
+        public ProducerConsumer(WorkingMemory workingMemory, BlockingQueue queue) {
+            this.workingMemory = workingMemory;
+            this.queue = queue;
+        }
+
+        public void run() {
+            while (true) {
+                try {
+                    Object object = this.queue.take();
+                    if ( object instanceof Object[] ) {
+                        this.workingMemory.assertObject( object );
+                    } else if ( object instanceof List ) {
+                        List list = ( List ) object;
+                        for ( Iterator it = list.iterator(); it.hasNext(); ) {
+                            this.workingMemory.assertObject( it.next() );
+                        }
+                    } else {
+                        Object[] objects = ( Object[] ) object;
+                        for ( int i = 0, length = objects.length; i < length; i++ ) {
+                            this.workingMemory.assertObject( objects[i] );
+                        }
+                    }
+                    Thread.sleep( 100 );
+                } catch(InterruptedException e) {
+                    return;
+                }
+            }
+        }        
+    }
+}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBase.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBase.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -45,6 +45,8 @@
 
     public static final int RETEOO = 1;
     public static final int LEAPS  = 2;
+    
+    StatelessSession newStatelessSession();
 
     /**
      * Create a new <code>WorkingMemory</code> session for this
@@ -61,7 +63,7 @@
      * 
      * @return A newly initialized <code>WorkingMemory</code>.
      */
-    WorkingMemory newWorkingMemory();
+    StatefulSession newStatefulSession();
 
     /**
      * Create a new <code>WorkingMemory</code> session for this
@@ -78,7 +80,7 @@
      * 
      * @return A newly initialized <code>WorkingMemory</code>.
      */
-    WorkingMemory newWorkingMemory(boolean keepReference);
+    StatefulSession newStatefulSession(boolean keepReference);
 
     /**
      * RuleBases handle the returning of a Serialized WorkingMemory
@@ -96,7 +98,7 @@
      * 
      * @return A serialised initialized <code>WorkingMemory</code>.
      */
-    WorkingMemory newWorkingMemory(InputStream stream) throws IOException,
+    StatefulSession newStatefulSession(InputStream stream) throws IOException,
                                                       ClassNotFoundException;
 
     /**
@@ -115,7 +117,7 @@
      * 
      * @return A serialised initialized <code>WorkingMemory</code>.
      */
-    WorkingMemory newWorkingMemory(InputStream stream,
+    StatefulSession newStatefulSession(InputStream stream,
                                    boolean keepReference) throws IOException,
                                                          ClassNotFoundException;
 
@@ -134,5 +136,5 @@
     void removeRule(String packageName,
                     String ruleName);
 
-    public Set getWorkingMemories();
+    public StatefulSession[] getStatefulSessions();
 }

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatefulSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatefulSession.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatefulSession.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,26 @@
+package org.drools;
+
+import java.util.List;
+
+import org.drools.concurrent.Future;
+import org.drools.spi.AgendaFilter;
+
+public interface StatefulSession extends WorkingMemory {
+    
+    /**
+     * Forces the workingMemory to be derefenced from
+     * 
+     */
+    void dispose();    
+    
+    Future asyncAssertObject(Object object);    
+    Future asyncRetractObject(FactHandle factHandle);   
+    Future asyncModifyObject(FactHandle factHandle, Object object);
+
+    Future asyncAssertObjects(Object[] list);
+    Future asyncAssertObjects(List list);
+    
+    Future asyncFireAllRules();
+    Future asyncFireAllRules(AgendaFilter agendaFilter); 
+
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSession.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSession.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,62 @@
+package org.drools;
+
+import java.util.List;
+
+import org.drools.event.AgendaEventListener;
+import org.drools.spi.AgendaFilter;
+import org.drools.spi.GlobalResolver;
+
+public interface StatelessSession {
+    /**
+     * Returns all event listeners.
+     * 
+     * @return listeners The listeners.
+     */
+    public List getWorkingMemoryEventListeners();
+
+    /**
+     * Add an event listener.
+     * 
+     * @param listener
+     *            The listener to add.
+     */
+    public void addEventListener(AgendaEventListener listener);
+
+    /**
+     * Remove an event listener.
+     * 
+     * @param listener
+     *            The listener to remove.
+     */
+    public void removeEventListener(AgendaEventListener listener);    
+    
+    
+    void setAgendaFilter(AgendaFilter agendaFilter);
+    
+    /**
+     * Delegate used to resolve any global names not found in the global map.
+     * @param globalResolver
+     */
+    void setGlobalResolver(GlobalResolver globalResolver);
+    
+    void setGlobal(String identifer, Object value);        
+    
+    
+    void execute(Object object);
+   
+    void execute(Object[] list);
+    
+    void execute(List list);    
+    
+    void asyncExecute(Object object);
+    
+    void asyncExecute(Object[] list);
+    
+    void asyncExecute(List list);      
+    
+    StatelessSessionResult executeWithResults(Object object);
+   
+    StatelessSessionResult executeWithResults(Object[] list);
+    
+    StatelessSessionResult executeWithResults(List list);
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSessionResult.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSessionResult.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/StatelessSessionResult.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,26 @@
+package org.drools;
+
+import java.util.Iterator;
+import java.util.List;
+
+public interface StatelessSessionResult {        
+    
+    Iterator iterateObjects();    
+    
+    Iterator iterateObjects(ObjectFilter filter);   
+    
+    /**
+     * Retrieve the QueryResults of the specified query.
+     *
+     * @param query
+     *            The name of the query.
+     *
+     * @return The QueryResults of the specified query.
+     *         If no results match the query it is empty.
+     *         
+     * @throws IllegalArgumentException 
+     *         if no query named "query" is found in the rulebase         
+     */
+    public QueryResults getQueryResults(String query);
+       
+}

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SynchronizedWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SynchronizedWorkingMemory.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SynchronizedWorkingMemory.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -1,190 +0,0 @@
-package org.drools;
-
-/*
- * Copyright 2005 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.
- */
-
-import java.util.List;
-import java.util.Map;
-
-import org.drools.event.AgendaEventListener;
-import org.drools.event.WorkingMemoryEventListener;
-import org.drools.ruleflow.common.instance.IProcessInstance;
-import org.drools.spi.AgendaFilter;
-import org.drools.spi.AgendaGroup;
-import org.drools.spi.AsyncExceptionHandler;
-import org.drools.spi.GlobalResolver;
-
-/**
- * Each implemented method of the WorkingMemory interface is synchronised.
- * This class simply delegates each method call to the underlying unsynchronized
- * WorkingMemoryImpl.
- * 
- * <preformat>
- * WorkingMemory workingMemory = new SynchronizedWorkingMemory( ruleBase.newWorkingMemory( ) );
- * </preformat>
- *   
- * @author mproctor
- *
- */
-public class SynchronizedWorkingMemory
-    implements
-    WorkingMemory {
-    /**
-     * 
-     */
-    private static final long serialVersionUID = 8304004224308319285L;
-    final WorkingMemory       workingMemory;
-
-    public SynchronizedWorkingMemory(final WorkingMemory workingMemory) {
-        this.workingMemory = workingMemory;
-    }
-
-    public synchronized void addEventListener(final WorkingMemoryEventListener listener) {
-        this.workingMemory.addEventListener( listener );
-    }
-
-    public synchronized FactHandle assertObject(final Object object,
-                                                final boolean dynamic) throws FactException {
-        return this.workingMemory.assertObject( object,
-                                                dynamic );
-    }
-
-    public synchronized FactHandle assertObject(final Object object) throws FactException {
-        return this.workingMemory.assertObject( object );
-    }
-
-    public synchronized void clearAgenda() {
-        this.workingMemory.clearAgenda();
-    }
-
-    public synchronized void clearAgendaGroup(final String group) {
-        this.workingMemory.clearAgendaGroup( group );
-    }
-
-    public synchronized void fireAllRules() throws FactException {
-        this.workingMemory.fireAllRules();
-    }
-
-    public synchronized void fireAllRules(final AgendaFilter agendaFilter) throws FactException {
-        this.workingMemory.fireAllRules( agendaFilter );
-    }
-
-    public synchronized FactHandle getFactHandle(final Object object) throws NoSuchFactHandleException {
-        return this.workingMemory.getFactHandle( object );
-    }
-
-    public synchronized List getFactHandles() {
-        return this.workingMemory.getFactHandles();
-    }
-
-    public synchronized Object getObject(final FactHandle handle) throws NoSuchFactObjectException {
-        return this.workingMemory.getObject( handle );
-    }
-
-    public synchronized List getObjects() {
-        return this.workingMemory.getObjects();
-    }
-
-    public synchronized List getObjects(final Class objectClass) {
-        return this.workingMemory.getObjects( objectClass );
-    }
-
-    public synchronized RuleBase getRuleBase() {
-        return this.workingMemory.getRuleBase();
-    }
-
-    public synchronized void modifyObject(final FactHandle handle,
-                                          final Object object) throws FactException {
-        this.workingMemory.modifyObject( handle,
-                                         object );
-    }
-
-    public synchronized void removeEventListener(final WorkingMemoryEventListener listener) {
-        this.workingMemory.removeEventListener( listener );
-    }
-
-    public synchronized void retractObject(final FactHandle handle) throws FactException {
-        this.workingMemory.retractObject( handle );
-    }
-
-    public synchronized void setAsyncExceptionHandler(final AsyncExceptionHandler handler) {
-        this.workingMemory.setAsyncExceptionHandler( handler );
-    }
-
-    public void addEventListener(final AgendaEventListener listener) {
-        this.workingMemory.addEventListener( listener );
-
-    }
-
-    public void dispose() {
-        this.workingMemory.dispose();
-
-    }
-
-    public Agenda getAgenda() {
-        return this.workingMemory.getAgenda();
-    }
-
-    public List getAgendaEventListeners() {
-        return this.workingMemory.getAgendaEventListeners();
-    }
-
-    public AgendaGroup getFocus() {
-        return this.workingMemory.getFocus();
-    }
-
-    public Object getGlobal(final String name) {
-        return this.workingMemory.getGlobal( name );
-    }
-
-    public Map getGlobals() {
-        return this.workingMemory.getGlobals();
-    }
-
-    public void setGlobalResolver(final GlobalResolver globalResolver) {
-        this.workingMemory.setGlobalResolver( globalResolver );
-    }
-
-    public QueryResults getQueryResults(final String query) {
-        return this.workingMemory.getQueryResults( query );
-    }
-
-    public List getWorkingMemoryEventListeners() {
-        return this.workingMemory.getWorkingMemoryEventListeners();
-    }
-
-    public void removeEventListener(final AgendaEventListener listener) {
-        this.workingMemory.removeEventListener( listener );
-    }
-
-    public void setFocus(final String focus) {
-        this.workingMemory.setFocus( focus );
-    }
-
-    public void setFocus(final AgendaGroup focus) {
-        this.workingMemory.setFocus( focus );
-    }
-
-    public void setGlobal(final String name,
-                          final Object value) {
-        this.workingMemory.setGlobal( name,
-                                      value );
-    }
-
-    public synchronized IProcessInstance startProcess(final String processId) {
-        return this.workingMemory.startProcess( processId );
-    }
-}
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/WorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/WorkingMemory.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/WorkingMemory.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -17,6 +17,7 @@
  */
 
 import java.io.Serializable;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -141,6 +142,7 @@
      *             If an error occurs.
      */
     void fireAllRules(AgendaFilter agendaFilter) throws FactException;
+      
 
     /**
      * Retrieve the object associated with a <code>FactHandle</code>.
@@ -174,37 +176,22 @@
      */
     FactHandle getFactHandle(Object object) throws NoSuchFactHandleException;
 
-    /**
-     * Retrieve all known objects.
-     * 
-     * @return The list of all known objects.
-     */
-    List getObjects();
+    Iterator iterateObjects();
+    
+    Iterator iterateObjects(ObjectFilter filter);
 
+    Iterator iterateFactHandles();
+    
+    Iterator iterateFactHandles(ObjectFilter filter);    
+    
     public AgendaGroup getFocus();
 
     void setFocus(String focus);
 
     void setFocus(AgendaGroup focus);
+        
 
     /**
-     * Retrieve all known objects of the specified class.
-     * 
-     * @param objectClass
-     *            The class of object to return.
-     * 
-     * @return The list of all known objects of the specified class.
-     */
-    List getObjects(Class objectClass);
-
-    /**
-     * Retrieve all known Fact Handles.
-     * 
-     * @return The list of all known fact handles.
-     */
-    List getFactHandles();
-
-    /**
      * Assert a fact.
      * 
      * @param object
@@ -295,12 +282,6 @@
     public void clearAgendaGroup(String group);
 
     /**
-     * Forces the workingMemory to be derefenced from
-     * 
-     */
-    void dispose();
-
-    /**
      * Starts a new process instance for the process with the given id. 
      */
     IProcessInstance startProcess(String processId);

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassObjectFilter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassObjectFilter.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassObjectFilter.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,16 @@
+package org.drools.base;
+
+import org.drools.ObjectFilter;
+
+public class ClassObjectFilter implements ObjectFilter {
+    private Class clazz;
+    
+    public ClassObjectFilter(Class clazz) {
+        this.clazz = clazz;
+    }
+
+    public boolean accept(Object object) {
+        return object.getClass().isAssignableFrom( this.clazz );
+    }
+    
+}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -112,11 +112,11 @@
     }
 
     public List getObjects() {
-        return this.workingMemory.getObjects();
+        return null; //this.workingMemory.getObjects();
     }
 
     public List getObjects(final Class objectClass) {
-        return this.workingMemory.getObjects( objectClass );
+        return null; //this.workingMemory.getObjects( objectClass );
     }
 
     public void clearAgenda() {

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-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -37,7 +37,7 @@
 import org.drools.RuleBase;
 import org.drools.RuleBaseConfiguration;
 import org.drools.RuleIntegrationException;
-import org.drools.WorkingMemory;
+import org.drools.StatefulSession;
 import org.drools.rule.CompositePackageClassLoader;
 import org.drools.rule.InvalidPatternException;
 import org.drools.rule.Package;
@@ -45,6 +45,7 @@
 import org.drools.rule.Rule;
 import org.drools.ruleflow.common.core.IProcess;
 import org.drools.spi.FactHandleFactory;
+import org.drools.util.ObjectHashSet;
 
 /**
  * Implementation of <code>RuleBase</code>.
@@ -82,11 +83,8 @@
      * WeakHashMap to keep references of WorkingMemories but allow them to be
      * garbage collected
      */
-    protected transient Map                         workingMemories;
+    protected transient ObjectHashSet               statefulSessions;
 
-    /** Special value when adding to the underlying map. */
-    protected static final Object                   PRESENT = new Object();
-
     /**
      * Default constructor - for Externalizable. This should never be used by a user, as it 
      * will result in an invalid state for the instance.
@@ -117,7 +115,7 @@
         this.pkgs = new HashMap();
         this.processes = new HashMap();
         this.globals = new HashMap();
-        this.workingMemories = new WeakHashMap();
+        this.statefulSessions = new ObjectHashSet();
     }
 
     // ------------------------------------------------------------
@@ -179,7 +177,7 @@
 
         this.config = (RuleBaseConfiguration) streamWithLoader.readObject();
 
-        this.workingMemories = new WeakHashMap();
+        this.statefulSessions = new ObjectHashSet();
 
         for ( int i = 0, length = objects.length; i < length; i++ ) {
             objects[i] = streamWithLoader.readObject();
@@ -196,17 +194,17 @@
     /**
      * @see RuleBase
      */
-    public WorkingMemory newWorkingMemory() {
-        return newWorkingMemory( true );
+    public StatefulSession newStatefulSession() {
+        return newStatefulSession( true );
     }
 
     /**
      * @see RuleBase
      */
-    abstract public WorkingMemory newWorkingMemory(boolean keepReference);
+    abstract public StatefulSession newStatefulSession(boolean keepReference);
 
-    public void disposeWorkingMemory(final WorkingMemory workingMemory) {
-        this.workingMemories.remove( workingMemory );
+    public synchronized void disposeStatefulSession(final StatefulSession statefulSession) {
+        this.statefulSessions.remove( statefulSession );
     }
 
     /**
@@ -248,14 +246,14 @@
      * @throws FactException
      * @throws InvalidPatternException
      */
-    public void addPackage(final Package newPkg) throws PackageIntegrationException {
+    public synchronized void addPackage(final Package newPkg) throws PackageIntegrationException {
         newPkg.checkValidity();
         final Package pkg = (Package) this.pkgs.get( newPkg.getName() );
         // INVARIANT: lastAquiredLock always contains the index of the last aquired lock +1 
         // in the working memory array 
         int lastAquiredLock = 0;
         // get a snapshot of current working memories for locking
-        final AbstractWorkingMemory[] wms = (AbstractWorkingMemory[]) this.workingMemories.keySet().toArray( new AbstractWorkingMemory[this.workingMemories.size()] );
+        final InternalWorkingMemory[] wms = getWorkingMemories();
 
         try {
             // Iterate each workingMemory and lock it
@@ -359,20 +357,20 @@
         }
     }
 
-    protected void addRule(final Rule rule) throws InvalidPatternException {
+    protected synchronized void addRule(final Rule rule) throws InvalidPatternException {
         if ( !rule.isValid() ) {
             throw new IllegalArgumentException( "The rule called " + rule.getName() + " is not valid. Check for compile errors reported." );
         }
     }
 
-    public void removePackage(final String packageName) {
+    public synchronized void removePackage(final String packageName) {
         final Package pkg = (Package) this.pkgs.get( packageName );
 
         // INVARIANT: lastAquiredLock always contains the index of the last aquired lock +1 
         // in the working memory array 
         int lastAquiredLock = 0;
         // get a snapshot of current working memories for locking
-        final AbstractWorkingMemory[] wms = (AbstractWorkingMemory[]) this.workingMemories.keySet().toArray( new AbstractWorkingMemory[this.workingMemories.size()] );
+        final InternalWorkingMemory[] wms = getWorkingMemories();
 
         try {
             // Iterate each workingMemory and lock it
@@ -420,8 +418,8 @@
         }
     }
 
-    public void removeRule(final String packageName,
-                           final String ruleName) {
+    public synchronized void removeRule(final String packageName,
+                                        final String ruleName) {
         final Package pkg = (Package) this.pkgs.get( packageName );
         final Rule rule = pkg.getRule( ruleName );
 
@@ -429,7 +427,7 @@
         // in the working memory array 
         int lastAquiredLock = 0;
         // get a snapshot of current working memories for locking
-        final AbstractWorkingMemory[] wms = (AbstractWorkingMemory[]) this.workingMemories.keySet().toArray( new AbstractWorkingMemory[this.workingMemories.size()] );
+        final InternalWorkingMemory[] wms = getWorkingMemories();
 
         try {
             // Iterate each workingMemory and lock it
@@ -454,12 +452,12 @@
 
     protected abstract void removeRule(Rule rule);
 
-    public void addProcess(final IProcess process) {
+    public synchronized void addProcess(final IProcess process) {
         this.processes.put( process.getId(),
-                       process );
+                            process );
     }
 
-    public void removeProcess(final String id) {
+    public synchronized void removeProcess(final String id) {
         this.processes.remove( id );
     }
 
@@ -467,31 +465,31 @@
         return (IProcess) this.processes.get( id );
     }
 
-    protected void addWorkingMemory(final WorkingMemory workingMemory,
-                                    final boolean keepReference) {
-        if ( keepReference ) {
-            this.workingMemories.put( workingMemory,
-                                      AbstractRuleBase.PRESENT );
-        }
+    protected synchronized void addStatefulSession(final StatefulSession statefulSession) {
+        this.statefulSessions.add( statefulSession );
     }
 
-    public Set getWorkingMemories() {
-        return this.workingMemories.keySet();
+    public StatefulSession[] getStatefulSessions() {
+        return (StatefulSession[]) this.statefulSessions.toArray( new StatefulSession[ this.statefulSessions.size() ] );
     }
+    
+    public InternalWorkingMemory[] getWorkingMemories() {
+        return (InternalWorkingMemory[]) this.statefulSessions.toArray( new InternalWorkingMemory[ this.statefulSessions.size() ] );
+    }
 
     public RuleBaseConfiguration getConfiguration() {
         return this.config;
     }
 
-    public WorkingMemory newWorkingMemory(final InputStream stream) throws IOException,
-                                                                   ClassNotFoundException {
-        return newWorkingMemory( stream,
-                                 true );
+    public StatefulSession newStatefulSession(final InputStream stream) throws IOException,
+                                                                       ClassNotFoundException {
+        return newStatefulSession( stream,
+                                   true );
     }
 
-    public WorkingMemory newWorkingMemory(final InputStream stream,
-                                          final boolean keepReference) throws IOException,
-                                                                      ClassNotFoundException {
+    public StatefulSession newStatefulSession(final InputStream stream,
+                                              final boolean keepReference) throws IOException,
+                                                                          ClassNotFoundException {
 
         final ObjectInputStreamWithLoader streamWithLoader = new ObjectInputStreamWithLoader( stream,
                                                                                               this.packageClassLoader );
@@ -499,6 +497,6 @@
         final AbstractWorkingMemory workingMemory = (AbstractWorkingMemory) streamWithLoader.readObject();
         workingMemory.setRuleBase( this );
 
-        return workingMemory;
+        return (StatefulSession) workingMemory;
     }
 }

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-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -33,6 +33,7 @@
 import org.drools.FactHandle;
 import org.drools.NoSuchFactHandleException;
 import org.drools.NoSuchFactObjectException;
+import org.drools.ObjectFilter;
 import org.drools.Otherwise;
 import org.drools.QueryResults;
 import org.drools.RuleBase;
@@ -58,8 +59,10 @@
 import org.drools.spi.FactHandleFactory;
 import org.drools.spi.GlobalResolver;
 import org.drools.spi.PropagationContext;
+import org.drools.util.JavaIteratorAdapter;
 import org.drools.util.ObjectHashMap;
 import org.drools.util.PrimitiveLongMap;
+import org.drools.util.AbstractHashTable.HashTableIterator;
 import org.drools.util.ObjectHashMap.ObjectEntry;
 import org.drools.util.concurrent.locks.Lock;
 import org.drools.util.concurrent.locks.ReentrantLock;
@@ -246,18 +249,6 @@
     /**
      * @see WorkingMemory
      */
-    public Map getGlobals() {
-        try {
-            this.lock.lock();
-            return this.globals;
-        } finally {
-            this.lock.unlock();
-        }
-    }
-
-    /**
-     * @see WorkingMemory
-     */
     public void setGlobal(final String name,
                           final Object value) {
         // Cannot set null values
@@ -285,7 +276,12 @@
     }
 
     public void setGlobalResolver(final GlobalResolver globalResolver) {
-        this.globalResolver = globalResolver;
+        try {
+            this.lock.lock();        
+            this.globalResolver = globalResolver;
+        } finally {
+            this.lock.unlock();
+        }            
     }
 
     public long getId() {
@@ -342,7 +338,7 @@
     /**
      * @see WorkingMemory
      */
-    public void fireAllRules() throws FactException {
+    public synchronized void fireAllRules() throws FactException {
         fireAllRules( null );
     }
 
@@ -376,7 +372,7 @@
 
             }
         }
-    }
+    }    
 
     /**
      * This does the "otherwise" phase of processing.
@@ -471,60 +467,49 @@
             this.lock.unlock();
         }
     }
-
-    public List getFactHandles() {
-        try {
-            this.lock.lock();
-            final List list = new ArrayList( this.assertMap.size() );
-            final org.drools.util.Iterator it = this.assertMap.iterator();
-            for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
-                list.add( entry.getKey() );
-            }
-            return list;
-        } finally {
-            this.lock.unlock();
-        }
-    }
-
-    /**
-     * A helper method used to avoid lookups when iterating over facthandles and
-     * objects at once. DO NOT MAKE THIS METHOD PUBLIC UNLESS YOU KNOW WHAT YOU
-     * ARE DOING
-     * 
-     * @return
+    
+    /** 
+     * This is an internal method, used to avoid java.util.Iterator adaptors
      */
     public ObjectHashMap getFactHandleMap() {
         return this.assertMap;
     }
 
     /**
-     * @see WorkingMemory
+     * This class is not thread safe, changes to the working memory during iteration may give unexpected results
      */
-    public List getObjects() {
-        final List list = new ArrayList( this.assertMap.size() );
-
-        final org.drools.util.Iterator it = this.assertMap.iterator();
-        for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
-            final InternalFactHandle handle = (InternalFactHandle) entry.getKey();
-            final Object object = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
-            list.add( object );
-        }
-        return list;
+    public Iterator iterateObjects() {
+        HashTableIterator iterator = new HashTableIterator( this.assertMap );
+        iterator.reset();
+        return new JavaIteratorAdapter( iterator, JavaIteratorAdapter.OBJECT );
     }
+    
+    /**
+     * This class is not thread safe, changes to the working memory during iteration may give unexpected results
+     */  
+    public Iterator iterateObjects(ObjectFilter filter) {
+        HashTableIterator iterator = new HashTableIterator( this.assertMap );
+        iterator.reset();
+        return new JavaIteratorAdapter( iterator, JavaIteratorAdapter.OBJECT, filter );
+    }
 
-    public List getObjects(final Class objectClass) {
-        final List list = new ArrayList( this.assertMap.size() );
-
-        final org.drools.util.Iterator it = this.assertMap.iterator();
-        for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
-            final InternalFactHandle handle = (InternalFactHandle) entry.getKey();
-            final Object object = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
-            if ( objectClass.isInstance( object ) ) {
-                list.add( object );
-            }
-        }
-        return list;
+    /**
+     * This class is not thread safe, changes to the working memory during iteration may give unexpected results
+     */
+    public Iterator iterateFactHandles() {
+        HashTableIterator iterator = new HashTableIterator( this.assertMap );
+        iterator.reset();
+        return new JavaIteratorAdapter( iterator, JavaIteratorAdapter.FACT_HANDLE );
     }
+    
+    /**
+     * This class is not thread safe, changes to the working memory during iteration may give unexpected results
+     */  
+    public Iterator iterateFactHandles(ObjectFilter filter) {
+        HashTableIterator iterator = new HashTableIterator( this.assertMap );
+        iterator.reset();
+        return new JavaIteratorAdapter( iterator, JavaIteratorAdapter.FACT_HANDLE, filter );
+    }       
 
     public abstract QueryResults getQueryResults(String query);
 
@@ -1063,10 +1048,6 @@
         return this.propagationIdCounter++;
     }
 
-    public void dispose() {
-        this.ruleBase.disposeWorkingMemory( this );
-    }
-
     public Lock getLock() {
         return this.lock;
     }

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-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -22,7 +22,7 @@
 import org.drools.FactHandle;
 import org.drools.RuleBase;
 import org.drools.RuleBaseConfiguration;
-import org.drools.WorkingMemory;
+import org.drools.StatefulSession;
 import org.drools.reteoo.ReteooWorkingMemory;
 import org.drools.spi.FactHandleFactory;
 import org.drools.spi.PropagationContext;
@@ -42,7 +42,7 @@
 
     public RuleBaseConfiguration getConfiguration();
 
-    void disposeWorkingMemory(WorkingMemory workingMemory);
+    void disposeStatefulSession(StatefulSession statefulSession);
 
     /**
      * Assert a fact object.

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-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -9,6 +9,7 @@
 import org.drools.spi.FactHandleFactory;
 import org.drools.spi.PropagationContext;
 import org.drools.util.ObjectHashMap;
+import org.drools.util.concurrent.locks.Lock;
 
 public interface InternalWorkingMemory
     extends
@@ -41,5 +42,7 @@
                        final boolean removeLogical,
                        final boolean updateEqualsMap,
                        final Rule rule,
-                       final Activation activation) throws FactException;    
+                       final Activation activation) throws FactException;
+
+    public Lock getLock();    
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -113,73 +113,17 @@
                                                                          node,
                                                                          set,
                                                                          handle,
-                                                                         context );    
+                                                                         context );
                 workingMemory.queueWorkingMemoryAction( action );
             }
-//            if ( set != null ) {
-//                set.remove( node );
-//                if ( set.isEmpty() ) {
-//                    // this needs to be scheduled so we don't upset the current
-//                    // working memory operation                    
-//                    WorkingMemoryAction action = new LogicalRetractCallback( this,
-//                                                                             node,
-//                                                                             set,
-//                                                                             handle,
-//                                                                             context );
-//                    workingMemory.queueWorkingMemoryAction( action );
-//
-//                    //                    this.justifiedMap.remove( handle.getId() );                    
-//                    //                    WorkingMemoryAction action = new WorkingMemoryRetractAction(handle,
-//                    //                                                                                false,
-//                    //                                                                                true,
-//                    //                                                                                context.getRuleOrigin(),
-//                    //                                                                                context.getActivationOrigin() );                    
-//                    //                    this.workingMemory.queueWorkingMemoryAction( action );                  
-//                }
-            }
         }
-    
-
-    public class WorkingMemoryRetractAction
-        implements
-        WorkingMemoryAction {
-        private InternalFactHandle factHandle;
-
-        private boolean            removeLogical;
-
-        private boolean            updateEqualsMap;
-
-        private Rule               ruleOrigin;
-
-        private Activation         activationOrigin;
-
-        public WorkingMemoryRetractAction(final InternalFactHandle factHandle,
-                                          final boolean removeLogical,
-                                          final boolean updateEqualsMap,
-                                          final Rule ruleOrigin,
-                                          final Activation activationOrigin) {
-            super();
-            this.factHandle = factHandle;
-            this.removeLogical = removeLogical;
-            this.updateEqualsMap = updateEqualsMap;
-            this.ruleOrigin = ruleOrigin;
-            this.activationOrigin = activationOrigin;
-        }
-
-        public void execute(InternalWorkingMemory workingMemory) {
-            workingMemory.retractObject( this.factHandle,
-                                         this.removeLogical,
-                                         this.updateEqualsMap,
-                                         this.ruleOrigin,
-                                         this.activationOrigin );
-        }
     }
 
     public static class LogicalRetractCallback
         implements
         WorkingMemoryAction {
         private final TruthMaintenanceSystem tms;
-        private final LogicalDependency node;
+        private final LogicalDependency      node;
         private final Set                    set;
         private final InternalFactHandle     handle;
         private final PropagationContext     context;
@@ -198,18 +142,18 @@
 
         public void execute(InternalWorkingMemory workingMemory) {
 
+            if ( set.isEmpty() ) {
                 if ( set.isEmpty() ) {
-                    if ( set.isEmpty() ) {
-                        this.tms.getJustifiedMap().remove( handle.getId() );
-                        // this needs to be scheduled so we don't upset the current
-                        // working memory operation
-                        workingMemory.retractObject( this.handle,
-                                                     false,
-                                                     true,
-                                                     context.getRuleOrigin(),
-                                                     context.getActivationOrigin() );
-                    }
+                    this.tms.getJustifiedMap().remove( handle.getId() );
+                    // this needs to be scheduled so we don't upset the current
+                    // working memory operation
+                    workingMemory.retractObject( this.handle,
+                                                 false,
+                                                 true,
+                                                 context.getRuleOrigin(),
+                                                 context.getActivationOrigin() );
                 }
+            }
         }
     }
 
@@ -251,7 +195,7 @@
         final LogicalDependency node = new LogicalDependency( activation,
                                                               handle );
         activation.getRule().setHasLogicalDependency( true );
-        
+
         activation.addLogicalDependency( node );
         Set set = (Set) this.justifiedMap.get( handle.getId() );
         if ( set == null ) {

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/AssertObject.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/AssertObject.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/AssertObject.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,30 @@
+/**
+ * 
+ */
+package org.drools.concurrent;
+
+import org.drools.WorkingMemory;
+
+public class AssertObject
+    implements
+    Command,
+    Future {
+    private Object          object;
+    private volatile Object result;
+
+    public AssertObject(final Object object) {
+        this.object = object;
+    }
+
+    public void execute(final WorkingMemory workingMemory) {
+        this.result = workingMemory.assertObject( this.object );
+    }
+
+    public Object getObject() {
+        return this.result;
+    }
+
+    public boolean isDone() {
+        return this.result != null;
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/AssertObjects.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/AssertObjects.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/AssertObjects.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,48 @@
+/**
+ * 
+ */
+package org.drools.concurrent;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.WorkingMemory;
+
+public class AssertObjects
+    implements
+    Command,
+    Future {
+    private Object        object;
+    private volatile List results;
+
+    public AssertObjects(final Object object) {
+        this.object = object;
+    }
+
+    public void execute(final WorkingMemory workingMemory) {
+        if ( this.object instanceof Object[] ) {
+            workingMemory.assertObject( this.object );
+        } else if ( this.object instanceof List ) {
+            final List list = (List) this.object;
+            this.results = new ArrayList( list.size() );
+            for ( final Iterator it = list.iterator(); it.hasNext(); ) {
+                this.results.add( workingMemory.assertObject( it.next() ) );
+            }
+        } else {
+            final Object[] objects = (Object[]) this.object;
+            this.results = new ArrayList( objects.length );
+            for ( int i = 0, length = objects.length; i < length; i++ ) {
+                this.results.add( workingMemory.assertObject( objects[i] ) );
+            }
+        }
+    }
+
+    public Object getObject() {
+        return this.results;
+    }
+
+    public boolean isDone() {
+        return this.results != null;
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/Command.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/Command.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/Command.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,12 @@
+/**
+ * 
+ */
+package org.drools.concurrent;
+
+import java.io.Serializable;
+
+import org.drools.WorkingMemory;
+
+public interface Command extends Serializable {
+    void execute(WorkingMemory workingMemory);
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/CommandExecutor.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/CommandExecutor.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/CommandExecutor.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,45 @@
+/**
+ * 
+ */
+package org.drools.concurrent;
+
+import java.io.Serializable;
+
+import org.drools.WorkingMemory;
+import org.drools.util.concurrent.locks.BlockingQueue;
+import org.drools.util.concurrent.locks.LinkedBlockingQueue;
+
+public class CommandExecutor implements Runnable, Serializable {
+    private WorkingMemory workingMemory;
+    private BlockingQueue queue;
+    
+    private volatile boolean run;
+    
+    
+    public CommandExecutor(WorkingMemory workingMemory) {
+        this.workingMemory = workingMemory;            
+        this.queue = new LinkedBlockingQueue();
+    }        
+    
+    public void shutdown() {
+        this.run = false;
+    }        
+    
+    public Future submit(Command command) {
+        this.queue.offer( command );
+        // we know our commands also implement Future
+        return (Future) command;
+    }
+
+    public void run() {
+        while (this.run) {
+            try {
+                Command executor = ( Command ) this.queue.take();
+                executor.execute( this.workingMemory );
+                Thread.sleep( 100 );
+            } catch(InterruptedException e) {
+                return;
+            }
+        }
+    }        
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/DefaultExecutorService.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/DefaultExecutorService.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/DefaultExecutorService.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,37 @@
+/**
+ * 
+ */
+package org.drools.concurrent;
+
+import org.drools.WorkingMemory;
+
+public class DefaultExecutorService implements ExecutorService {   
+    private Thread thread;
+    private CommandExecutor executor;
+    private boolean running;
+    
+    public DefaultExecutorService() {
+        
+    }
+    
+    public void setCommandExecutor(CommandExecutor executor) {
+        this.executor = executor;
+    }
+    
+    public void startUp() {
+        this.thread = new Thread( executor );
+        this.running = true;
+    }
+    
+    public void shutDown() {
+        this.executor.shutdown();
+        this.running = false;
+    }             
+    
+    public Future submit(Command command) {
+        if (!this.running) {
+            startUp();
+        }
+        return this.executor.submit( command );
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/ExecutorService.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/ExecutorService.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/ExecutorService.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,15 @@
+/**
+ * 
+ */
+package org.drools.concurrent;
+
+import java.io.Serializable;
+
+
+
+public interface ExecutorService extends Serializable {
+    public void setCommandExecutor(CommandExecutor executor);
+    Future submit(Command command);
+    void shutDown();
+    void startUp();
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/FireAllRules.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/FireAllRules.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/FireAllRules.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,32 @@
+/**
+ * 
+ */
+package org.drools.concurrent;
+
+import org.drools.WorkingMemory;
+import org.drools.spi.AgendaFilter;
+
+public class FireAllRules
+    implements
+    Command,
+    Future {
+    private AgendaFilter     agendaFilter;
+    private volatile boolean done;
+
+    public FireAllRules(final AgendaFilter agendaFilter) {
+        this.agendaFilter = agendaFilter;
+    }
+
+    public void execute(final WorkingMemory workingMemory) {
+        workingMemory.fireAllRules( this.agendaFilter );
+        this.done = true;
+    }
+
+    public Object getObject() {
+        return null;
+    }
+
+    public boolean isDone() {
+        return this.done;
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/Future.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/Future.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/Future.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,9 @@
+package org.drools.concurrent;
+
+import java.io.Serializable;
+
+public interface Future extends Serializable  {
+    boolean isDone();
+    
+    Object getObject();
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/InternalFuture.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/InternalFuture.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/InternalFuture.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,6 @@
+package org.drools.concurrent;
+
+public interface InternalFuture extends Future {
+    void setObject(Object object);
+    Command getCommand();
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/ModifyObject.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/ModifyObject.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/ModifyObject.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,36 @@
+/**
+ * 
+ */
+package org.drools.concurrent;
+
+import org.drools.FactHandle;
+import org.drools.WorkingMemory;
+
+public class ModifyObject
+    implements
+    Command,
+    Future {
+    private FactHandle       factHandle;
+    private Object           object;
+    private volatile boolean done;
+
+    public ModifyObject(final FactHandle factHandle,
+                        final Object object) {
+        this.factHandle = factHandle;
+        this.object = object;
+    }
+
+    public void execute(final WorkingMemory workingMemory) {
+        workingMemory.modifyObject( this.factHandle,
+                                    this.object );
+        this.done = true;
+    }
+
+    public Object getObject() {
+        return null;
+    }
+
+    public boolean isDone() {
+        return this.done == true;
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/RetractObject.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/RetractObject.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/concurrent/RetractObject.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,33 @@
+/**
+ * 
+ */
+package org.drools.concurrent;
+
+import org.drools.FactHandle;
+import org.drools.WorkingMemory;
+
+public class RetractObject
+    implements
+    Command,
+    Future {
+    private FactHandle       factHandle;
+    private volatile boolean done;
+
+    public RetractObject(final FactHandle factHandle) {
+        this.factHandle = factHandle;
+    }
+
+    public void execute(final WorkingMemory workingMemory) {
+        workingMemory.retractObject( this.factHandle );
+        this.done = true;
+
+    }
+
+    public Object getObject() {
+        return null;
+    }
+
+    public boolean isDone() {
+        return this.done;
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteStatelessSessionResult.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteStatelessSessionResult.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteStatelessSessionResult.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,29 @@
+package org.drools.reteoo;
+
+import java.util.Iterator;
+
+import org.drools.ObjectFilter;
+import org.drools.QueryResults;
+import org.drools.StatelessSessionResult;
+import org.drools.WorkingMemory;
+
+public class ReteStatelessSessionResult implements StatelessSessionResult {
+    private WorkingMemory workingMemory;
+    
+    public ReteStatelessSessionResult(WorkingMemory workingMemory) {
+        this.workingMemory = workingMemory;
+    }
+
+    public QueryResults getQueryResults(String query) {
+        return this.workingMemory.getQueryResults( query );
+    }
+
+    public Iterator iterateObjects() {
+        return this.workingMemory.iterateObjects();
+    }
+
+    public Iterator iterateObjects(ObjectFilter filter) {
+        return this.workingMemory.iterateObjects(filter);
+    }
+
+}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -23,6 +23,7 @@
 
 import org.drools.RuleIntegrationException;
 import org.drools.common.BaseNode;
+import org.drools.common.InternalWorkingMemory;
 import org.drools.reteoo.builder.ReteooRuleBuilder;
 import org.drools.rule.InvalidPatternException;
 import org.drools.rule.Rule;
@@ -51,7 +52,7 @@
     /** The RuleBase */
     private transient ReteooRuleBase        ruleBase;
 
-    private transient ReteooWorkingMemory[] workingMemories;
+    private transient InternalWorkingMemory[] workingMemories;
 
     private Map                             rules;
 
@@ -122,7 +123,7 @@
 
     public void removeRule(final Rule rule) {
         // reset working memories for potential propagation
-        this.workingMemories = (ReteooWorkingMemory[]) this.ruleBase.getWorkingMemories().toArray( new ReteooWorkingMemory[this.ruleBase.getWorkingMemories().size()] );
+        this.workingMemories = (InternalWorkingMemory[]) this.ruleBase.getWorkingMemories();
 
         final Object object = this.rules.get( rule );
 

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-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -27,15 +27,20 @@
 import org.drools.FactHandle;
 import org.drools.RuleBase;
 import org.drools.RuleBaseConfiguration;
-import org.drools.WorkingMemory;
+import org.drools.StatefulSession;
+import org.drools.StatelessSession;
 import org.drools.common.AbstractRuleBase;
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.InternalFactHandle;
+import org.drools.concurrent.CommandExecutor;
+import org.drools.concurrent.DefaultExecutorService;
+import org.drools.concurrent.ExecutorService;
 import org.drools.rule.CompositePackageClassLoader;
 import org.drools.rule.InvalidPatternException;
 import org.drools.rule.Rule;
 import org.drools.spi.FactHandleFactory;
 import org.drools.spi.PropagationContext;
+import org.drools.util.ObjectHashSet;
 
 /**
  * Implementation of <code>RuleBase</code>.
@@ -127,7 +132,7 @@
         this.packageClassLoader = new CompositePackageClassLoader( Thread.currentThread().getContextClassLoader() );
         this.pkgs = new HashMap();
         this.globals = new HashMap();
-        this.workingMemories = new WeakHashMap();
+        this.statefulSessions = new ObjectHashSet();
 
         this.rete = new Rete();
         this.reteooBuilder = new ReteooBuilder( this );
@@ -220,32 +225,46 @@
     /**
      * @see RuleBase
      */
-    public WorkingMemory newWorkingMemory(final boolean keepReference) {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( this.workingMemoryCounter++,
-                                                                           this );
+    public synchronized StatefulSession newStatefulSession(final boolean keepReference) {
+        ExecutorService executor = new DefaultExecutorService();
+        final ReteooStatefulSession session = new ReteooStatefulSession( this.workingMemoryCounter++,
+                                                                         this,
+                                                                         new DefaultExecutorService() );
+        executor.setCommandExecutor( new CommandExecutor( session ) );
 
-        super.addWorkingMemory( workingMemory,
-                                keepReference );
+        if ( keepReference ) {
+            super.addStatefulSession( session );
+        }
 
-        final InitialFactHandle handle = new InitialFactHandle( workingMemory.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject() ) );
+        final InitialFactHandle handle = new InitialFactHandle( session.getFactHandleFactory().newFactHandle( new InitialFactHandleDummyObject() ) );
 
-        workingMemory.queueWorkingMemoryAction( workingMemory.new WorkingMemoryReteAssertAction( handle,
-                                                                                                 false,
-                                                                                                 true,
-                                                                                                 null,
-                                                                                                 null ) );
+        session.queueWorkingMemoryAction( session.new WorkingMemoryReteAssertAction( handle,
+                                                                                     false,
+                                                                                     true,
+                                                                                     null,
+                                                                                     null ) );
 
-        return workingMemory;
+        return session;
     }
+    
+    public StatelessSession newStatelessSession() {
+        ExecutorService executor = new DefaultExecutorService();
+        ReteooWorkingMemory wm = new ReteooWorkingMemory( this.workingMemoryCounter++,
+                                                          this  );
+        
+        executor.setCommandExecutor( new CommandExecutor( wm ) );
+        
+        return new ReteooStatelessSession( wm, executor );
+    }    
 
-    protected void addRule(final Rule rule) throws InvalidPatternException {
+    protected synchronized void addRule(final Rule rule) throws InvalidPatternException {
         super.addRule( rule );
 
         // This adds the rule. ReteBuilder has a reference to the WorkingMemories and will propagate any existing facts.
         this.reteooBuilder.addRule( rule );
     }
 
-    protected void removeRule(final Rule rule) {
+    protected synchronized void removeRule(final Rule rule) {
         this.reteooBuilder.removeRule( rule );
     }
 
@@ -254,5 +273,4 @@
         Serializable {
         private static final long serialVersionUID = 1L;
     }
-
 }

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatefulSession.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,73 @@
+package org.drools.reteoo;
+
+import java.util.List;
+
+import org.drools.FactHandle;
+import org.drools.StatefulSession;
+import org.drools.common.InternalRuleBase;
+import org.drools.concurrent.AssertObject;
+import org.drools.concurrent.AssertObjects;
+import org.drools.concurrent.ExecutorService;
+import org.drools.concurrent.FireAllRules;
+import org.drools.concurrent.Future;
+import org.drools.concurrent.ModifyObject;
+import org.drools.concurrent.RetractObject;
+import org.drools.spi.AgendaFilter;
+
+public class ReteooStatefulSession extends ReteooWorkingMemory
+    implements
+    StatefulSession {
+    private final ExecutorService executor;
+
+    public ReteooStatefulSession(final int id,
+                                 final InternalRuleBase ruleBase,
+                                 final ExecutorService executorService) {
+        super( id,
+               ruleBase );
+        this.executor = executorService;
+    }
+
+    public Future asyncAssertObject(final Object object) {
+        final AssertObject assertObject = new AssertObject( object );
+        this.executor.submit( assertObject );
+        return assertObject;
+    }
+
+    public Future asyncRetractObject(final FactHandle factHandle) {
+        return this.executor.submit( new RetractObject( factHandle ) );
+    }
+
+    public Future asyncModifyObject(final FactHandle factHandle,
+                                    final Object object) {
+        return this.executor.submit( new ModifyObject( factHandle,
+                                                       object ) );
+    }
+
+    public Future asyncAssertObjects(final Object[] list) {
+        final AssertObjects assertObjects = new AssertObjects( list );
+        this.executor.submit( assertObjects );
+        return assertObjects;
+    }
+
+    public Future asyncAssertObjects(final List list) {
+        final AssertObjects assertObjects = new AssertObjects( list );
+        this.executor.submit( assertObjects );
+        return assertObjects;
+    }
+
+    public Future asyncFireAllRules(final AgendaFilter agendaFilter) {
+        final FireAllRules fireAllRules = new FireAllRules( agendaFilter );
+        this.executor.submit( fireAllRules );
+        return fireAllRules;
+    }
+
+    public Future asyncFireAllRules() {
+        final FireAllRules fireAllRules = new FireAllRules( null );
+        this.executor.submit( fireAllRules );
+        return fireAllRules;
+    }
+    
+    public void dispose() {
+        this.ruleBase.disposeStatefulSession( this );
+    }    
+}

Added: 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	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooStatelessSession.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,114 @@
+package org.drools.reteoo;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.ObjectFilter;
+import org.drools.StatelessSession;
+import org.drools.StatelessSessionResult;
+import org.drools.WorkingMemory;
+import org.drools.common.InternalRuleBase;
+import org.drools.concurrent.AssertObject;
+import org.drools.concurrent.AssertObjects;
+import org.drools.concurrent.ExecutorService;
+import org.drools.concurrent.FireAllRules;
+import org.drools.concurrent.Future;
+import org.drools.event.AgendaEventListener;
+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 ReteooStatelessSession(final WorkingMemory workingMemory,
+                                final ExecutorService executorService) {
+        this.workingMemory = workingMemory;
+        this.executor = executorService;
+    }        
+
+    public void addEventListener(AgendaEventListener listener) {
+        this.workingMemory.addEventListener( listener );
+    }
+
+    public List getWorkingMemoryEventListeners() {
+        return this.workingMemory.getWorkingMemoryEventListeners();
+    }
+
+    public void removeEventListener(AgendaEventListener listener) {
+        this.removeEventListener( listener );   
+    }
+
+    public void setAgendaFilter(AgendaFilter agendaFilter) {
+        this.agendaFilter = agendaFilter;
+    }
+    
+    public void setGlobal(String identifier,
+                          Object value) {
+        this.workingMemory.setGlobal( identifier, value );
+    }
+
+    public void setGlobalResolver(GlobalResolver globalResolver) {
+       this.workingMemory.setGlobalResolver( globalResolver );        
+    }
+
+    public void execute(Object object) {
+        this.workingMemory.assertObject( object );
+        this.workingMemory.fireAllRules( this.agendaFilter );
+    }
+
+    public void execute(Object[] list) {
+        for ( int i = 0, length = list.length; i < length; i++ ) {
+            this.workingMemory.assertObject( list[i] );
+        }
+        this.workingMemory.fireAllRules( this.agendaFilter );
+    }
+
+    public void execute(List list) {
+        for( Iterator it = list.iterator(); it.hasNext(); ) {
+            this.workingMemory.assertObject( it.next() );
+        }
+        this.workingMemory.fireAllRules( this.agendaFilter );
+    }
+    
+    public void asyncExecute(final Object object) {
+        final AssertObject assertObjects = new AssertObject( object );
+        this.executor.submit( assertObjects );
+        this.executor.submit( new FireAllRules( this.agendaFilter ) );
+    }       
+    
+    public void asyncExecute(final Object[] list) {
+        final AssertObjects assertObjects = new AssertObjects( list );
+        this.executor.submit( assertObjects );
+        this.executor.submit( new FireAllRules( this.agendaFilter ) );
+    }
+    
+    public void asyncExecute(final List list) {
+        final AssertObjects assertObjects = new AssertObjects( list );
+        this.executor.submit( assertObjects );
+        this.executor.submit( new FireAllRules( this.agendaFilter ) );
+    }         
+    
+    public StatelessSessionResult executeWithResults(Object object) {
+        this.workingMemory.assertObject( object );
+        this.workingMemory.fireAllRules( this.agendaFilter );
+        return new ReteStatelessSessionResult( this.workingMemory );
+    }
+
+    public StatelessSessionResult executeWithResults(Object[] list) {
+        for ( int i = 0, length = list.length; i < length; i++ ) {
+            this.workingMemory.assertObject( list[i] );
+        }
+        this.workingMemory.fireAllRules( this.agendaFilter );
+        return new ReteStatelessSessionResult( this.workingMemory );
+    }
+
+    public StatelessSessionResult executeWithResults(List list) {
+        for( Iterator it = list.iterator(); it.hasNext(); ) {
+            this.workingMemory.assertObject( it.next() );
+        }
+        this.workingMemory.fireAllRules( this.agendaFilter );
+        return new ReteStatelessSessionResult( this.workingMemory );
+    }    
+}

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	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -22,6 +22,7 @@
 import java.util.Map;
 
 import org.drools.common.BetaConstraints;
+import org.drools.common.InternalWorkingMemory;
 import org.drools.reteoo.ObjectSource;
 import org.drools.reteoo.ReteooBuilder;
 import org.drools.reteoo.ReteooRuleBase;
@@ -52,7 +53,7 @@
     private ReteooRuleBase            rulebase;
 
     // working memories attached to the given rulebase
-    private ReteooWorkingMemory[]     workingMemories;
+    private InternalWorkingMemory[]     workingMemories;
 
     // id generator
     private ReteooBuilder.IdGenerator idGenerator;
@@ -66,7 +67,7 @@
     public BuildContext(final ReteooRuleBase rulebase,
                         final ReteooBuilder.IdGenerator idGenerator) {
         this.rulebase = rulebase;
-        this.workingMemories = (ReteooWorkingMemory[]) this.rulebase.getWorkingMemories().toArray( new ReteooWorkingMemory[this.rulebase.getWorkingMemories().size()] );
+        this.workingMemories = (InternalWorkingMemory[]) this.rulebase.getWorkingMemories();
         this.idGenerator = idGenerator;
 
         this.objectType = new LinkedHashMap();
@@ -156,7 +157,7 @@
      * 
      * @return
      */
-    public ReteooWorkingMemory[] getWorkingMemories() {
+    public InternalWorkingMemory[] getWorkingMemories() {
         return this.workingMemories;
     }
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/AbstractHashTable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/AbstractHashTable.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/AbstractHashTable.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -30,7 +30,7 @@
         this( 16,
               0.75f );
     }
-
+    
     public AbstractHashTable(final int capacity,
                              final float loadFactor) {
         this.loadFactor = loadFactor;
@@ -38,6 +38,18 @@
         this.table = new Entry[capacity];
         this.comparator = EqualityEquals.getInstance();
     }
+    
+    public AbstractHashTable(final Entry[] table) {
+        this( 0.75f, table);
+    }      
+    
+    public AbstractHashTable(final float loadFactor,
+                             final Entry[] table) {
+        this.loadFactor = loadFactor;
+        this.threshold = (int) (table.length * loadFactor);
+        this.table = table;
+        this.comparator = EqualityEquals.getInstance();
+    }    
 
     public Iterator iterator() {
         if ( this.iterator == null ) {

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/JavaIteratorAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/JavaIteratorAdapter.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/JavaIteratorAdapter.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,87 @@
+package org.drools.util;
+
+import java.util.NoSuchElementException;
+
+import org.drools.FactHandle;
+import org.drools.ObjectFilter;
+import org.drools.base.ShadowProxy;
+import org.drools.common.InternalFactHandle;
+import org.drools.util.ObjectHashMap.ObjectEntry;
+
+public class JavaIteratorAdapter
+    implements
+    java.util.Iterator {
+    public static int    OBJECT = 0;
+    public static int    FACT_HANDLE = 1;
+
+    private Iterator     iterator;
+    private ObjectEntry  nextEntry;
+    //    private Object  nextObject;
+    //    private InternalFactHandle  nextHandle;
+    private ObjectFilter filter;
+    private int          type;
+
+    public JavaIteratorAdapter(Iterator iterator,
+                               int type) {
+        this( iterator,
+              type,
+              null );
+    }
+
+    public JavaIteratorAdapter(Iterator iterator,
+                               int type,
+                               ObjectFilter filter) {
+        this.iterator = iterator;
+        this.filter = filter;
+        this.type = type;
+        setNext();
+    }
+
+    public boolean hasNext() {
+        return (this.nextEntry != null);
+    }
+
+    public Object next() {
+        ObjectEntry current = this.nextEntry;
+
+        if ( current != null ) {
+            setNext();
+        } else {
+            throw new NoSuchElementException( "No more elements to return" );
+        }
+
+        if ( this.type == OBJECT ) {
+            InternalFactHandle handle = (InternalFactHandle) current.getKey();
+            Object object = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
+            return object;
+        } else {
+            return current.getKey();
+        }
+    }
+
+    private void setNext() {
+        ObjectEntry entry = null;
+
+        while ( entry == null ) {
+            entry = (ObjectEntry) this.iterator.next();
+            if ( entry == null ) {
+                break;
+            }
+            if ( this.filter != null ) {
+                InternalFactHandle handle = (InternalFactHandle) entry.getKey();
+                Object object = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
+                if ( this.filter.accept( object ) == false ) {
+                    entry = null;
+                }
+            }
+        }
+
+        this.nextEntry = entry;
+        //        this.nextHandle = handle;
+        //        this.nextObject = object;
+    }
+
+    public void remove() {
+        throw new UnsupportedOperationException( "remove() is not support" );
+    }
+}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashMap.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashMap.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashMap.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -3,6 +3,8 @@
  */
 package org.drools.util;
 
+import org.drools.util.AbstractHashTable.EqualityEquals;
+
 public class ObjectHashMap extends AbstractHashTable {
 
     private static final long serialVersionUID = 929633553699602561L;
@@ -17,6 +19,15 @@
         super( capacity,
                loadFactor );
     }
+    
+    public ObjectHashMap(final Entry[] table) {
+        super( 0.75f, table);
+    }      
+    
+    public ObjectHashMap(final float loadFactor,
+                             final Entry[] table) {
+        super(loadFactor, table);
+    }     
 
     public Object put(final Object key,
                       final Object value) {

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashSet.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashSet.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjectHashSet.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,181 @@
+/**
+ * 
+ */
+package org.drools.util;
+
+import org.drools.util.AbstractHashTable.EqualityEquals;
+
+public class ObjectHashSet extends AbstractHashTable {
+
+    private static final long serialVersionUID = 929633553699602561L;
+
+    public ObjectHashSet() {
+        this( 16,
+              0.75f );
+    }
+
+    public ObjectHashSet(final int capacity,
+                         final float loadFactor) {
+        super( capacity,
+               loadFactor );
+    }
+
+    public ObjectHashSet(final Entry[] table) {
+        super( 0.75f,
+               table );
+    }
+
+    public ObjectHashSet(final float loadFactor,
+                         final Entry[] table) {
+        super( loadFactor,
+               table );
+    }
+
+    public boolean add(final Object value) {
+        return add( value,
+                    true );
+    }
+
+    public void clear() {
+        this.table = new Entry[Math.min( this.table.length,
+                                         16 )];
+        this.threshold = (int) (this.table.length * this.loadFactor);
+    }
+
+    public boolean add(final Object value,
+                       final boolean checkExists) {
+        final int hashCode = this.comparator.hashCodeOf( value );
+        final int index = indexOf( hashCode,
+                                   this.table.length );
+
+        // scan the linked entries to see if it exists
+        if ( checkExists ) {
+            ObjectEntry current = (ObjectEntry) this.table[index];
+            while ( current != null ) {
+                if ( hashCode == current.hashCode && this.comparator.equal( value,
+                                                                            current.value ) ) {
+                    final Object oldValue = current.value;
+                    current.value = value;
+                    return true;
+                }
+                current = (ObjectEntry) current.getNext();
+            }
+        }
+
+        // We aren't checking the key exists, or it didn't find the key
+        final ObjectEntry entry = new ObjectEntry( value,
+                                                   hashCode );
+        entry.next = this.table[index];
+        this.table[index] = entry;
+
+        if ( this.size++ >= this.threshold ) {
+            resize( 2 * this.table.length );
+        }
+        return false;
+    }
+
+    public boolean contains(final Object value) {
+        final int hashCode = this.comparator.hashCodeOf( value );
+        final int index = indexOf( hashCode,
+                                   this.table.length );
+
+        ObjectEntry current = (ObjectEntry) this.table[index];
+        while ( current != null ) {
+            if ( hashCode == current.hashCode && this.comparator.equal( value,
+                                                                        current.value ) ) {
+                return true;
+            }
+            current = (ObjectEntry) current.getNext();
+        }
+        return false;
+    }
+
+    public boolean remove(final Object value) {
+        final int hashCode = this.comparator.hashCodeOf( value );
+        final int index = indexOf( hashCode,
+                                   this.table.length );
+
+        ObjectEntry previous = (ObjectEntry) this.table[index];
+        ObjectEntry current = previous;
+        while ( current != null ) {
+            final ObjectEntry next = (ObjectEntry) current.getNext();
+            if ( hashCode == current.hashCode && this.comparator.equal( value,
+                                                                        current.value ) ) {
+                if ( previous == current ) {
+                    this.table[index] = next;
+                } else {
+                    previous.setNext( next );
+                }
+                current.setNext( null );
+                this.size--;
+                return true;
+            }
+            previous = current;
+            current = next;
+        }
+        return false;
+    }
+
+    public Entry getBucket(final Object object) {
+        final int hashCode = this.comparator.hashCodeOf( object );
+        final int index = indexOf( hashCode,
+                                   this.table.length );
+
+        return this.table[index];
+    }
+    
+    public Object[] toArray(Object[] objects) {
+        Iterator it = iterator();
+        int i = 0;
+        for ( ObjectEntry entry = ( ObjectEntry) it.next(); entry != null; entry = ( ObjectEntry ) it.next() ) {
+            objects[i++] = entry.getValue();
+        }
+        return objects;
+    }
+
+    public static class ObjectEntry
+        implements
+        Entry {
+
+        private static final long serialVersionUID = -2589987113898296555L;
+
+        private Object            value;
+
+        private int               hashCode;
+
+        private Entry             next;
+
+        public ObjectEntry(final Object value,
+                           final int hashCode) {
+            this.value = value;
+            this.hashCode = hashCode;
+        }
+
+        public Object getValue() {
+            return this.value;
+        }
+
+        public Entry getNext() {
+            return this.next;
+        }
+
+        public void setNext(final Entry next) {
+            this.next = next;
+        }
+
+        public int hashCode() {
+            return this.hashCode;
+        }
+
+        public boolean equals(final Object object) {
+            if ( object == this ) {
+                return true;
+            }
+
+            // assumes we never have null or wrong class
+
+            final ObjectEntry other = (ObjectEntry) object;
+            return this.value.equals( other.value );
+        }
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ThreadSafeJavaIteratorAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ThreadSafeJavaIteratorAdapter.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ThreadSafeJavaIteratorAdapter.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,5 @@
+package org.drools.util;
+
+public class ThreadSafeJavaIteratorAdapter {
+
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/AbstractCollection.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/AbstractCollection.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/AbstractCollection.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,31 @@
+/*
+ * Written by Dawid Kurzyniec, based on public domain code written by Doug Lea
+ * and publictly available documentation, and released to the public domain, as
+ * explained at http://creativecommons.org/licenses/publicdomain
+ */
+
+package org.drools.util.concurrent.locks;
+
+/**
+ * Overrides toArray() and toArray(Object[]) in AbstractCollection to provide
+ * implementations valid for concurrent collections.
+ *
+ * @author Doug Lea
+ * @author Dawid Kurzyniec
+ */
+public abstract class AbstractCollection extends java.util.AbstractCollection {
+
+    /**
+     * Sole constructor. (For invocation by subclass constructors, typically
+     * implicit.)
+     */
+    protected AbstractCollection() { super(); }
+
+    public Object[] toArray() {
+        return Utils.collectionToArray(this);
+    }
+
+    public Object[] toArray(Object[] a) {
+        return Utils.collectionToArray(this, a);
+    }
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/AbstractQueue.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/AbstractQueue.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/AbstractQueue.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,170 @@
+/*
+ * Written by Doug Lea with assistance from members of JCP JSR-166
+ * Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
+ */
+
+package org.drools.util.concurrent.locks;
+
+import java.util.Iterator;
+import java.util.Collection;
+import java.util.NoSuchElementException;
+
+/**
+ * This class provides skeletal implementations of some {@link Queue}
+ * operations. The implementations in this class are appropriate when
+ * the base implementation does <em>not</em> allow <tt>null</tt>
+ * elements.  Methods {@link #add add}, {@link #remove remove}, and
+ * {@link #element element} are based on {@link #offer offer}, {@link
+ * #poll poll}, and {@link #peek peek}, respectively but throw
+ * exceptions instead of indicating failure via <tt>false</tt> or
+ * <tt>null</tt> returns.
+ *
+ * <p> A <tt>Queue</tt> implementation that extends this class must
+ * minimally define a method {@link Queue#offer} which does not permit
+ * insertion of <tt>null</tt> elements, along with methods {@link
+ * Queue#peek}, {@link Queue#poll}, {@link Collection#size}, and a
+ * {@link Collection#iterator} supporting {@link
+ * Iterator#remove}. Typically, additional methods will be overridden
+ * as well. If these requirements cannot be met, consider instead
+ * subclassing {@link AbstractCollection}.
+ *
+ * <p>This class is a member of the
+ * <a href="{@docRoot}/../technotes/guides/collections/index.html">
+ * Java Collections Framework</a>.
+ *
+ * @since 1.5
+ * @author Doug Lea
+ */
+public abstract class AbstractQueue
+    extends AbstractCollection
+    implements Queue {
+
+    /**
+     * Constructor for use by subclasses.
+     */
+    protected AbstractQueue() {
+    }
+
+    /**
+     * Inserts the specified element into this queue if it is possible to do so
+     * immediately without violating capacity restrictions, returning
+     * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
+     * if no space is currently available.
+     *
+     * <p>This implementation returns <tt>true</tt> if <tt>offer</tt> succeeds,
+     * else throws an <tt>IllegalStateException</tt>.
+     *
+     * @param e the element to add
+     * @return <tt>true</tt> (as specified by {@link Collection#add})
+     * @throws IllegalStateException if the element cannot be added at this
+     *         time due to capacity restrictions
+     * @throws ClassCastException if the class of the specified element
+     *         prevents it from being added to this queue
+     * @throws NullPointerException if the specified element is null and
+     *         this queue does not permit null elements
+     * @throws IllegalArgumentException if some property of this element
+     *         prevents it from being added to this queue
+     */
+    public boolean add(Object e) {
+        if (offer(e))
+            return true;
+        else
+            throw new IllegalStateException("Queue full");
+    }
+
+    /**
+     * Retrieves and removes the head of this queue.  This method differs
+     * from {@link #poll poll} only in that it throws an exception if this
+     * queue is empty.
+     *
+     * <p>This implementation returns the result of <tt>poll</tt>
+     * unless the queue is empty.
+     *
+     * @return the head of this queue
+     * @throws NoSuchElementException if this queue is empty
+     */
+    public Object remove() {
+        Object x = poll();
+        if (x != null)
+            return x;
+        else
+            throw new NoSuchElementException();
+    }
+
+
+    /**
+     * Retrieves, but does not remove, the head of this queue.  This method
+     * differs from {@link #peek peek} only in that it throws an exception if
+     * this queue is empty.
+     *
+     * <p>This implementation returns the result of <tt>peek</tt>
+     * unless the queue is empty.
+     *
+     * @return the head of this queue
+     * @throws NoSuchElementException if this queue is empty
+     */
+    public Object element() {
+        Object x = peek();
+        if (x != null)
+            return x;
+        else
+            throw new NoSuchElementException();
+    }
+
+    /**
+     * Removes all of the elements from this queue.
+     * The queue will be empty after this call returns.
+     *
+     * <p>This implementation repeatedly invokes {@link #poll poll} until it
+     * returns <tt>null</tt>.
+     */
+    public void clear() {
+        while (poll() != null)
+            ;
+    }
+
+    /**
+     * Adds all of the elements in the specified collection to this
+     * queue.  Attempts to addAll of a queue to itself result in
+     * <tt>IllegalArgumentException</tt>. Further, the behavior of
+     * this operation is undefined if the specified collection is
+     * modified while the operation is in progress.
+     *
+     * <p>This implementation iterates over the specified collection,
+     * and adds each element returned by the iterator to this
+     * queue, in turn.  A runtime exception encountered while
+     * trying to add an element (including, in particular, a
+     * <tt>null</tt> element) may result in only some of the elements
+     * having been successfully added when the associated exception is
+     * thrown.
+     *
+     * @param c collection containing elements to be added to this queue
+     * @return <tt>true</tt> if this queue changed as a result of the call
+     * @throws ClassCastException if the class of an element of the specified
+     *         collection prevents it from being added to this queue
+     * @throws NullPointerException if the specified collection contains a
+     *         null element and this queue does not permit null elements,
+     *         or if the specified collection is null
+     * @throws IllegalArgumentException if some property of an element of the
+     *         specified collection prevents it from being added to this
+     *         queue, or if the specified collection is this queue
+     * @throws IllegalStateException if not all the elements can be added at
+     *         this time due to insertion restrictions
+     * @see #add(Object)
+     */
+    public boolean addAll(Collection c) {
+        if (c == null)
+            throw new NullPointerException();
+        if (c == this)
+            throw new IllegalArgumentException();
+        boolean modified = false;
+        Iterator e = c.iterator();
+        while (e.hasNext()) {
+            if (add(e.next()))
+                modified = true;
+        }
+        return modified;
+    }
+
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Arrays.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Arrays.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Arrays.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,811 @@
+/*
+ * Written by Dawid Kurzyniec, based on code written by Doug Lea with assistance
+ * from members of JCP JSR-166 Expert Group. Released to the public domain,
+ * as explained at http://creativecommons.org/licenses/publicdomain.
+ */
+
+package org.drools.util.concurrent.locks;
+
+import java.lang.reflect.Array;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Comparator;
+
+public class Arrays {
+
+    private Arrays() {}
+
+    public static void sort(long[] a) {
+        java.util.Arrays.sort(a);
+    }
+
+    public static void sort(long[] a, int fromIndex, int toIndex) {
+        java.util.Arrays.sort(a, fromIndex, toIndex);
+    }
+
+    public static void sort(int[] a) {
+        java.util.Arrays.sort(a);
+    }
+
+    public static void sort(int[] a, int fromIndex, int toIndex) {
+        java.util.Arrays.sort(a, fromIndex, toIndex);
+    }
+
+    public static void sort(short[] a) {
+        java.util.Arrays.sort(a);
+    }
+
+    public static void sort(short[] a, int fromIndex, int toIndex) {
+        java.util.Arrays.sort(a, fromIndex, toIndex);
+    }
+
+    public static void sort(char[] a) {
+        java.util.Arrays.sort(a);
+    }
+
+    public static void sort(char[] a, int fromIndex, int toIndex) {
+        java.util.Arrays.sort(a, fromIndex, toIndex);
+    }
+
+    public static void sort(byte[] a) {
+        java.util.Arrays.sort(a);
+    }
+
+    public static void sort(byte[] a, int fromIndex, int toIndex) {
+        java.util.Arrays.sort(a, fromIndex, toIndex);
+    }
+
+    public static void sort(double[] a) {
+        java.util.Arrays.sort(a);
+    }
+
+    public static void sort(double[] a, int fromIndex, int toIndex) {
+        java.util.Arrays.sort(a, fromIndex, toIndex);
+    }
+
+    public static void sort(float[] a) {
+        java.util.Arrays.sort(a);
+    }
+
+    public static void sort(float[] a, int fromIndex, int toIndex) {
+        java.util.Arrays.sort(a, fromIndex, toIndex);
+    }
+
+
+    public static void sort(Object[] a) {
+        java.util.Arrays.sort(a);
+    }
+
+    public static void sort(Object[] a, int fromIndex, int toIndex) {
+        java.util.Arrays.sort(a, fromIndex, toIndex);
+    }
+
+    public static void sort(Object[] a, Comparator c) {
+        java.util.Arrays.sort(a, c);
+    }
+
+    public static void sort(Object[] a, int fromIndex, int toIndex, Comparator c) {
+        java.util.Arrays.sort(a, fromIndex, toIndex, c);
+    }
+
+
+    // Searching
+
+    public static int binarySearch(long[] a, long key) {
+        return java.util.Arrays.binarySearch(a, key);
+    }
+
+    public static int binarySearch(int[] a, int key) {
+        return java.util.Arrays.binarySearch(a, key);
+    }
+
+    public static int binarySearch(short[] a, short key) {
+        return java.util.Arrays.binarySearch(a, key);
+    }
+
+    public static int binarySearch(char[] a, char key) {
+        return java.util.Arrays.binarySearch(a, key);
+    }
+
+    public static int binarySearch(byte[] a, byte key) {
+        return java.util.Arrays.binarySearch(a, key);
+    }
+
+    public static int binarySearch(double[] a, double key) {
+        return java.util.Arrays.binarySearch(a, key);
+    }
+
+    public static int binarySearch(float[] a, float key) {
+        return java.util.Arrays.binarySearch(a, key);
+    }
+
+    public static int binarySearch(Object[] a, Object key) {
+        return java.util.Arrays.binarySearch(a, key);
+    }
+
+    public static int binarySearch(Object[] a, Object key, Comparator c) {
+        return java.util.Arrays.binarySearch(a, key, c);
+    }
+
+
+    // Equality Testing
+
+    public static boolean equals(long[] a, long[] a2) {
+        return java.util.Arrays.equals(a, a2);
+    }
+
+    public static boolean equals(int[] a, int[] a2) {
+        return java.util.Arrays.equals(a, a2);
+    }
+
+    public static boolean equals(short[] a, short a2[]) {
+        return java.util.Arrays.equals(a, a2);
+    }
+
+    public static boolean equals(char[] a, char[] a2) {
+        return java.util.Arrays.equals(a, a2);
+    }
+
+    public static boolean equals(byte[] a, byte[] a2) {
+        return java.util.Arrays.equals(a, a2);
+    }
+
+    public static boolean equals(boolean[] a, boolean[] a2) {
+        return java.util.Arrays.equals(a, a2);
+    }
+
+    public static boolean equals(double[] a, double[] a2) {
+        return java.util.Arrays.equals(a, a2);
+    }
+
+    public static boolean equals(float[] a, float[] a2) {
+        return java.util.Arrays.equals(a, a2);
+    }
+
+    public static boolean equals(Object[] a, Object[] a2) {
+        return java.util.Arrays.equals(a, a2);
+    }
+
+
+    // Filling
+
+    public static void fill(long[] a, long val) {
+        java.util.Arrays.fill(a, val);
+    }
+
+    public static void fill(long[] a, int fromIndex, int toIndex, long val) {
+        java.util.Arrays.fill(a, fromIndex, toIndex, val);
+    }
+
+    public static void fill(int[] a, int val) {
+        java.util.Arrays.fill(a, val);
+    }
+
+    public static void fill(int[] a, int fromIndex, int toIndex, int val) {
+        java.util.Arrays.fill(a, fromIndex, toIndex, val);
+    }
+
+    public static void fill(short[] a, short val) {
+        java.util.Arrays.fill(a, val);
+    }
+
+    public static void fill(short[] a, int fromIndex, int toIndex, short val) {
+        java.util.Arrays.fill(a, fromIndex, toIndex, val);
+    }
+
+    public static void fill(char[] a, char val) {
+        java.util.Arrays.fill(a, val);
+    }
+
+    public static void fill(char[] a, int fromIndex, int toIndex, char val) {
+        java.util.Arrays.fill(a, fromIndex, toIndex, val);
+    }
+
+    public static void fill(byte[] a, byte val) {
+        java.util.Arrays.fill(a, val);
+    }
+
+    public static void fill(byte[] a, int fromIndex, int toIndex, byte val) {
+        java.util.Arrays.fill(a, fromIndex, toIndex, val);
+    }
+
+    public static void fill(boolean[] a, boolean val) {
+        java.util.Arrays.fill(a, val);
+    }
+
+    public static void fill(boolean[] a, int fromIndex, int toIndex,
+                            boolean val) {
+        java.util.Arrays.fill(a, fromIndex, toIndex, val);
+    }
+
+    public static void fill(double[] a, double val) {
+        java.util.Arrays.fill(a, val);
+    }
+
+    public static void fill(double[] a, int fromIndex, int toIndex,double val) {
+        java.util.Arrays.fill(a, fromIndex, toIndex, val);
+    }
+
+    public static void fill(float[] a, float val) {
+        java.util.Arrays.fill(a, val);
+    }
+
+    public static void fill(float[] a, int fromIndex, int toIndex, float val) {
+        java.util.Arrays.fill(a, fromIndex, toIndex, val);
+    }
+
+    public static void fill(Object[] a, Object val) {
+        java.util.Arrays.fill(a, val);
+    }
+
+    public static void fill(Object[] a, int fromIndex, int toIndex, Object val) {
+        java.util.Arrays.fill(a, fromIndex, toIndex, val);
+    }
+
+
+    // Cloning
+
+    /**
+     * @since 1.6
+     */
+    public static Object[] copyOf(Object[] original, int newLength) {
+        return copyOf(original, newLength, original.getClass());
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static Object[] copyOf(Object[] original, int newLength, Class newType) {
+        Object[] arr = (newType == Object[].class) ? new Object[newLength] :
+            (Object[])Array.newInstance(newType.getComponentType(), newLength);
+        int len  = (original.length < newLength ? original.length : newLength);
+        System.arraycopy(original, 0, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static byte[] copyOf(byte[] original, int newLength) {
+        byte[] arr = new byte[newLength];
+        int len  = (original.length < newLength ? original.length : newLength);
+        System.arraycopy(original, 0, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static short[] copyOf(short[] original, int newLength) {
+        short[] arr = new short[newLength];
+        int len  = (original.length < newLength ? original.length : newLength);
+        System.arraycopy(original, 0, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static int[] copyOf(int[] original, int newLength) {
+        int[] arr = new int[newLength];
+        int len  = (original.length < newLength ? original.length : newLength);
+        System.arraycopy(original, 0, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static long[] copyOf(long[] original, int newLength) {
+        long[] arr = new long[newLength];
+        int len  = (original.length < newLength ? original.length : newLength);
+        System.arraycopy(original, 0, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static char[] copyOf(char[] original, int newLength) {
+        char[] arr = new char[newLength];
+        int len  = (original.length < newLength ? original.length : newLength);
+        System.arraycopy(original, 0, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static float[] copyOf(float[] original, int newLength) {
+        float[] arr = new float[newLength];
+        int len  = (original.length < newLength ? original.length : newLength);
+        System.arraycopy(original, 0, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static double[] copyOf(double[] original, int newLength) {
+        double[] arr = new double[newLength];
+        int len  = (original.length < newLength ? original.length : newLength);
+        System.arraycopy(original, 0, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static boolean[] copyOf(boolean[] original, int newLength) {
+        boolean[] arr = new boolean[newLength];
+        int len  = (original.length < newLength ? original.length : newLength);
+        System.arraycopy(original, 0, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static Object[] copyOfRange(Object[] original, int from, int to) {
+        return copyOfRange(original, from, to, original.getClass());
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static Object[] copyOfRange(Object[] original, int from, int to, Class newType) {
+        int newLength = to - from;
+        if (newLength < 0) throw new IllegalArgumentException(from + " > " + to);
+        Object[] arr = (newType == Object[].class) ? new Object[newLength] :
+            (Object[])Array.newInstance(newType.getComponentType(), newLength);
+        int ceil = original.length-from;
+        int len = (ceil < newLength) ? ceil : newLength;
+        System.arraycopy(original, from, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static byte[] copyOfRange(byte[] original, int from, int to) {
+        int newLength = to - from;
+        if (newLength < 0) throw new IllegalArgumentException(from + " > " + to);
+        byte[] arr = new byte[newLength];
+        int ceil = original.length-from;
+        int len = (ceil < newLength) ? ceil : newLength;
+        System.arraycopy(original, from, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static short[] copyOfRange(short[] original, int from, int to) {
+        int newLength = to - from;
+        if (newLength < 0) throw new IllegalArgumentException(from + " > " + to);
+        short[] arr = new short[newLength];
+        int ceil = original.length-from;
+        int len = (ceil < newLength) ? ceil : newLength;
+        System.arraycopy(original, from, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static int[] copyOfRange(int[] original, int from, int to) {
+        int newLength = to - from;
+        if (newLength < 0) throw new IllegalArgumentException(from + " > " + to);
+        int[] arr = new int[newLength];
+        int ceil = original.length-from;
+        int len = (ceil < newLength) ? ceil : newLength;
+        System.arraycopy(original, from, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static long[] copyOfRange(long[] original, int from, int to) {
+        int newLength = to - from;
+        if (newLength < 0) throw new IllegalArgumentException(from + " > " + to);
+        long[] arr = new long[newLength];
+        int ceil = original.length-from;
+        int len = (ceil < newLength) ? ceil : newLength;
+        System.arraycopy(original, from, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static char[] copyOfRange(char[] original, int from, int to) {
+        int newLength = to - from;
+        if (newLength < 0) throw new IllegalArgumentException(from + " > " + to);
+        char[] arr = new char[newLength];
+        int ceil = original.length-from;
+        int len = (ceil < newLength) ? ceil : newLength;
+        System.arraycopy(original, from, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static float[] copyOfRange(float[] original, int from, int to) {
+        int newLength = to - from;
+        if (newLength < 0) throw new IllegalArgumentException(from + " > " + to);
+        float[] arr = new float[newLength];
+        int ceil = original.length-from;
+        int len = (ceil < newLength) ? ceil : newLength;
+        System.arraycopy(original, from, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static double[] copyOfRange(double[] original, int from, int to) {
+        int newLength = to - from;
+        if (newLength < 0) throw new IllegalArgumentException(from + " > " + to);
+        double[] arr = new double[newLength];
+        int ceil = original.length-from;
+        int len = (ceil < newLength) ? ceil : newLength;
+        System.arraycopy(original, from, arr, 0, len);
+        return arr;
+    }
+
+    /**
+     * @since 1.6
+     */
+    public static boolean[] copyOfRange(boolean[] original, int from, int to) {
+        int newLength = to - from;
+        if (newLength < 0) throw new IllegalArgumentException(from + " > " + to);
+        boolean[] arr = new boolean[newLength];
+        int ceil = original.length-from;
+        int len = (ceil < newLength) ? ceil : newLength;
+        System.arraycopy(original, from, arr, 0, len);
+        return arr;
+    }
+
+
+    public static List asList(Object[] a) {
+        return java.util.Arrays.asList(a);
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static int hashCode(long a[]) {
+        if (a == null) return 0;
+        int hash = 1;
+        for (int i=0; i<a.length; i++) {
+            long e = a[i];
+            hash = 31*hash + (int)(e ^ (e >>> 32));
+        }
+        return hash;
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static int hashCode(int a[]) {
+        if (a == null) return 0;
+        int hash = 1;
+        for (int i=0; i<a.length; i++) {
+            hash = 31*hash + a[i];
+        }
+        return hash;
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static int hashCode(short a[]) {
+        if (a == null) return 0;
+        int hash = 1;
+        for (int i=0; i<a.length; i++) {
+            hash = 31*hash + a[i];
+        }
+        return hash;
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static int hashCode(char a[]) {
+        if (a == null) return 0;
+        int hash = 1;
+        for (int i=0; i<a.length; i++) {
+            hash = 31*hash + a[i];
+        }
+        return hash;
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static int hashCode(byte a[]) {
+        if (a == null) return 0;
+        int hash = 1;
+        for (int i=0; i<a.length; i++) {
+            hash = 31*hash + a[i];
+        }
+        return hash;
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static int hashCode(boolean a[]) {
+        if (a == null) return 0;
+        int hash = 1;
+        for (int i=0; i<a.length; i++) {
+            hash = 31*hash + (a[i] ? 1231 : 1237);
+        }
+        return hash;
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static int hashCode(float a[]) {
+        if (a == null) return 0;
+        int hash = 1;
+        for (int i=0; i<a.length; i++) {
+            hash = 31*hash + Float.floatToIntBits(a[i]);
+        }
+        return hash;
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static int hashCode(double a[]) {
+        if (a == null) return 0;
+        int hash = 1;
+        for (int i=0; i<a.length; i++) {
+            long e = Double.doubleToLongBits(a[i]);
+            hash = 31*hash + (int)(e ^ (e >>> 32));
+        }
+        return hash;
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static int hashCode(Object a[]) {
+        if (a == null) return 0;
+        int hash = 1;
+        for (int i=0; i<a.length; i++) {
+            Object e = a[i];
+            hash = 31*hash + (e == null ? 0 : e.hashCode());
+        }
+        return hash;
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static int deepHashCode(Object a[]) {
+        if (a == null) return 0;
+        int hash = 1;
+        for (int i=0; i<a.length; i++) {
+            Object e = a[i];
+            hash = 31*hash +
+                   (e instanceof Object[]  ? deepHashCode((Object[])e) :
+                   (e instanceof byte[]    ? hashCode((byte[])e) :
+                   (e instanceof short[]   ? hashCode((short[])e) :
+                   (e instanceof int[]     ? hashCode((int[])e) :
+                   (e instanceof long[]    ? hashCode((long[])e) :
+                   (e instanceof char[]    ? hashCode((char[])e) :
+                   (e instanceof boolean[] ? hashCode((boolean[])e) :
+                   (e instanceof float[]   ? hashCode((float[])e) :
+                   (e instanceof double[]  ? hashCode((double[])e) :
+                   (e != null              ? e.hashCode() : 0))))))))));
+        }
+        return hash;
+
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static boolean deepEquals(Object[] a1, Object[] a2) {
+        if (a1 == a2) return true;
+        if (a1 == null || a2==null) return false;
+        int len = a1.length;
+        if (len != a2.length) return false;
+        for (int i = 0; i < len; i++) {
+            Object e1 = a1[i];
+            Object e2 = a2[i];
+            if (e1 == e2) continue;
+            if (e1 == null) return false;
+            boolean eq =
+                (e1.getClass() != e2.getClass() || e1.getClass().isArray()) ?
+                        e1.equals(e2) :
+                (e1 instanceof Object[] && e2 instanceof Object[]) ?
+                        deepEquals((Object[])e1, (Object[])e2) :
+                (e1 instanceof byte[] && e2 instanceof byte[]) ?
+                        equals((byte[])e1, (byte[])e2) :
+                (e1 instanceof short[] && e2 instanceof short[]) ?
+                        equals((short[])e1, (short[])e2) :
+                (e1 instanceof int[] && e2 instanceof int[]) ?
+                        equals((int[])e1, (int[])e2) :
+                (e1 instanceof long[] && e2 instanceof long[]) ?
+                        equals((long[])e1, (long[])e2) :
+                (e1 instanceof char[] && e2 instanceof char[]) ?
+                        equals((char[])e1, (char[])e2) :
+                (e1 instanceof boolean[] && e2 instanceof boolean[]) ?
+                        equals((boolean[])e1, (boolean[])e2) :
+                (e1 instanceof float[] && e2 instanceof float[]) ?
+                        equals((float[])e1, (float[])e2) :
+                (e1 instanceof double[] && e2 instanceof double[]) ?
+                        equals((double[])e1, (double[])e2) :
+                e1.equals(e2);
+
+            if (!eq) return false;
+        }
+        return true;
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static String toString(long[] a) {
+        if (a == null) return "null";
+        if (a.length == 0) return "[]";
+        StringBuffer buf = new StringBuffer();
+        buf.append('[').append(a[0]);
+        for (int i=1; i<a.length; i++) buf.append(", ").append(a[i]);
+        buf.append(']');
+        return buf.toString();
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static String toString(int[] a) {
+        if (a == null) return "null";
+        if (a.length == 0) return "[]";
+        StringBuffer buf = new StringBuffer();
+        buf.append('[').append(a[0]);
+        for (int i=1; i<a.length; i++) buf.append(", ").append(a[i]);
+        buf.append(']');
+        return buf.toString();
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static String toString(short[] a) {
+        if (a == null) return "null";
+        if (a.length == 0) return "[]";
+        StringBuffer buf = new StringBuffer();
+        buf.append('[').append(a[0]);
+        for (int i=1; i<a.length; i++) buf.append(", ").append(a[i]);
+        buf.append(']');
+        return buf.toString();
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static String toString(char[] a) {
+        if (a == null) return "null";
+        if (a.length == 0) return "[]";
+        StringBuffer buf = new StringBuffer();
+        buf.append('[').append(a[0]);
+        for (int i=1; i<a.length; i++) buf.append(", ").append(a[i]);
+        buf.append(']');
+        return buf.toString();
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static String toString(byte[] a) {
+        if (a == null) return "null";
+        if (a.length == 0) return "[]";
+        StringBuffer buf = new StringBuffer();
+        buf.append('[').append(a[0]);
+        for (int i=1; i<a.length; i++) buf.append(", ").append(a[i]);
+        buf.append(']');
+        return buf.toString();
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static String toString(boolean[] a) {
+        if (a == null) return "null";
+        if (a.length == 0) return "[]";
+        StringBuffer buf = new StringBuffer();
+        buf.append('[').append(a[0]);
+        for (int i=1; i<a.length; i++) buf.append(", ").append(a[i]);
+        buf.append(']');
+        return buf.toString();
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static String toString(float[] a) {
+        if (a == null) return "null";
+        if (a.length == 0) return "[]";
+        StringBuffer buf = new StringBuffer();
+        buf.append('[').append(a[0]);
+        for (int i=1; i<a.length; i++) buf.append(", ").append(a[i]);
+        buf.append(']');
+        return buf.toString();
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static String toString(double[] a) {
+        if (a == null) return "null";
+        if (a.length == 0) return "[]";
+        StringBuffer buf = new StringBuffer();
+        buf.append('[').append(a[0]);
+        for (int i=1; i<a.length; i++) buf.append(", ").append(a[i]);
+        buf.append(']');
+        return buf.toString();
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static String toString(Object[] a) {
+        if (a == null) return "null";
+        if (a.length == 0) return "[]";
+        StringBuffer buf = new StringBuffer();
+        buf.append('[').append(a[0]);
+        for (int i=1; i<a.length; i++) buf.append(", ").append(a[i]);
+        buf.append(']');
+        return buf.toString();
+    }
+
+    /**
+     * @since 1.5
+     */
+    public static String deepToString(Object[] a) {
+        if (a == null) return "null";
+        StringBuffer buf = new StringBuffer();
+        deepToString(a, buf, new ArrayList());
+        return buf.toString();
+    }
+
+    private static void deepToString(Object[] a, StringBuffer buf, List seen) {
+        seen.add(a);
+        buf.append('[');
+        for (int i = 0; i < a.length; i++) {
+            if (i>0) buf.append(", ");
+            Object e = a[i];
+            if (e == null) {
+                buf.append("null");
+            }
+            else if (!e.getClass().isArray()) {
+                buf.append(e.toString());
+            }
+            else if (e instanceof Object[]) {
+                if (seen.contains(e)) buf.append("[...]");
+                else deepToString((Object[])e, buf, seen);
+            }
+            else {
+                // primitive arr
+                buf.append(
+                    (e instanceof byte[]) ? toString( (byte[]) e) :
+                    (e instanceof short[]) ? toString( (short[]) e) :
+                    (e instanceof int[]) ? toString( (int[]) e) :
+                    (e instanceof long[]) ? toString( (long[]) e) :
+                    (e instanceof char[]) ? toString( (char[]) e) :
+                    (e instanceof boolean[]) ? toString( (boolean[]) e) :
+                    (e instanceof float[]) ? toString( (float[]) e) :
+                    (e instanceof double[]) ? toString( (double[]) e) : "");
+            }
+        }
+        buf.append(']');
+        seen.remove(seen.size()-1);
+    }
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/BlockingQueue.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/BlockingQueue.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/BlockingQueue.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,342 @@
+/*
+ * Written by Doug Lea with assistance from members of JCP JSR-166
+ * Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
+ */
+
+package org.drools.util.concurrent.locks;
+
+import java.util.Collection;
+
+/**
+ * A {@link edu.emory.mathcs.backport.java.util.Queue} that additionally supports operations
+ * that wait for the queue to become non-empty when retrieving an
+ * element, and wait for space to become available in the queue when
+ * storing an element.
+ *
+ * <p><tt>BlockingQueue</tt> methods come in four forms, with different ways
+ * of handling operations that cannot be satisfied immediately, but may be
+ * satisfied at some point in the future:
+ * one throws an exception, the second returns a special value (either
+ * <tt>null</tt> or <tt>false</tt>, depending on the operation), the third
+ * blocks the current thread indefinitely until the operation can succeed,
+ * and the fourth blocks for only a given maximum time limit before giving
+ * up.  These methods are summarized in the following table:
+ *
+ * <p>
+ * <table BORDER CELLPADDING=3 CELLSPACING=1>
+ *  <tr>
+ *    <td></td>
+ *    <td ALIGN=CENTER><em>Throws exception</em></td>
+ *    <td ALIGN=CENTER><em>Special value</em></td>
+ *    <td ALIGN=CENTER><em>Blocks</em></td>
+ *    <td ALIGN=CENTER><em>Times out</em></td>
+ *  </tr>
+ *  <tr>
+ *    <td><b>Insert</b></td>
+ *    <td>{@link #add add(e)}</td>
+ *    <td>{@link #offer offer(e)}</td>
+ *    <td>{@link #put put(e)}</td>
+ *    <td>{@link #offer(Object, long, TimeUnit) offer(e, time, unit)}</td>
+ *  </tr>
+ *  <tr>
+ *    <td><b>Remove</b></td>
+ *    <td>{@link #remove remove()}</td>
+ *    <td>{@link #poll poll()}</td>
+ *    <td>{@link #take take()}</td>
+ *    <td>{@link #poll(long, TimeUnit) poll(time, unit)}</td>
+ *  </tr>
+ *  <tr>
+ *    <td><b>Examine</b></td>
+ *    <td>{@link #element element()}</td>
+ *    <td>{@link #peek peek()}</td>
+ *    <td><em>not applicable</em></td>
+ *    <td><em>not applicable</em></td>
+ *  </tr>
+ * </table>
+ *
+ * <p>A <tt>BlockingQueue</tt> does not accept <tt>null</tt> elements.
+ * Implementations throw <tt>NullPointerException</tt> on attempts
+ * to <tt>add</tt>, <tt>put</tt> or <tt>offer</tt> a <tt>null</tt>.  A
+ * <tt>null</tt> is used as a sentinel value to indicate failure of
+ * <tt>poll</tt> operations.
+ *
+ * <p>A <tt>BlockingQueue</tt> may be capacity bounded. At any given
+ * time it may have a <tt>remainingCapacity</tt> beyond which no
+ * additional elements can be <tt>put</tt> without blocking.
+ * A <tt>BlockingQueue</tt> without any intrinsic capacity constraints always
+ * reports a remaining capacity of <tt>Integer.MAX_VALUE</tt>.
+ *
+ * <p> <tt>BlockingQueue</tt> implementations are designed to be used
+ * primarily for producer-consumer queues, but additionally support
+ * the {@link java.util.Collection} interface.  So, for example, it is
+ * possible to remove an arbitrary element from a queue using
+ * <tt>remove(x)</tt>. However, such operations are in general
+ * <em>not</em> performed very efficiently, and are intended for only
+ * occasional use, such as when a queued message is cancelled.
+ *
+ * <p> <tt>BlockingQueue</tt> implementations are thread-safe.  All
+ * queuing methods achieve their effects atomically using internal
+ * locks or other forms of concurrency control. However, the
+ * <em>bulk</em> Collection operations <tt>addAll</tt>,
+ * <tt>containsAll</tt>, <tt>retainAll</tt> and <tt>removeAll</tt> are
+ * <em>not</em> necessarily performed atomically unless specified
+ * otherwise in an implementation. So it is possible, for example, for
+ * <tt>addAll(c)</tt> to fail (throwing an exception) after adding
+ * only some of the elements in <tt>c</tt>.
+ *
+ * <p>A <tt>BlockingQueue</tt> does <em>not</em> intrinsically support
+ * any kind of &quot;close&quot; or &quot;shutdown&quot; operation to
+ * indicate that no more items will be added.  The needs and usage of
+ * such features tend to be implementation-dependent. For example, a
+ * common tactic is for producers to insert special
+ * <em>end-of-stream</em> or <em>poison</em> objects, that are
+ * interpreted accordingly when taken by consumers.
+ *
+ * <p>
+ * Usage example, based on a typical producer-consumer scenario.
+ * Note that a <tt>BlockingQueue</tt> can safely be used with multiple
+ * producers and multiple consumers.
+ * <pre>
+ * class Producer implements Runnable {
+ *   private final BlockingQueue queue;
+ *   Producer(BlockingQueue q) { queue = q; }
+ *   public void run() {
+ *     try {
+ *       while (true) { queue.put(produce()); }
+ *     } catch (InterruptedException ex) { ... handle ...}
+ *   }
+ *   Object produce() { ... }
+ * }
+ *
+ * class Consumer implements Runnable {
+ *   private final BlockingQueue queue;
+ *   Consumer(BlockingQueue q) { queue = q; }
+ *   public void run() {
+ *     try {
+ *       while (true) { consume(queue.take()); }
+ *     } catch (InterruptedException ex) { ... handle ...}
+ *   }
+ *   void consume(Object x) { ... }
+ * }
+ *
+ * class Setup {
+ *   void main() {
+ *     BlockingQueue q = new SomeQueueImplementation();
+ *     Producer p = new Producer(q);
+ *     Consumer c1 = new Consumer(q);
+ *     Consumer c2 = new Consumer(q);
+ *     new Thread(p).start();
+ *     new Thread(c1).start();
+ *     new Thread(c2).start();
+ *   }
+ * }
+ * </pre>
+ *
+ * <p>Memory consistency effects: As with other concurrent
+ * collections, actions in a thread prior to placing an object into a
+ * {@code BlockingQueue}
+ * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
+ * actions subsequent to the access or removal of that element from
+ * the {@code BlockingQueue} in another thread.
+ *
+ * <p>This interface is a member of the
+ * <a href="{@docRoot}/../technotes/guides/collections/index.html">
+ * Java Collections Framework</a>.
+ *
+ * @since 1.5
+ * @author Doug Lea
+ */
+public interface BlockingQueue extends Queue {
+    /**
+     * Inserts the specified element into this queue if it is possible to do
+     * so immediately without violating capacity restrictions, returning
+     * <tt>true</tt> upon success and throwing an
+     * <tt>IllegalStateException</tt> if no space is currently available.
+     * When using a capacity-restricted queue, it is generally preferable to
+     * use {@link #offer(Object) offer}.
+     *
+     * @param e the element to add
+     * @return <tt>true</tt> (as specified by {@link java.util.Collection#add})
+     * @throws IllegalStateException if the element cannot be added at this
+     *         time due to capacity restrictions
+     * @throws ClassCastException if the class of the specified element
+     *         prevents it from being added to this queue
+     * @throws NullPointerException if the specified element is null
+     * @throws IllegalArgumentException if some property of the specified
+     *         element prevents it from being added to this queue
+     */
+    boolean add(Object e);
+
+    /**
+     * Inserts the specified element into this queue if it is possible to do
+     * so immediately without violating capacity restrictions, returning
+     * <tt>true</tt> upon success and <tt>false</tt> if no space is currently
+     * available.  When using a capacity-restricted queue, this method is
+     * generally preferable to {@link #add}, which can fail to insert an
+     * element only by throwing an exception.
+     *
+     * @param e the element to add
+     * @return <tt>true</tt> if the element was added to this queue, else
+     *         <tt>false</tt>
+     * @throws ClassCastException if the class of the specified element
+     *         prevents it from being added to this queue
+     * @throws NullPointerException if the specified element is null
+     * @throws IllegalArgumentException if some property of the specified
+     *         element prevents it from being added to this queue
+     */
+    boolean offer(Object e);
+
+    /**
+     * Inserts the specified element into this queue, waiting if necessary
+     * for space to become available.
+     *
+     * @param e the element to add
+     * @throws InterruptedException if interrupted while waiting
+     * @throws ClassCastException if the class of the specified element
+     *         prevents it from being added to this queue
+     * @throws NullPointerException if the specified element is null
+     * @throws IllegalArgumentException if some property of the specified
+     *         element prevents it from being added to this queue
+     */
+    void put(Object e) throws InterruptedException;
+
+    /**
+     * Inserts the specified element into this queue, waiting up to the
+     * specified wait time if necessary for space to become available.
+     *
+     * @param e the element to add
+     * @param timeout how long to wait before giving up, in units of
+     *        <tt>unit</tt>
+     * @param unit a <tt>TimeUnit</tt> determining how to interpret the
+     *        <tt>timeout</tt> parameter
+     * @return <tt>true</tt> if successful, or <tt>false</tt> if
+     *         the specified waiting time elapses before space is available
+     * @throws InterruptedException if interrupted while waiting
+     * @throws ClassCastException if the class of the specified element
+     *         prevents it from being added to this queue
+     * @throws NullPointerException if the specified element is null
+     * @throws IllegalArgumentException if some property of the specified
+     *         element prevents it from being added to this queue
+     */
+    boolean offer(Object e, long timeout, TimeUnit unit)
+        throws InterruptedException;
+
+    /**
+     * Retrieves and removes the head of this queue, waiting if necessary
+     * until an element becomes available.
+     *
+     * @return the head of this queue
+     * @throws InterruptedException if interrupted while waiting
+     */
+    Object take() throws InterruptedException;
+
+    /**
+     * Retrieves and removes the head of this queue, waiting up to the
+     * specified wait time if necessary for an element to become available.
+     *
+     * @param timeout how long to wait before giving up, in units of
+     *        <tt>unit</tt>
+     * @param unit a <tt>TimeUnit</tt> determining how to interpret the
+     *        <tt>timeout</tt> parameter
+     * @return the head of this queue, or <tt>null</tt> if the
+     *         specified waiting time elapses before an element is available
+     * @throws InterruptedException if interrupted while waiting
+     */
+    Object poll(long timeout, TimeUnit unit)
+        throws InterruptedException;
+
+    /**
+     * Returns the number of additional elements that this queue can ideally
+     * (in the absence of memory or resource constraints) accept without
+     * blocking, or <tt>Integer.MAX_VALUE</tt> if there is no intrinsic
+     * limit.
+     *
+     * <p>Note that you <em>cannot</em> always tell if an attempt to insert
+     * an element will succeed by inspecting <tt>remainingCapacity</tt>
+     * because it may be the case that another thread is about to
+     * insert or remove an element.
+     *
+     * @return the remaining capacity
+     */
+    int remainingCapacity();
+
+    /**
+     * Removes a single instance of the specified element from this queue,
+     * if it is present.  More formally, removes an element <tt>e</tt> such
+     * that <tt>o.equals(e)</tt>, if this queue contains one or more such
+     * elements.
+     * Returns <tt>true</tt> if this queue contained the specified element
+     * (or equivalently, if this queue changed as a result of the call).
+     *
+     * @param o element to be removed from this queue, if present
+     * @return <tt>true</tt> if this queue changed as a result of the call
+     * @throws ClassCastException if the class of the specified element
+     *         is incompatible with this queue (optional)
+     * @throws NullPointerException if the specified element is null (optional)
+     */
+    boolean remove(Object o);
+
+    /**
+     * Returns <tt>true</tt> if this queue contains the specified element.
+     * More formally, returns <tt>true</tt> if and only if this queue contains
+     * at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>.
+     *
+     * @param o object to be checked for containment in this queue
+     * @return <tt>true</tt> if this queue contains the specified element
+     * @throws ClassCastException if the class of the specified element
+     *         is incompatible with this queue (optional)
+     * @throws NullPointerException if the specified element is null (optional)
+     */
+    public boolean contains(Object o);
+
+    /**
+     * Removes all available elements from this queue and adds them
+     * to the given collection.  This operation may be more
+     * efficient than repeatedly polling this queue.  A failure
+     * encountered while attempting to add elements to
+     * collection <tt>c</tt> may result in elements being in neither,
+     * either or both collections when the associated exception is
+     * thrown.  Attempts to drain a queue to itself result in
+     * <tt>IllegalArgumentException</tt>. Further, the behavior of
+     * this operation is undefined if the specified collection is
+     * modified while the operation is in progress.
+     *
+     * @param c the collection to transfer elements into
+     * @return the number of elements transferred
+     * @throws UnsupportedOperationException if addition of elements
+     *         is not supported by the specified collection
+     * @throws ClassCastException if the class of an element of this queue
+     *         prevents it from being added to the specified collection
+     * @throws NullPointerException if the specified collection is null
+     * @throws IllegalArgumentException if the specified collection is this
+     *         queue, or some property of an element of this queue prevents
+     *         it from being added to the specified collection
+     */
+    int drainTo(Collection c);
+
+    /**
+     * Removes at most the given number of available elements from
+     * this queue and adds them to the given collection.  A failure
+     * encountered while attempting to add elements to
+     * collection <tt>c</tt> may result in elements being in neither,
+     * either or both collections when the associated exception is
+     * thrown.  Attempts to drain a queue to itself result in
+     * <tt>IllegalArgumentException</tt>. Further, the behavior of
+     * this operation is undefined if the specified collection is
+     * modified while the operation is in progress.
+     *
+     * @param c the collection to transfer elements into
+     * @param maxElements the maximum number of elements to transfer
+     * @return the number of elements transferred
+     * @throws UnsupportedOperationException if addition of elements
+     *         is not supported by the specified collection
+     * @throws ClassCastException if the class of an element of this queue
+     *         prevents it from being added to the specified collection
+     * @throws NullPointerException if the specified collection is null
+     * @throws IllegalArgumentException if the specified collection is this
+     *         queue, or some property of an element of this queue prevents
+     *         it from being added to the specified collection
+     */
+    int drainTo(Collection c, int maxElements);
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/LinkedBlockingQueue.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/LinkedBlockingQueue.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/LinkedBlockingQueue.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,749 @@
+/*
+ * Written by Doug Lea with assistance from members of JCP JSR-166
+ * Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
+ */
+
+package org.drools.util.concurrent.locks;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * An optionally-bounded {@linkplain BlockingQueue blocking queue} based on
+ * linked nodes.
+ * This queue orders elements FIFO (first-in-first-out).
+ * The <em>head</em> of the queue is that element that has been on the
+ * queue the longest time.
+ * The <em>tail</em> of the queue is that element that has been on the
+ * queue the shortest time. New elements
+ * are inserted at the tail of the queue, and the queue retrieval
+ * operations obtain elements at the head of the queue.
+ * Linked queues typically have higher throughput than array-based queues but
+ * less predictable performance in most concurrent applications.
+ *
+ * <p> The optional capacity bound constructor argument serves as a
+ * way to prevent excessive queue expansion. The capacity, if unspecified,
+ * is equal to {@link Integer#MAX_VALUE}.  Linked nodes are
+ * dynamically created upon each insertion unless this would bring the
+ * queue above capacity.
+ *
+ * <p>This class and its iterator implement all of the
+ * <em>optional</em> methods of the {@link Collection} and {@link
+ * Iterator} interfaces.
+ *
+ * <p>This class is a member of the
+ * <a href="{@docRoot}/../technotes/guides/collections/index.html">
+ * Java Collections Framework</a>.
+ *
+ * @since 1.5
+ * @author Doug Lea
+ *
+ */
+public class LinkedBlockingQueue extends AbstractQueue
+        implements BlockingQueue, java.io.Serializable {
+    private static final long serialVersionUID = -6903933977591709194L;
+
+    /*
+     * A variant of the "two lock queue" algorithm.  The putLock gates
+     * entry to put (and offer), and has an associated condition for
+     * waiting puts.  Similarly for the takeLock.  The "count" field
+     * that they both rely on is maintained as an atomic to avoid
+     * needing to get both locks in most cases. Also, to minimize need
+     * for puts to get takeLock and vice-versa, cascading notifies are
+     * used. When a put notices that it has enabled at least one take,
+     * it signals taker. That taker in turn signals others if more
+     * items have been entered since the signal. And symmetrically for
+     * takes signalling puts. Operations such as remove(Object) and
+     * iterators acquire both locks.
+     */
+
+    /**
+     * Linked list node class
+     */
+    static class Node {
+        /** The item, volatile to ensure barrier separating write and read */
+        volatile Object item;
+        Node next;
+        Node(Object x) { item = x; }
+    }
+
+    /** The capacity bound, or Integer.MAX_VALUE if none */
+    private final int capacity;
+
+    /** Current number of elements */
+    private volatile int count = 0;
+
+    /** Head of linked list */
+    private transient Node head;
+
+    /** Tail of linked list */
+    private transient Node last;
+
+    /** Lock held by take, poll, etc */
+    private final Object takeLock = new SerializableLock();
+
+    /** Lock held by put, offer, etc */
+    private final Object putLock = new SerializableLock();
+
+    /**
+     * Signals a waiting take. Called only from put/offer (which do not
+     * otherwise ordinarily lock takeLock.)
+     */
+    private void signalNotEmpty() {
+        synchronized (takeLock) {
+            takeLock.notify();
+        }
+    }
+
+    /**
+     * Signals a waiting put. Called only from take/poll.
+     */
+    private void signalNotFull() {
+        synchronized (putLock) {
+            putLock.notify();
+        }
+    }
+
+    /**
+     * Creates a node and links it at end of queue.
+     * @param x the item
+     */
+    private void insert(Object x) {
+        last = last.next = new Node(x);
+    }
+
+    /**
+     * Removes a node from head of queue,
+     * @return the node
+     */
+    private Object extract() {
+        Node first = head.next;
+        head = first;
+        Object x = first.item;
+        first.item = null;
+        return x;
+    }
+
+
+    /**
+     * Creates a <tt>LinkedBlockingQueue</tt> with a capacity of
+     * {@link Integer#MAX_VALUE}.
+     */
+    public LinkedBlockingQueue() {
+        this(Integer.MAX_VALUE);
+    }
+
+    /**
+     * Creates a <tt>LinkedBlockingQueue</tt> with the given (fixed) capacity.
+     *
+     * @param capacity the capacity of this queue
+     * @throws IllegalArgumentException if <tt>capacity</tt> is not greater
+     *         than zero
+     */
+    public LinkedBlockingQueue(int capacity) {
+        if (capacity <= 0) throw new IllegalArgumentException();
+        this.capacity = capacity;
+        last = head = new Node(null);
+    }
+
+    /**
+     * Creates a <tt>LinkedBlockingQueue</tt> with a capacity of
+     * {@link Integer#MAX_VALUE}, initially containing the elements of the
+     * given collection,
+     * added in traversal order of the collection's iterator.
+     *
+     * @param c the collection of elements to initially contain
+     * @throws NullPointerException if the specified collection or any
+     *         of its elements are null
+     */
+    public LinkedBlockingQueue(Collection c) {
+        this(Integer.MAX_VALUE);
+        for (Iterator itr = c.iterator(); itr.hasNext();) {
+            Object e = itr.next();
+            add(e);
+        }
+    }
+
+
+    // this doc comment is overridden to remove the reference to collections
+    // greater in size than Integer.MAX_VALUE
+    /**
+     * Returns the number of elements in this queue.
+     *
+     * @return the number of elements in this queue
+     */
+    public int size() {
+        return count;
+    }
+
+    // this doc comment is a modified copy of the inherited doc comment,
+    // without the reference to unlimited queues.
+    /**
+     * Returns the number of additional elements that this queue can ideally
+     * (in the absence of memory or resource constraints) accept without
+     * blocking. This is always equal to the initial capacity of this queue
+     * less the current <tt>size</tt> of this queue.
+     *
+     * <p>Note that you <em>cannot</em> always tell if an attempt to insert
+     * an element will succeed by inspecting <tt>remainingCapacity</tt>
+     * because it may be the case that another thread is about to
+     * insert or remove an element.
+     */
+    public int remainingCapacity() {
+        return capacity - count;
+    }
+
+    /**
+     * Inserts the specified element at the tail of this queue, waiting if
+     * necessary for space to become available.
+     *
+     * @throws InterruptedException {@inheritDoc}
+     * @throws NullPointerException {@inheritDoc}
+     */
+    public void put(Object e) throws InterruptedException {
+        if (e == null) throw new NullPointerException();
+        // Note: convention in all put/take/etc is to preset
+        // local var holding count  negative to indicate failure unless set.
+        int c = -1;
+        synchronized (putLock) {
+            /*
+             * Note that count is used in wait guard even though it is
+             * not protected by lock. This works because count can
+             * only decrease at this point (all other puts are shut
+             * out by lock), and we (or some other waiting put) are
+             * signalled if it ever changes from
+             * capacity. Similarly for all other uses of count in
+             * other wait guards.
+             */
+            try {
+                while (count == capacity)
+                    putLock.wait();
+            } catch (InterruptedException ie) {
+                putLock.notify(); // propagate to a non-interrupted thread
+                throw ie;
+            }
+            insert(e);
+            synchronized (this) { c = count++; }
+            if (c + 1 < capacity)
+                putLock.notify();
+        }
+
+        if (c == 0)
+            signalNotEmpty();
+    }
+
+    /**
+     * Inserts the specified element at the tail of this queue, waiting if
+     * necessary up to the specified wait time for space to become available.
+     *
+     * @return <tt>true</tt> if successful, or <tt>false</tt> if
+     *         the specified waiting time elapses before space is available.
+     * @throws InterruptedException {@inheritDoc}
+     * @throws NullPointerException {@inheritDoc}
+     */
+    public boolean offer(Object e, long timeout, TimeUnit unit)
+        throws InterruptedException {
+
+        if (e == null) throw new NullPointerException();
+        long nanos = unit.toNanos(timeout);
+        int c = -1;
+        synchronized (putLock) {
+            long deadline = Utils.nanoTime() + nanos;
+            for (;;) {
+                if (count < capacity) {
+                    insert(e);
+                    synchronized (this) { c = count++; }
+                    if (c + 1 < capacity)
+                        putLock.notify();
+                    break;
+                }
+                if (nanos <= 0)
+                    return false;
+                try {
+                    TimeUnit.NANOSECONDS.timedWait(putLock, nanos);
+                    nanos = deadline - Utils.nanoTime();
+                } catch (InterruptedException ie) {
+                    putLock.notify(); // propagate to a non-interrupted thread
+                    throw ie;
+                }
+            }
+        }
+        if (c == 0)
+            signalNotEmpty();
+        return true;
+    }
+
+    /**
+     * Inserts the specified element at the tail of this queue if it is
+     * possible to do so immediately without exceeding the queue's capacity,
+     * returning <tt>true</tt> upon success and <tt>false</tt> if this queue
+     * is full.
+     * When using a capacity-restricted queue, this method is generally
+     * preferable to method {@link BlockingQueue#add add}, which can fail to
+     * insert an element only by throwing an exception.
+     *
+     * @throws NullPointerException if the specified element is null
+     */
+    public boolean offer(Object e) {
+        if (e == null) throw new NullPointerException();
+        if (count == capacity)
+            return false;
+        int c = -1;
+        synchronized (putLock) {
+            if (count < capacity) {
+                insert(e);
+                synchronized (this) { c = count++; }
+                if (c + 1 < capacity)
+                    putLock.notify();
+            }
+        }
+        if (c == 0)
+            signalNotEmpty();
+        return c >= 0;
+    }
+
+
+    public Object take() throws InterruptedException {
+        Object x;
+        int c = -1;
+        synchronized (takeLock) {
+            try {
+                while (count == 0)
+                    takeLock.wait();
+            } catch (InterruptedException ie) {
+                takeLock.notify(); // propagate to a non-interrupted thread
+                throw ie;
+            }
+
+            x = extract();
+            synchronized (this) { c = count--; }
+            if (c > 1)
+                takeLock.notify();
+        }
+        if (c == capacity)
+            signalNotFull();
+        return x;
+    }
+
+    public Object poll(long timeout, TimeUnit unit) throws InterruptedException {
+        Object x = null;
+        int c = -1;
+        long nanos = unit.toNanos(timeout);
+        synchronized (takeLock) {
+            long deadline = Utils.nanoTime() + nanos;
+            for (;;) {
+                if (count > 0) {
+                    x = extract();
+                    synchronized (this) { c = count--; }
+                    if (c > 1)
+                        takeLock.notify();
+                    break;
+                }
+                if (nanos <= 0)
+                    return null;
+                try {
+                    TimeUnit.NANOSECONDS.timedWait(takeLock, nanos);
+                    nanos = deadline - Utils.nanoTime();
+                } catch (InterruptedException ie) {
+                    takeLock.notify(); // propagate to a non-interrupted thread
+                    throw ie;
+                }
+            }
+        }
+        if (c == capacity)
+            signalNotFull();
+        return x;
+    }
+
+    public Object poll() {
+        if (count == 0)
+            return null;
+        Object x = null;
+        int c = -1;
+        synchronized (takeLock) {
+            if (count > 0) {
+                x = extract();
+                synchronized (this) { c = count--; }
+                if (c > 1)
+                    takeLock.notify();
+            }
+        }
+        if (c == capacity)
+            signalNotFull();
+        return x;
+    }
+
+
+    public Object peek() {
+        if (count == 0)
+            return null;
+        synchronized (takeLock) {
+            Node first = head.next;
+            if (first == null)
+                return null;
+            else
+                return first.item;
+        }
+    }
+
+    /**
+     * Removes a single instance of the specified element from this queue,
+     * if it is present.  More formally, removes an element <tt>e</tt> such
+     * that <tt>o.equals(e)</tt>, if this queue contains one or more such
+     * elements.
+     * Returns <tt>true</tt> if this queue contained the specified element
+     * (or equivalently, if this queue changed as a result of the call).
+     *
+     * @param o element to be removed from this queue, if present
+     * @return <tt>true</tt> if this queue changed as a result of the call
+     */
+    public boolean remove(Object o) {
+        if (o == null) return false;
+        boolean removed = false;
+        synchronized (putLock) {
+            synchronized (takeLock) {
+                Node trail = head;
+                Node p = head.next;
+                while (p != null) {
+                    if (o.equals(p.item)) {
+                        removed = true;
+                        break;
+                    }
+                    trail = p;
+                    p = p.next;
+                }
+                if (removed) {
+                    p.item = null;
+                    trail.next = p.next;
+                    if (last == p)
+                        last = trail;
+                    synchronized (this) {
+                        if (count-- == capacity)
+                            putLock.notifyAll();
+                    }
+                }
+            }
+        }
+        return removed;
+    }
+
+    /**
+     * Returns an array containing all of the elements in this queue, in
+     * proper sequence.
+     *
+     * <p>The returned array will be "safe" in that no references to it are
+     * maintained by this queue.  (In other words, this method must allocate
+     * a new array).  The caller is thus free to modify the returned array.
+     *
+     * <p>This method acts as bridge between array-based and collection-based
+     * APIs.
+     *
+     * @return an array containing all of the elements in this queue
+     */
+    public Object[] toArray() {
+        synchronized (putLock) {
+            synchronized (takeLock) {
+                int size = count;
+                Object[] a = new Object[size];
+                int k = 0;
+                for (Node p = head.next; p != null; p = p.next)
+                    a[k++] = p.item;
+                return a;
+            }
+        }
+    }
+
+    /**
+     * Returns an array containing all of the elements in this queue, in
+     * proper sequence; the runtime type of the returned array is that of
+     * the specified array.  If the queue fits in the specified array, it
+     * is returned therein.  Otherwise, a new array is allocated with the
+     * runtime type of the specified array and the size of this queue.
+     *
+     * <p>If this queue fits in the specified array with room to spare
+     * (i.e., the array has more elements than this queue), the element in
+     * the array immediately following the end of the queue is set to
+     * <tt>null</tt>.
+     *
+     * <p>Like the {@link #toArray()} method, this method acts as bridge between
+     * array-based and collection-based APIs.  Further, this method allows
+     * precise control over the runtime type of the output array, and may,
+     * under certain circumstances, be used to save allocation costs.
+     *
+     * <p>Suppose <tt>x</tt> is a queue known to contain only strings.
+     * The following code can be used to dump the queue into a newly
+     * allocated array of <tt>String</tt>:
+     *
+     * <pre>
+     *     String[] y = x.toArray(new String[0]);</pre>
+     *
+     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
+     * <tt>toArray()</tt>.
+     *
+     * @param a the array into which the elements of the queue are to
+     *          be stored, if it is big enough; otherwise, a new array of the
+     *          same runtime type is allocated for this purpose
+     * @return an array containing all of the elements in this queue
+     * @throws ArrayStoreException if the runtime type of the specified array
+     *         is not a supertype of the runtime type of every element in
+     *         this queue
+     * @throws NullPointerException if the specified array is null
+     */
+    public Object[] toArray(Object[] a) {
+        synchronized (putLock) {
+            synchronized (takeLock) {
+                int size = count;
+                if (a.length < size)
+                    a = (Object[])java.lang.reflect.Array.newInstance
+                        (a.getClass().getComponentType(), size);
+
+                int k = 0;
+                for (Node p = head.next; p != null; p = p.next)
+                    a[k++] = (Object)p.item;
+                if (a.length > k)
+                    a[k] = null;
+                return a;
+            }
+        }
+    }
+
+    public String toString() {
+        synchronized (putLock) {
+            synchronized (takeLock) {
+                return super.toString();
+            }
+        }
+    }
+
+    /**
+     * Atomically removes all of the elements from this queue.
+     * The queue will be empty after this call returns.
+     */
+    public void clear() {
+        synchronized (putLock) {
+            synchronized (takeLock) {
+                head.next = null;
+                //assert head.item == null;
+                last = head;
+                int c;
+                synchronized (this) {
+                    c = count;
+                    count = 0;
+                }
+                if (c == capacity)
+                    putLock.notifyAll();
+            }
+        }
+    }
+
+    /**
+     * @throws UnsupportedOperationException {@inheritDoc}
+     * @throws ClassCastException            {@inheritDoc}
+     * @throws NullPointerException          {@inheritDoc}
+     * @throws IllegalArgumentException      {@inheritDoc}
+     */
+    public int drainTo(Collection c) {
+        if (c == null)
+            throw new NullPointerException();
+        if (c == this)
+            throw new IllegalArgumentException();
+        Node first;
+        synchronized (putLock) {
+            synchronized (takeLock) {
+                first = head.next;
+                head.next = null;
+                //assert head.item == null;
+                last = head;
+                int cold;
+                synchronized (this) {
+                    cold = count;
+                    count = 0;
+                }
+                if (cold == capacity)
+                    putLock.notifyAll();
+            }
+        }
+        // Transfer the elements outside of locks
+        int n = 0;
+        for (Node p = first; p != null; p = p.next) {
+            c.add(p.item);
+            p.item = null;
+            ++n;
+        }
+        return n;
+    }
+
+    /**
+     * @throws UnsupportedOperationException {@inheritDoc}
+     * @throws ClassCastException            {@inheritDoc}
+     * @throws NullPointerException          {@inheritDoc}
+     * @throws IllegalArgumentException      {@inheritDoc}
+     */
+    public int drainTo(Collection c, int maxElements) {
+        if (c == null)
+            throw new NullPointerException();
+        if (c == this)
+            throw new IllegalArgumentException();
+        synchronized (putLock) {
+            synchronized (takeLock) {
+                int n = 0;
+                Node p = head.next;
+                while (p != null && n < maxElements) {
+                    c.add(p.item);
+                    p.item = null;
+                    p = p.next;
+                    ++n;
+                }
+                if (n != 0) {
+                    head.next = p;
+                    //assert head.item == null;
+                    if (p == null)
+                        last = head;
+                    int cold;
+                    synchronized (this) {
+                        cold = count;
+                        count -= n;
+                    }
+                    if (cold == capacity)
+                        putLock.notifyAll();
+                }
+                return n;
+            }
+        }
+    }
+
+    /**
+     * Returns an iterator over the elements in this queue in proper sequence.
+     * The returned <tt>Iterator</tt> is a "weakly consistent" iterator that
+     * will never throw {@link java.util.ConcurrentModificationException},
+     * and guarantees to traverse elements as they existed upon
+     * construction of the iterator, and may (but is not guaranteed to)
+     * reflect any modifications subsequent to construction.
+     *
+     * @return an iterator over the elements in this queue in proper sequence
+     */
+    public Iterator iterator() {
+      return new Itr();
+    }
+
+    private class Itr implements Iterator {
+        /*
+         * Basic weak-consistent iterator.  At all times hold the next
+         * item to hand out so that if hasNext() reports true, we will
+         * still have it to return even if lost race with a take etc.
+         */
+        private Node current;
+        private Node lastRet;
+        private Object currentElement;
+
+        Itr() {
+            synchronized (putLock) {
+                synchronized (takeLock) {
+                    current = head.next;
+                    if (current != null)
+                        currentElement = current.item;
+                }
+            }
+        }
+
+        public boolean hasNext() {
+            return current != null;
+        }
+
+        public Object next() {
+            synchronized (putLock) {
+                synchronized (takeLock) {
+                    if (current == null)
+                        throw new NoSuchElementException();
+                    Object x = currentElement;
+                    lastRet = current;
+                    current = current.next;
+                    if (current != null)
+                        currentElement = current.item;
+                    return x;
+                }
+            }
+        }
+
+        public void remove() {
+            if (lastRet == null)
+                throw new IllegalStateException();
+            synchronized (putLock) {
+                synchronized (takeLock) {
+                    Node node = lastRet;
+                    lastRet = null;
+                    Node trail = head;
+                    Node p = head.next;
+                    while (p != null && p != node) {
+                        trail = p;
+                        p = p.next;
+                    }
+                    if (p == node) {
+                        p.item = null;
+                        trail.next = p.next;
+                        if (last == p)
+                            last = trail;
+                        int c;
+                        synchronized (this) { c = count--; }
+                        if (c == capacity)
+                            putLock.notifyAll();
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Save the state to a stream (that is, serialize it).
+     *
+     * @serialData The capacity is emitted (int), followed by all of
+     * its elements (each an <tt>Object</tt>) in the proper order,
+     * followed by a null
+     * @param s the stream
+     */
+    private void writeObject(java.io.ObjectOutputStream s)
+        throws java.io.IOException {
+
+        synchronized (putLock) {
+            synchronized (takeLock) {
+                // Write out any hidden stuff, plus capacity
+                s.defaultWriteObject();
+
+                // Write out all elements in the proper order.
+                for (Node p = head.next; p != null; p = p.next)
+                    s.writeObject(p.item);
+
+                // Use trailing null as sentinel
+                s.writeObject(null);
+            }
+        }
+    }
+
+    /**
+     * Reconstitute this queue instance from a stream (that is,
+     * deserialize it).
+     * @param s the stream
+     */
+    private void readObject(java.io.ObjectInputStream s)
+        throws java.io.IOException, ClassNotFoundException {
+        // Read in capacity, and any hidden stuff
+        s.defaultReadObject();
+
+        synchronized (this) { count = 0; }
+        last = head = new Node(null);
+
+        // Read in all elements and place in queue
+        for (;;) {
+            Object item = (Object)s.readObject();
+            if (item == null)
+                break;
+            add(item);
+        }
+    }
+
+    private static class SerializableLock implements java.io.Serializable {
+        private final static long serialVersionUID = -8856990691138858668L;
+    }
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/NanoTimer.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/NanoTimer.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/NanoTimer.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,29 @@
+/*
+ * Written by Dawid Kurzyniec and released to the public domain, as explained
+ * at http://creativecommons.org/licenses/publicdomain
+ */
+package org.drools.util.concurrent.locks;
+
+/**
+ * Interface to specify custom implementation of precise timer.
+ *
+ * @author Dawid Kurzyniec
+ * @version 1.0
+ */
+public interface NanoTimer {
+    /**
+     * Returns the current value of the most precise available system timer,
+     * in nanoseconds. This method can only be used to measure elapsed time and
+     * is not related to any other notion of system or wall-clock time. The
+     * value returned represents nanoseconds since some fixed but arbitrary
+     * time (perhaps in the future, so values may be negative). This method
+     * provides nanosecond precision, but not necessarily nanosecond accuracy.
+     * No guarantees are made about how frequently values change. Differences
+     * in successive calls that span greater than approximately 292 years
+     * (263 nanoseconds) will not accurately compute elapsed time due to
+     * numerical overflow.
+     *
+     * @return The current value of the system timer, in nanoseconds.
+     */
+    long nanoTime();
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Queue.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Queue.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Queue.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,191 @@
+/*
+ * Written by Doug Lea with assistance from members of JCP JSR-166
+ * Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
+ */
+
+package org.drools.util.concurrent.locks;
+
+import java.util.Collection;
+
+/**
+ * A collection designed for holding elements prior to processing.
+ * Besides basic {@link java.util.Collection Collection} operations,
+ * queues provide additional insertion, extraction, and inspection
+ * operations.  Each of these methods exists in two forms: one throws
+ * an exception if the operation fails, the other returns a special
+ * value (either <tt>null</tt> or <tt>false</tt>, depending on the
+ * operation).  The latter form of the insert operation is designed
+ * specifically for use with capacity-restricted <tt>Queue</tt>
+ * implementations; in most implementations, insert operations cannot
+ * fail.
+ *
+ * <p>
+ * <table BORDER CELLPADDING=3 CELLSPACING=1>
+ *  <tr>
+ *    <td></td>
+ *    <td ALIGN=CENTER><em>Throws exception</em></td>
+ *    <td ALIGN=CENTER><em>Returns special value</em></td>
+ *  </tr>
+ *  <tr>
+ *    <td><b>Insert</b></td>
+ *    <td>{@link #add add(e)}</td>
+ *    <td>{@link #offer offer(e)}</td>
+ *  </tr>
+ *  <tr>
+ *    <td><b>Remove</b></td>
+ *    <td>{@link #remove remove()}</td>
+ *    <td>{@link #poll poll()}</td>
+ *  </tr>
+ *  <tr>
+ *    <td><b>Examine</b></td>
+ *    <td>{@link #element element()}</td>
+ *    <td>{@link #peek peek()}</td>
+ *  </tr>
+ * </table>
+ *
+ * <p>Queues typically, but do not necessarily, order elements in a
+ * FIFO (first-in-first-out) manner.  Among the exceptions are
+ * priority queues, which order elements according to a supplied
+ * comparator, or the elements' natural ordering, and LIFO queues (or
+ * stacks) which order the elements LIFO (last-in-first-out).
+ * Whatever the ordering used, the <em>head</em> of the queue is that
+ * element which would be removed by a call to {@link #remove() } or
+ * {@link #poll()}.  In a FIFO queue, all new elements are inserted at
+ * the <em> tail</em> of the queue. Other kinds of queues may use
+ * different placement rules.  Every <tt>Queue</tt> implementation
+ * must specify its ordering properties.
+ *
+ * <p>The {@link #offer offer} method inserts an element if possible,
+ * otherwise returning <tt>false</tt>.  This differs from the {@link
+ * java.util.Collection#add Collection.add} method, which can fail to
+ * add an element only by throwing an unchecked exception.  The
+ * <tt>offer</tt> method is designed for use when failure is a normal,
+ * rather than exceptional occurrence, for example, in fixed-capacity
+ * (or &quot;bounded&quot;) queues.
+ *
+ * <p>The {@link #remove()} and {@link #poll()} methods remove and
+ * return the head of the queue.
+ * Exactly which element is removed from the queue is a
+ * function of the queue's ordering policy, which differs from
+ * implementation to implementation. The <tt>remove()</tt> and
+ * <tt>poll()</tt> methods differ only in their behavior when the
+ * queue is empty: the <tt>remove()</tt> method throws an exception,
+ * while the <tt>poll()</tt> method returns <tt>null</tt>.
+ *
+ * <p>The {@link #element()} and {@link #peek()} methods return, but do
+ * not remove, the head of the queue.
+ *
+ * <p>The <tt>Queue</tt> interface does not define the <i>blocking queue
+ * methods</i>, which are common in concurrent programming.  These methods,
+ * which wait for elements to appear or for space to become available, are
+ * defined in the {@link edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue} interface, which
+ * extends this interface.
+ *
+ * <p><tt>Queue</tt> implementations generally do not allow insertion
+ * of <tt>null</tt> elements, although some implementations, such as
+ * {@link LinkedList}, do not prohibit insertion of <tt>null</tt>.
+ * Even in the implementations that permit it, <tt>null</tt> should
+ * not be inserted into a <tt>Queue</tt>, as <tt>null</tt> is also
+ * used as a special return value by the <tt>poll</tt> method to
+ * indicate that the queue contains no elements.
+ *
+ * <p><tt>Queue</tt> implementations generally do not define
+ * element-based versions of methods <tt>equals</tt> and
+ * <tt>hashCode</tt> but instead inherit the identity based versions
+ * from class <tt>Object</tt>, because element-based equality is not
+ * always well-defined for queues with the same elements but different
+ * ordering properties.
+ *
+ *
+ * <p>This interface is a member of the
+ * <a href="{@docRoot}/../technotes/guides/collections/index.html">
+ * Java Collections Framework</a>.
+ *
+ * @see java.util.Collection
+ * @see LinkedList
+ * @see PriorityQueue
+ * @see edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue
+ * @see edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue
+ * @see edu.emory.mathcs.backport.java.util.concurrent.ArrayBlockingQueue
+ * @see edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue
+ * @see edu.emory.mathcs.backport.java.util.concurrent.PriorityBlockingQueue
+ * @since 1.5
+ * @author Doug Lea
+ */
+public interface Queue extends Collection {
+    /**
+     * Inserts the specified element into this queue if it is possible to do so
+     * immediately without violating capacity restrictions, returning
+     * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
+     * if no space is currently available.
+     *
+     * @param e the element to add
+     * @return <tt>true</tt> (as specified by {@link Collection#add})
+     * @throws IllegalStateException if the element cannot be added at this
+     *         time due to capacity restrictions
+     * @throws ClassCastException if the class of the specified element
+     *         prevents it from being added to this queue
+     * @throws NullPointerException if the specified element is null and
+     *         this queue not permit null elements
+     * @throws IllegalArgumentException if some property of this element
+     *         prevents it from being added to this queue
+     */
+    boolean add(Object e);
+
+    /**
+     * Inserts the specified element into this queue if it is possible to do
+     * so immediately without violating capacity restrictions.
+     * When using a capacity-restricted queue, this method is generally
+     * preferable to {@link #add}, which can fail to insert an element only
+     * by throwing an exception.
+     *
+     * @param e the element to add
+     * @return <tt>true</tt> if the element was added to this queue, else
+     *         <tt>false</tt>
+     * @throws ClassCastException if the class of the specified element
+     *         prevents it from being added to this queue
+     * @throws NullPointerException if the specified element is null and
+     *         this queue does not permit null elements
+     * @throws IllegalArgumentException if some property of this element
+     *         prevents it from being added to this queue
+     */
+    boolean offer(Object e);
+
+    /**
+     * Retrieves and removes the head of this queue.  This method differs
+     * from {@link #poll poll} only in that it throws an exception if this
+     * queue is empty.
+     * is empty.
+     *
+     * @return the head of this queue
+     * @throws NoSuchElementException if this queue is empty
+     */
+    Object remove();
+
+    /**
+     * Retrieves and removes the head of this queue,
+     * or returns <tt>null</tt> if this queue is empty.
+     *
+     * @return the head of this queue, or <tt>null</tt> if this queue is empty
+     */
+    Object poll();
+
+    /**
+     * Retrieves, but does not remove, the head of this queue.  This method
+     * differs from {@link #peek peek} only in that it throws an exception
+     * if this queue is empty.
+     *
+     * @return the head of this queue
+     * @throws NoSuchElementException if this queue is empty
+     */
+    Object element();
+
+    /**
+     * Retrieves, but does not remove, the head of this queue,
+     * or returns <tt>null</tt> if this queue is empty.
+     *
+     * @return the head of this queue, or <tt>null</tt> if this queue is empty
+     */
+    Object peek();
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/TimeUnit.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/TimeUnit.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/TimeUnit.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,407 @@
+/*
+  * Written by Doug Lea with assistance from members of JCP JSR-166
+  * Expert Group and released to the public domain, as explained at
+  * http://creativecommons.org/licenses/publicdomain
+  */
+
+package org.drools.util.concurrent.locks;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectStreamException;
+
+/**
+  * A <tt>TimeUnit</tt> represents time durations at a given unit of
+  * granularity and provides utility methods to convert across units,
+  * and to perform timing and delay operations in these units.  A
+  * <tt>TimeUnit</tt> does not maintain time information, but only
+  * helps organize and use time representations that may be maintained
+  * separately across various contexts.  A nanosecond is defined as one
+  * thousandth of a microsecond, a microsecond as one thousandth of a
+  * millisecond, a millisecond as one thousandth of a second, a minute
+  * as sixty seconds, an hour as sixty minutes, and a day as twenty four
+  * hours.
+  *
+  * <p>A <tt>TimeUnit</tt> is mainly used to inform time-based methods
+  * how a given timing parameter should be interpreted. For example,
+  * the following code will timeout in 50 milliseconds if the {@link
+  * edu.emory.mathcs.backport.java.util.concurrent.locks.Lock lock} is not available:
+  *
+  * <pre>  Lock lock = ...;
+  *  if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ...
+  * </pre>
+  * while this code will timeout in 50 seconds:
+  * <pre>
+  *  Lock lock = ...;
+  *  if ( lock.tryLock(50L, TimeUnit.SECONDS) ) ...
+  * </pre>
+  *
+  * Note however, that there is no guarantee that a particular timeout
+  * implementation will be able to notice the passage of time at the
+  * same granularity as the given <tt>TimeUnit</tt>.
+  *
+  * @since 1.5
+  * @author Doug Lea
+  */
+public abstract class TimeUnit implements java.io.Serializable {
+
+    public static final TimeUnit NANOSECONDS = new TimeUnit(0, "NANOSECONDS") {
+        private final static long serialVersionUID = 535148490883208361L;
+        public long toNanos(long d)   { return d; }
+        public long toMicros(long d)  { return d/(C1/C0); }
+        public long toMillis(long d)  { return d/(C2/C0); }
+        public long toSeconds(long d) { return d/(C3/C0); }
+        public long toMinutes(long d) { return d/(C4/C0); }
+        public long toHours(long d)   { return d/(C5/C0); }
+        public long toDays(long d)    { return d/(C6/C0); }
+        public long convert(long d, TimeUnit u) { return u.toNanos(d); }
+        int excessNanos(long d, long m) { return (int)(d - (m*C2)); }
+    };
+    public static final TimeUnit MICROSECONDS = new TimeUnit(1, "MICROSECONDS") {
+        private final static long serialVersionUID = 2185906575929579108L;
+        public long toNanos(long d)   { return x(d, C1/C0, MAX/(C1/C0)); }
+        public long toMicros(long d)  { return d; }
+        public long toMillis(long d)  { return d/(C2/C1); }
+        public long toSeconds(long d) { return d/(C3/C1); }
+        public long toMinutes(long d) { return d/(C4/C1); }
+        public long toHours(long d)   { return d/(C5/C1); }
+        public long toDays(long d)    { return d/(C6/C1); }
+        public long convert(long d, TimeUnit u) { return u.toMicros(d); }
+        int excessNanos(long d, long m) { return (int)((d*C1) - (m*C2)); }
+    };
+    public static final TimeUnit MILLISECONDS = new TimeUnit(2, "MILLISECONDS") {
+        private final static long serialVersionUID = 9032047794123325184L;
+        public long toNanos(long d)   { return x(d, C2/C0, MAX/(C2/C0)); }
+        public long toMicros(long d)  { return x(d, C2/C1, MAX/(C2/C1)); }
+        public long toMillis(long d)  { return d; }
+        public long toSeconds(long d) { return d/(C3/C2); }
+        public long toMinutes(long d) { return d/(C4/C2); }
+        public long toHours(long d)   { return d/(C5/C2); }
+        public long toDays(long d)    { return d/(C6/C2); }
+        public long convert(long d, TimeUnit u) { return u.toMillis(d); }
+        int excessNanos(long d, long m) { return 0; }
+    };
+    public static final TimeUnit SECONDS = new TimeUnit(3, "SECONDS") {
+        private final static long serialVersionUID = 227755028449378390L;
+        public long toNanos(long d)   { return x(d, C3/C0, MAX/(C3/C0)); }
+        public long toMicros(long d)  { return x(d, C3/C1, MAX/(C3/C1)); }
+        public long toMillis(long d)  { return x(d, C3/C2, MAX/(C3/C2)); }
+        public long toSeconds(long d) { return d; }
+        public long toMinutes(long d) { return d/(C4/C3); }
+        public long toHours(long d)   { return d/(C5/C3); }
+        public long toDays(long d)    { return d/(C6/C3); }
+        public long convert(long d, TimeUnit u) { return u.toSeconds(d); }
+        int excessNanos(long d, long m) { return 0; }
+    };
+    public static final TimeUnit MINUTES = new TimeUnit(4, "MINUTES") {
+        private final static long serialVersionUID = 1827351566402609187L;
+        public long toNanos(long d)   { return x(d, C4/C0, MAX/(C4/C0)); }
+        public long toMicros(long d)  { return x(d, C4/C1, MAX/(C4/C1)); }
+        public long toMillis(long d)  { return x(d, C4/C2, MAX/(C4/C2)); }
+        public long toSeconds(long d) { return x(d, C4/C3, MAX/(C4/C3)); }
+        public long toMinutes(long d) { return d; }
+        public long toHours(long d)   { return d/(C5/C4); }
+        public long toDays(long d)    { return d/(C6/C4); }
+        public long convert(long d, TimeUnit u) { return u.toMinutes(d); }
+        int excessNanos(long d, long m) { return 0; }
+    };
+    public static final TimeUnit HOURS = new TimeUnit(5, "HOURS") {
+        private final static long serialVersionUID = -6438436134732089810L;
+        public long toNanos(long d)   { return x(d, C5/C0, MAX/(C5/C0)); }
+        public long toMicros(long d)  { return x(d, C5/C1, MAX/(C5/C1)); }
+        public long toMillis(long d)  { return x(d, C5/C2, MAX/(C5/C2)); }
+        public long toSeconds(long d) { return x(d, C5/C3, MAX/(C5/C3)); }
+        public long toMinutes(long d) { return x(d, C5/C4, MAX/(C5/C4)); }
+        public long toHours(long d)   { return d; }
+        public long toDays(long d)    { return d/(C6/C5); }
+        public long convert(long d, TimeUnit u) { return u.toHours(d); }
+        int excessNanos(long d, long m) { return 0; }
+    };
+    public static final TimeUnit DAYS = new TimeUnit(6, "DAYS") {
+        private final static long serialVersionUID = 567463171959674600L;
+        public long toNanos(long d)   { return x(d, C6/C0, MAX/(C6/C0)); }
+        public long toMicros(long d)  { return x(d, C6/C1, MAX/(C6/C1)); }
+        public long toMillis(long d)  { return x(d, C6/C2, MAX/(C6/C2)); }
+        public long toSeconds(long d) { return x(d, C6/C3, MAX/(C6/C3)); }
+        public long toMinutes(long d) { return x(d, C6/C4, MAX/(C6/C4)); }
+        public long toHours(long d)   { return x(d, C6/C5, MAX/(C6/C5)); }
+        public long toDays(long d)    { return d; }
+        public long convert(long d, TimeUnit u) { return u.toDays(d); }
+        int excessNanos(long d, long m) { return 0; }
+    };
+
+    private static final TimeUnit[] values = new TimeUnit[]
+        { NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS };
+
+    public static TimeUnit[] values() {
+        return (TimeUnit[])values.clone();
+    }
+
+    /**
+     * Returns the enum constant of this type with the specified name. The
+     * string must match <em>exactly</em> an identifier used to declare an
+     * enum constant in this type. (Extraneous whitespace characters are not
+     * permitted.)
+     *
+     * @param name the name of the enum constant to be returned
+     * @return the enum constant with the specified name
+     * @throws IllegalArgumentException
+     *         if this enum type has no constant with the specified name
+     */
+    public static TimeUnit valueOf(String name) {
+        for (int i = 0; i < values.length; i++) {
+            if (values[i].name.equals(name)) {
+                return values[i];
+            }
+        }
+        throw new IllegalArgumentException("No enum const TimeUnit." + name);
+    }
+
+    /**
+     * The ordinal of this unit. This is useful both for {@link #ordinal()}
+     * and to maintain serialization consistence with earlier versions.
+     */
+    private final int index;
+
+    /** name of this unit */
+    private final String name;
+
+    /** Internal constructor */
+    TimeUnit(int index, String name) {
+        this.index = index;
+        this.name = name;
+    }
+
+    // Handy constants for conversion methods
+    static final long C0 = 1;
+    static final long C1 = C0 * 1000;
+    static final long C2 = C1 * 1000;
+    static final long C3 = C2 * 1000;
+    static final long C4 = C3 * 60;
+    static final long C5 = C4 * 60;
+    static final long C6 = C5 * 24;
+
+    static final long MAX = Long.MAX_VALUE;
+
+    /**
+     * Scale d by m, checking for overflow.
+     * This has a short name to make above code more readable.
+     */
+    static long x(long d, long m, long over) {
+        if (d >  over) return Long.MAX_VALUE;
+        if (d < -over) return Long.MIN_VALUE;
+        return d * m;
+    }
+
+    /**
+     * Convert the given time duration in the given unit to this
+     * unit.  Conversions from finer to coarser granularities
+     * truncate, so lose precision. For example converting
+     * <tt>999</tt> milliseconds to seconds results in
+     * <tt>0</tt>. Conversions from coarser to finer granularities
+     * with arguments that would numerically overflow saturate to
+     * <tt>Long.MIN_VALUE</tt> if negative or <tt>Long.MAX_VALUE</tt>
+     * if positive.
+     *
+     * <p>For example, to convert 10 minutes to milliseconds, use:
+     * <tt>TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)</tt>
+     *
+     * @param sourceDuration the time duration in the given <tt>sourceUnit</tt>
+     * @param sourceUnit the unit of the <tt>sourceDuration</tt> argument
+     * @return the converted duration in this unit,
+     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
+     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
+     */
+    public abstract long convert(long sourceDuration, TimeUnit sourceUnit);
+
+    /**
+     * Equivalent to <tt>NANOSECONDS.convert(duration, this)</tt>.
+     * @param duration the duration
+     * @return the converted duration,
+     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
+     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
+     * @see #convert
+     */
+    public abstract long toNanos(long duration);
+
+    /**
+     * Equivalent to <tt>MICROSECONDS.convert(duration, this)</tt>.
+     * @param duration the duration
+     * @return the converted duration,
+     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
+     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
+     * @see #convert
+     */
+    public abstract long toMicros(long duration);
+
+    /**
+     * Equivalent to <tt>MILLISECONDS.convert(duration, this)</tt>.
+     * @param duration the duration
+     * @return the converted duration,
+     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
+     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
+     * @see #convert
+     */
+    public abstract long toMillis(long duration);
+
+    /**
+     * Equivalent to <tt>SECONDS.convert(duration, this)</tt>.
+     * @param duration the duration
+     * @return the converted duration,
+     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
+     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
+     * @see #convert
+     */
+    public abstract long toSeconds(long duration);
+
+    /**
+     * Equivalent to <tt>MINUTES.convert(duration, this)</tt>.
+     * @param duration the duration
+     * @return the converted duration,
+     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
+     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
+     * @see #convert
+     * @since 1.6
+     */
+    public abstract long toMinutes(long duration);
+
+    /**
+     * Equivalent to <tt>HOURS.convert(duration, this)</tt>.
+     * @param duration the duration
+     * @return the converted duration,
+     * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
+     * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
+     * @see #convert
+     * @since 1.6
+     */
+    public abstract long toHours(long duration);
+
+    /**
+     * Equivalent to <tt>DAYS.convert(duration, this)</tt>.
+     * @param duration the duration
+     * @return the converted duration
+     * @see #convert
+     * @since 1.6
+     */
+    public abstract long toDays(long duration);
+
+    /**
+     * Utility to compute the excess-nanosecond argument to wait,
+     * sleep, join.
+     * @param d the duration
+     * @param m the number of milliseconds
+     * @return the number of nanoseconds
+     */
+    abstract int excessNanos(long d, long m);
+
+    /**
+     * Returns the name of this enum constant, exactly as declared in its enum
+     * declaration. <strong>Most programmers should use the
+     * {@link #toString()} method in preference to this one, as the toString
+     * method may return a more user-friendly name.</strong> This method is
+     * designed primarily for use in specialized situations where correctness
+     * depends on getting the exact name, which will not vary from release to
+     * release.
+     *
+     * @return the name of this enum constant
+     */
+    public String name() {
+        return name;
+    }
+
+    /**
+     * Returns the ordinal of this enumeration constant (its position in its
+     * enum declaration, where the initial constant is assigned an ordinal of
+     * zero). Most programmers will have no use for this method. It is
+     * designed for use by sophisticated enum-based data structures, such as
+     * <code>EnumSet</code> and <code>EnumMap</code>.
+     *
+     * @return the ordinal of this enumeration constant
+     */
+    public int ordinal() {
+        return index;
+    }
+
+    /*
+     * Guarantees that deserialized objects will be referentially equal to the
+     * standard enumeration objects.
+     */
+    protected Object readResolve() throws ObjectStreamException {
+        try {
+            return valueOf(name);
+        } catch (IllegalArgumentException e) {
+            throw new InvalidObjectException(name
+                    + " is not a valid enum for TimeUnit");
+        }
+    }
+
+    /**
+     * Performs a timed <tt>Object.wait</tt> using this time unit.
+     * This is a convenience method that converts timeout arguments
+     * into the form required by the <tt>Object.wait</tt> method.
+     *
+     * <p>For example, you could implement a blocking <tt>poll</tt>
+     * method (see {@link BlockingQueue#poll BlockingQueue.poll})
+     * using:
+     *
+     * <pre>  public synchronized  Object poll(long timeout, TimeUnit unit) throws InterruptedException {
+     *    while (empty) {
+     *      unit.timedWait(this, timeout);
+     *      ...
+     *    }
+     *  }</pre>
+     *
+     * @param obj the object to wait on
+     * @param timeout the maximum time to wait. If less than
+     * or equal to zero, do not wait at all.
+     * @throws InterruptedException if interrupted while waiting.
+     * @see java.lang.Object#wait(long, int)
+     */
+    public void timedWait(Object obj, long timeout)
+        throws InterruptedException {
+        if (timeout > 0) {
+            long ms = toMillis(timeout);
+            int ns = excessNanos(timeout, ms);
+            obj.wait(ms, ns);
+        }
+    }
+
+    /**
+     * Performs a timed <tt>Thread.join</tt> using this time unit.
+     * This is a convenience method that converts time arguments into the
+     * form required by the <tt>Thread.join</tt> method.
+     * @param thread the thread to wait for
+     * @param timeout the maximum time to wait. If less than
+     * or equal to zero, do not wait at all.
+     * @throws InterruptedException if interrupted while waiting.
+     * @see java.lang.Thread#join(long, int)
+     */
+    public void timedJoin(Thread thread, long timeout)
+        throws InterruptedException {
+        if (timeout > 0) {
+            long ms = toMillis(timeout);
+            int ns = excessNanos(timeout, ms);
+            thread.join(ms, ns);
+        }
+    }
+
+    /**
+     * Performs a <tt>Thread.sleep</tt> using this unit.
+     * This is a convenience method that converts time arguments into the
+     * form required by the <tt>Thread.sleep</tt> method.
+     * @param timeout the maximum time to sleep. If less than
+     * or equal to zero, do not sleep at all.
+     * @throws InterruptedException if interrupted while sleeping.
+     * @see java.lang.Thread#sleep
+     */
+    public void sleep(long timeout) throws InterruptedException {
+        if (timeout > 0) {
+            long ms = toMillis(timeout);
+            int ns = excessNanos(timeout, ms);
+            Thread.sleep(ms, ns);
+        }
+    }
+
+    public String toString() {
+        return name;
+    }
+}

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Utils.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Utils.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/concurrent/locks/Utils.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,242 @@
+/*
+ * Written by Dawid Kurzyniec, based on code written by Doug Lea with assistance
+ * from members of JCP JSR-166 Expert Group. Released to the public domain,
+ * as explained at http://creativecommons.org/licenses/publicdomain.
+ *
+ * Thanks to Craig Mattocks for suggesting to use <code>sun.misc.Perf</code>.
+ */
+
+package org.drools.util.concurrent.locks;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.lang.reflect.Array;
+import java.util.Iterator;
+import java.util.Collection;
+
+/**
+ * <p>
+ * This class groups together the functionality of java.util.concurrent that
+ * cannot be fully and reliably implemented in backport, but for which some
+ * form of emulation is possible.
+ * <p>
+ * Currently, this class contains methods related to nanosecond-precision
+ * timing, particularly via the {@link #nanoTime} method. To measure time
+ * accurately, this method by default uses <code>java.sun.Perf</code> on
+ * JDK1.4.2 and it falls back to <code>System.currentTimeMillis</code>
+ * on earlier JDKs.
+ *
+ * @author Dawid Kurzyniec
+ * @version 1.0
+ */
+public final class Utils {
+
+    private final static NanoTimer nanoTimer;
+    private final static String providerProp =
+        "edu.emory.mathcs.backport.java.util.concurrent.NanoTimerProvider";
+
+    static {
+        NanoTimer timer = null;
+        try {
+            String nanoTimerClassName = (String)
+                AccessController.doPrivileged(new PrivilegedAction() {
+                    public Object run() {
+                        return System.getProperty(providerProp);
+                    }
+                });
+            if (nanoTimerClassName != null) {
+                Class cls = Class.forName(nanoTimerClassName);
+                timer = (NanoTimer) cls.newInstance();
+            }
+        }
+        catch (Exception e) {
+            System.err.println("WARNING: unable to load the system-property-defined " +
+                               "nanotime provider; switching to the default");
+            e.printStackTrace();
+        }
+
+        if (timer == null) {
+            try {
+                timer = new SunPerfProvider();
+            }
+            catch (Throwable e) {}
+        }
+
+        if (timer == null) {
+            timer = new MillisProvider();
+        }
+
+        nanoTimer = timer;
+    }
+
+    private Utils() {}
+
+    /**
+     * Returns the current value of the most precise available system timer,
+     * in nanoseconds. This method can only be used to measure elapsed time and
+     * is not related to any other notion of system or wall-clock time. The
+     * value returned represents nanoseconds since some fixed but arbitrary
+     * time (perhaps in the future, so values may be negative). This method
+     * provides nanosecond precision, but not necessarily nanosecond accuracy.
+     * No guarantees are made about how frequently values change. Differences
+     * in successive calls that span greater than approximately 292 years
+     * (2^63 nanoseconds) will not accurately compute elapsed time due to
+     * numerical overflow.
+     * <p>
+     * <em>Implementation note:</em>By default, this method uses
+     * <code>sun.misc.Perf</code> on Java 1.4.2, and falls back to
+     * System.currentTimeMillis() emulation on earlier JDKs. Custom
+     * timer can be provided via the system property
+     * <code>edu.emory.mathcs.backport.java.util.concurrent.NanoTimerProvider</code>.
+     * The value of the property should name a class implementing
+     * {@link NanoTimer} interface.
+     * <p>
+     * Note: on JDK 1.4.2, <code>sun.misc.Perf</code> timer seems to have
+     * resolution of the order of 1 microsecond, measured on Linux.
+     *
+     * @return The current value of the system timer, in nanoseconds.
+     */
+    public static long nanoTime() {
+        return nanoTimer.nanoTime();
+    }
+
+
+    private static final class SunPerfProvider implements NanoTimer {
+        final sun.misc.Perf perf;
+        final long multiplier, divisor;
+        SunPerfProvider() {
+            perf = (sun.misc.Perf)
+                AccessController.doPrivileged(new PrivilegedAction() {
+                    public Object run() {
+                        return sun.misc.Perf.getPerf();
+                    }
+                });
+            // trying to avoid BOTH overflow and rounding errors
+            long numerator = 1000000000;
+            long denominator = perf.highResFrequency();
+            long gcd = gcd(numerator, denominator);
+            this.multiplier = numerator / gcd;
+            this.divisor = denominator / gcd;
+        }
+        public long nanoTime() {
+            long ctr = perf.highResCounter();
+
+            // anything less sophisticated suffers either from rounding errors
+            // (FP arithmetics, backport v1.0) or overflow, when gcd is small
+            // (a bug in backport v1.0_01 reported by Ramesh Nethi)
+
+            return ((ctr / divisor) * multiplier) +
+                    (ctr % divisor) * multiplier / divisor;
+
+            // even the above can theoretically cause problems if your JVM is
+            // running for sufficiently long time, but "sufficiently" means 292
+            // years (worst case), or 30,000 years (common case).
+
+            // Details: when the ticks ctr overflows, there is no way to avoid
+            // discontinuity in computed nanos, even in infinite arithmetics,
+            // unless we count number of overflows that the ctr went through
+            // since the JVM started. This follows from the fact that
+            // (2^64*multiplier/divisor) mod (2^64) > 0 in general case.
+            // Theoretically we could find out the number of overflows by
+            // checking System.currentTimeMillis(), but this is unreliable
+            // since the system time can unpredictably change during the JVM
+            // lifetime.
+            // The time to overflow is 2^63 / ticks frequency. With current
+            // ticks frequencies of several MHz, it gives about 30,000 years
+            // before the problem happens. If ticks frequency reaches 1 GHz, the
+            // time to overflow is 292 years. It is unlikely that the frequency
+            // ever exceeds 1 GHz. We could double the time to overflow
+            // (to 2^64 / frequency) by using unsigned arithmetics, e.g. by
+            // adding the following correction whenever the ticks is negative:
+            //      -2*((Long.MIN_VALUE / divisor) * multiplier +
+            //          (Long.MIN_VALUE % divisor) * multiplier / divisor)
+            // But, with the worst case of as much as 292 years, it does not
+            // seem justified.
+        }
+    }
+
+    private static final class MillisProvider implements NanoTimer {
+        MillisProvider() {}
+        public long nanoTime() {
+            return System.currentTimeMillis() * 1000000;
+        }
+    }
+
+    private static long gcd(long a, long b) {
+        long r;
+        while (b>0) { r = a % b; a = b; b = r; }
+        return a;
+    }
+
+
+    public static Object[] collectionToArray(Collection c) {
+        // guess the array size; expect to possibly be different
+        int len = c.size();
+        Object[] arr = new Object[len];
+        Iterator itr = c.iterator();
+        int idx = 0;
+        while (true) {
+            while (idx < len && itr.hasNext()) {
+                arr[idx++] = itr.next();
+            }
+            if (!itr.hasNext()) {
+                if (idx == len) return arr;
+                // otherwise have to trim
+                return Arrays.copyOf(arr, idx, Object[].class);
+            }
+            // otherwise, have to grow
+            int newcap = ((arr.length/2)+1)*3;
+            if (newcap < arr.length) {
+                // overflow
+                if (arr.length < Integer.MAX_VALUE) {
+                    newcap = Integer.MAX_VALUE;
+                }
+                else {
+                    throw new OutOfMemoryError("required array size too large");
+                }
+            }
+            arr = Arrays.copyOf(arr, newcap, Object[].class);
+            len = newcap;
+        }
+    }
+
+    public static Object[] collectionToArray(Collection c, Object[] a) {
+        Class aType = a.getClass();
+        // guess the array size; expect to possibly be different
+        int len = c.size();
+        Object[] arr = (a.length >= len ? a :
+                        (Object[])Array.newInstance(aType.getComponentType(), len));
+        Iterator itr = c.iterator();
+        int idx = 0;
+        while (true) {
+            while (idx < len && itr.hasNext()) {
+                arr[idx++] = itr.next();
+            }
+            if (!itr.hasNext()) {
+                if (idx == len) return arr;
+                if (arr == a) {
+                    // orig array -> null terminate
+                    a[idx] = null;
+                    return a;
+                }
+                else {
+                    // have to trim
+                    return Arrays.copyOf(arr, idx, aType);
+                }
+            }
+            // otherwise, have to grow
+            int newcap = ((arr.length/2)+1)*3;
+            if (newcap < arr.length) {
+                // overflow
+                if (arr.length < Integer.MAX_VALUE) {
+                    newcap = Integer.MAX_VALUE;
+                }
+                else {
+                    throw new OutOfMemoryError("required array size too large");
+                }
+            }
+            arr = Arrays.copyOf(arr, newcap, aType);
+            len = newcap;
+        }
+    }
+}

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/DroolsTestCase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/DroolsTestCase.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/DroolsTestCase.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -43,6 +43,16 @@
                       len,
                       collection.size() );
     }
+    
+    public void assertNotContains (final Object obj,
+                                   final Object[] array) {
+        try {
+            assertContains( obj, array); 
+            fail( Arrays.asList( array ) + " contains " + obj );    
+        } catch(Throwable t) {
+            // do nothing as this is assertion is ok
+        }
+    }
 
     public void assertContains(final Object obj,
                                final Object[] array) {
@@ -55,6 +65,16 @@
         fail( Arrays.asList( array ) + " does not contain " + obj );
     }
 
+    public void assertNotContains (final Object obj,
+                                   final Collection collection) {
+        try {
+            assertContains( obj, collection); 
+            fail( collection + " does not contain " + obj );    
+        } catch(Throwable t) {
+            // do nothing as this is assertion is ok
+        }
+    }    
+    
     public void assertContains(final Object obj,
                                final Collection collection) {
         assertTrue( collection + " does not contain " + obj,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/DelegateJavaFactHandlerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/DelegateJavaFactHandlerTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/DelegateJavaFactHandlerTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -15,7 +15,7 @@
         final Field field = handler.getClass().getDeclaredField( "entries" );
         field.setAccessible( true );
 
-        final WorkingMemory wm1 = RuleBaseFactory.newRuleBase().newWorkingMemory();
+        final WorkingMemory wm1 = RuleBaseFactory.newRuleBase().newStatefulSession();
         handler.register( wm1 );
 
         JavaFactRegistryEntry[] entries = (JavaFactRegistryEntry[]) field.get( handler );
@@ -29,7 +29,7 @@
         assertSame( wm1,
                     handler.listWorkingMemories()[0].getWorkingMemory() );
 
-        final WorkingMemory wm2 = RuleBaseFactory.newRuleBase().newWorkingMemory();
+        final WorkingMemory wm2 = RuleBaseFactory.newRuleBase().newStatefulSession();
         assertFalse( handler.isRegistered( wm2 ) );
 
         handler.unregister( wm1 );
@@ -44,8 +44,8 @@
         final Field field = handler.getClass().getDeclaredField( "entries" );
         field.setAccessible( true );
 
-        final WorkingMemory wm1 = RuleBaseFactory.newRuleBase().newWorkingMemory();
-        final WorkingMemory wm2 = RuleBaseFactory.newRuleBase().newWorkingMemory();
+        final WorkingMemory wm1 = RuleBaseFactory.newRuleBase().newStatefulSession();
+        final WorkingMemory wm2 = RuleBaseFactory.newRuleBase().newStatefulSession();
         handler.register( wm1 );
         handler.register( wm2 );
 
@@ -96,9 +96,9 @@
         final Field field = handler.getClass().getDeclaredField( "entries" );
         field.setAccessible( true );
 
-        final WorkingMemory wm1 = RuleBaseFactory.newRuleBase().newWorkingMemory();
-        final WorkingMemory wm2 = RuleBaseFactory.newRuleBase().newWorkingMemory();
-        final WorkingMemory wm3 = RuleBaseFactory.newRuleBase().newWorkingMemory();
+        final WorkingMemory wm1 = RuleBaseFactory.newRuleBase().newStatefulSession();
+        final WorkingMemory wm2 = RuleBaseFactory.newRuleBase().newStatefulSession();
+        final WorkingMemory wm3 = RuleBaseFactory.newRuleBase().newStatefulSession();
         handler.register( wm1 );
         handler.register( wm2 );
         handler.register( wm3 );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -82,7 +82,7 @@
         rb.addPackage( pkg );
 
         // create a new working memory and add an AgendaEventListener
-        final WorkingMemory wm = rb.newWorkingMemory();
+        final WorkingMemory wm = rb.newStatefulSession();
         final List agendaList = new ArrayList();
         final AgendaEventListener agendaEventListener = new AgendaEventListener() {
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -38,7 +38,7 @@
 
     public void testWorkingMemoryEventListener() {
         final RuleBase rb = RuleBaseFactory.newRuleBase();
-        final WorkingMemory wm = rb.newWorkingMemory();
+        final WorkingMemory wm = rb.newStatefulSession();
 
         final List wmList = new ArrayList();
         final WorkingMemoryEventListener workingMemoryListener = new WorkingMemoryEventListener() {

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -32,7 +32,7 @@
 
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase( RuleBase.RETEOO );
         ruleBase.addPackage( this.pkg );
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final DefaultAgendaEventListener listener = new DefaultAgendaEventListener() {
             private int counter = 0;

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AddRemoveTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AddRemoveTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AddRemoveTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -37,7 +37,7 @@
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         // objectTypeNode.
     }

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-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -50,7 +50,7 @@
     public void testClearAgenda() {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Agenda agenda = workingMemory.getAgenda();
 
@@ -104,7 +104,7 @@
     public void testFilters() throws Exception {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
         final Rule rule = new Rule( "test-rule" );
@@ -196,7 +196,7 @@
     public void testFocusStack() throws ConsequenceException {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
@@ -421,7 +421,7 @@
     public void testAutoFocus() throws ConsequenceException {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
         // create the agendaGroup
@@ -498,7 +498,7 @@
     public void testAgendaGroupLockOnActive() {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
         // create the agendaGroup
@@ -552,7 +552,7 @@
     public void testActivationGroup() {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
@@ -738,7 +738,7 @@
     public void testRuleFlowGroup() {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
@@ -890,7 +890,7 @@
     public void testRuleFlowGroup1() {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
@@ -987,7 +987,7 @@
     public void testRuleFlowGroup2() {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
@@ -1086,7 +1086,7 @@
     public void testRuleFlowGroup3() {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
@@ -1174,7 +1174,7 @@
     public void testRuleFlowGroup4() {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
@@ -1279,7 +1279,7 @@
     public void testRuleFlowGroupLockOnActive() {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
         // create the agendaGroup

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CrossProductTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CrossProductTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CrossProductTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -85,7 +85,7 @@
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
         ruleBase.addPackage( this.pkg );
 
-        this.workingMemory = ruleBase.newWorkingMemory();
+        this.workingMemory = ruleBase.newStatefulSession();
         this.workingMemory.assertObject( "F1" );
         this.workingMemory.assertObject( "F2" );
         this.workingMemory.assertObject( "F3" );
@@ -104,7 +104,7 @@
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
         ruleBase.addPackage( this.pkg );
 
-        this.workingMemory = ruleBase.newWorkingMemory();
+        this.workingMemory = ruleBase.newStatefulSession();
         this.workingMemory.assertObject( "F1" );
         this.workingMemory.assertObject( "F2" );
         this.workingMemory.assertObject( "F3" );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -54,7 +54,7 @@
                                                             new MockTupleSource( 2 ),
                                                             rule1,
                                                             rule1.getLhs() );
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
@@ -155,7 +155,7 @@
                                                             rule1.getLhs() );
 
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Agenda agenda = workingMemory.getAgenda();
 
@@ -242,7 +242,7 @@
                                                             rule1,
                                                             rule1.getLhs() );
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Agenda agenda = workingMemory.getAgenda();
 
@@ -379,7 +379,7 @@
         conf.setLogicalOverride( RuleBaseConfiguration.LogicalOverride.PRESERVE );
 
         final RuleBase ruleBase = new ReteooRuleBase( conf );
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Agenda agenda = workingMemory.getAgenda();
 
@@ -466,7 +466,7 @@
                                                             rule1,
                                                             rule1.getLhs() );
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Consequence consequence = new Consequence() {
             /**
@@ -563,7 +563,7 @@
                                                             new MockTupleSource( 2 ),
                                                             rule1,
                                                             rule1.getLhs() );
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Agenda agenda = workingMemory.getAgenda();
 
@@ -691,7 +691,7 @@
                                                             rule1,
                                                             rule1.getLhs() );
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Agenda agenda = workingMemory.getAgenda();
 
@@ -790,7 +790,7 @@
                                                             rule1,
                                                             rule1.getLhs() );
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Agenda agenda = workingMemory.getAgenda();
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/OtherwiseTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/OtherwiseTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/OtherwiseTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -33,7 +33,7 @@
 
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         workingMemory.assertObject( new TestBean() );
         workingMemory.fireAllRules();
 
@@ -56,7 +56,7 @@
 
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         workingMemory.assertObject( new TestBean() );
         workingMemory.fireAllRules();
 
@@ -78,7 +78,7 @@
 
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         workingMemory.fireAllRules();
 
@@ -103,7 +103,7 @@
 
         ruleBase.addPackage( pkg );
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         workingMemory.fireAllRules();
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -12,7 +12,7 @@
     public void test1() {
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Rete rete = ruleBase.getRete();
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -119,7 +119,7 @@
             Assert.fail( "Should not throw any exception: " + e.getMessage() );
         }
 
-        final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         QueryResults results = workingMemory.getQueryResults( "query-1" );
 
         assertEquals( 0,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooRuleBaseTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooRuleBaseTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooRuleBaseTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -18,56 +18,36 @@
 
 import org.drools.DroolsTestCase;
 import org.drools.RuleBaseFactory;
+import org.drools.StatefulSession;
 import org.drools.WorkingMemory;
 
 public class ReteooRuleBaseTest extends DroolsTestCase {
     ReteooRuleBase ruleBase;
 
-    WorkingMemory  wm1;
-    WorkingMemory  wm2;
-    WorkingMemory  wm3;
-    WorkingMemory  wm4;
+    StatefulSession  wm1;
+    StatefulSession  wm2;
+    StatefulSession  wm3;
+    StatefulSession  wm4;
 
     public void setUp() {
         this.ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
 
-        this.wm1 = this.ruleBase.newWorkingMemory();
-        this.wm2 = this.ruleBase.newWorkingMemory();
-        this.wm3 = this.ruleBase.newWorkingMemory();
-        this.wm4 = this.ruleBase.newWorkingMemory();
+        this.wm1 = this.ruleBase.newStatefulSession();
+        this.wm2 = this.ruleBase.newStatefulSession();
+        this.wm3 = this.ruleBase.newStatefulSession();
+        this.wm4 = this.ruleBase.newStatefulSession();
     }
 
     public void testKeepReference() throws Exception {
         /* Make sure the RuleBase is referencing all 4 Working Memories */
         assertLength( 4,
-                      this.ruleBase.getWorkingMemories() );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm1 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm2 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm4 ) );
+                      this.ruleBase.getStatefulSessions() );
+        assertContains( this.wm1, this.ruleBase.getStatefulSessions() );
+        assertContains( this.wm2, this.ruleBase.getStatefulSessions() );
+        assertContains( this.wm3, this.ruleBase.getStatefulSessions() );
+        assertContains( this.wm4, this.ruleBase.getStatefulSessions() );
     }
-
-    public void testWeakReference() throws Exception {
-        /* nulling these two so the keys should get garbage collected */
-        this.wm2 = null;
-        this.wm4 = null;
-
-        /* Run GC */
-        System.gc();
-        Thread.sleep( 200 ); // Shouldn't need to sleep, but put it in anyway
-
-        /* Check we now only have two keys */
-        assertLength( 2,
-                      this.ruleBase.getWorkingMemories() );
-
-        /* Make sure the correct keys were removed */
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm1 ) );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm2 ) );
-        assertTrue( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm4 ) );
-
-    }
-
+    
     public void testDispose() throws Exception {
         /*
          * Now lets test the dispose method on the WorkingMemory itself. dispose
@@ -77,17 +57,17 @@
 
         /* Check only wm3 was removed */
         assertLength( 3,
-                      this.ruleBase.getWorkingMemories() );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( this.wm3 ) );
+                      this.ruleBase.getStatefulSessions() );
+        assertNotContains( this.wm3, this.ruleBase.getStatefulSessions() );
     }
 
     public void testNoKeepReference() throws Exception {
-        final WorkingMemory wm5 = this.ruleBase.newWorkingMemory( false );
-        final WorkingMemory wm6 = this.ruleBase.newWorkingMemory( false );
+        final WorkingMemory wm5 = this.ruleBase.newStatefulSession( false );
+        final WorkingMemory wm6 = this.ruleBase.newStatefulSession( false );
         assertLength( 4,
-                      this.ruleBase.getWorkingMemories() );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( wm5 ) );
-        assertFalse( this.ruleBase.getWorkingMemories().contains( wm6 ) );
+                      this.ruleBase.getStatefulSessions() );
+        assertNotContains( wm5, this.ruleBase.getStatefulSessions() );
+        assertNotContains( wm6, this.ruleBase.getStatefulSessions() );
     }
 
     public void testAddPackage() throws Exception {

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooWorkingMemoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooWorkingMemoryTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteooWorkingMemoryTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -17,7 +17,7 @@
      * @see JBRULES-356
      */
     public void testBasicWorkingMemoryActions() {
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) RuleBaseFactory.newRuleBase().newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) RuleBaseFactory.newRuleBase().newStatefulSession();
         final TruthMaintenanceSystem tms = workingMemory.getTruthMaintenanceSystem();
         final String string = "test";
         FactHandle fd = workingMemory.assertObject( string );
@@ -61,10 +61,10 @@
 
     public void testId() {
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
         assertEquals( 0,
                       workingMemory.getId() );
-        workingMemory = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
         assertEquals( 1,
                       workingMemory.getId() );
     }
@@ -83,7 +83,7 @@
 
         };
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
         workingMemory.setGlobalResolver( resolver );
         assertEquals( "value1",
                       workingMemory.getGlobal( "global1" ) );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -58,7 +58,7 @@
     public void testRuleFlowGroup() {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -40,7 +40,7 @@
     public void testScheduledActivation() throws Exception {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Rule rule = new Rule( "test-rule" );
         final RuleTerminalNode node = new RuleTerminalNode( 1,
@@ -102,7 +102,7 @@
     public void testDoLoopScheduledActivation() throws Exception {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
         final Agenda agenda = workingMemory.getAgenda();
 
         final Rule rule = new Rule( "test-rule" );
@@ -179,7 +179,7 @@
     public void testNoLoopScheduledActivation() throws Exception {
         final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newWorkingMemory();
+        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
         final Agenda agenda = workingMemory.getAgenda();
 
         final Rule rule = new Rule( "test-rule" );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -63,7 +63,7 @@
      */
     public void testLiteralConstraint() throws IntrospectionException {
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
 
         final ClassFieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
                                                                        "type" );
@@ -108,7 +108,7 @@
      */
     public void testPrimitiveLiteralConstraint() throws IntrospectionException {
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
 
         final ClassFieldExtractor extractor = new ClassFieldExtractor( Cheese.class,
                                                                        "price" );
@@ -154,7 +154,7 @@
      */
     public void testPredicateConstraint() throws IntrospectionException {
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
 
         final FieldExtractor priceExtractor = new ClassFieldExtractor( Cheese.class,
                                                                        "price" );
@@ -236,7 +236,7 @@
      */
     public void testReturnValueConstraint() throws IntrospectionException {
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newWorkingMemory();
+        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
 
         final FieldExtractor priceExtractor = new ClassFieldExtractor( Cheese.class,
                                                                        "price" );

Modified: labs/jbossrules/trunk/drools-decisiontables/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/.classpath	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-decisiontables/.classpath	2007-04-23 22:54:04 UTC (rev 11274)
@@ -5,18 +5,18 @@
   <classpathentry kind="src" path="src/test/resources" output="target/test-classes"/>
   <classpathentry kind="output" path="target/classes"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-  <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="var" path="M2_REPO/antlr/antlr/2.7.7/antlr-2.7.7.jar"/>
+  <classpathentry kind="src" path="/drools-core"/>
   <classpathentry kind="var" path="M2_REPO/antlr/stringtemplate/3.0/stringtemplate-3.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.5/janino-2.5.5.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/org/antlr/antlr/3.0b5/antlr-3.0b5.jar"/>
+  <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta15/mvel14-1.2beta15.jar"/>
+  <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="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta15/mvel14-1.2beta15.jar"/>
   <classpathentry kind="src" path="/drools-compiler"/>
-  <classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.7/antlr-2.7.7.jar"/>
+  <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
   <classpathentry kind="var" path="M2_REPO/jexcelapi/jxl/2.4.2/jxl-2.4.2.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/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
-  <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/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
+  <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.5/janino-2.5.5.jar"/>
 </classpath>
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-decisiontables/.project
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/.project	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-decisiontables/.project	2007-04-23 22:54:04 UTC (rev 11274)
@@ -2,8 +2,8 @@
   <name>drools-decisiontables</name>
   <comment>A rule production system</comment>
   <projects>
+    <project>drools-core</project>
     <project>drools-compiler</project>
-    <project>drools-core</project>
   </projects>
   <buildSpec>
     <buildCommand>

Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/DefaultTemplateRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/DefaultTemplateRuleBase.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/DefaultTemplateRuleBase.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -24,6 +24,8 @@
 
 import org.drools.RuleBase;
 import org.drools.RuleBaseFactory;
+import org.drools.StatefulSession;
+import org.drools.StatelessSession;
 import org.drools.WorkingMemory;
 import org.drools.compiler.PackageBuilder;
 import org.drools.decisiontable.model.Condition;
@@ -68,8 +70,8 @@
 	/* (non-Javadoc)
 	 * @see org.drools.decisiontable.parser.TemplateRuleBase#newWorkingMemory()
 	 */
-	public WorkingMemory newWorkingMemory() {
-		return ruleBase.newWorkingMemory();
+	public StatefulSession newStatefulSession() {
+		return ruleBase.newStatefulSession();
 	}
 	/**
 	 * 

Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/ExternalSheetListener.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/ExternalSheetListener.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/ExternalSheetListener.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -18,6 +18,8 @@
 
 import java.util.Properties;
 
+import org.drools.StatefulSession;
+import org.drools.StatelessSession;
 import org.drools.WorkingMemory;
 import org.drools.decisiontable.model.DRLOutput;
 
@@ -36,7 +38,7 @@
 
 	private Column[] columns;
 
-	private WorkingMemory wm;
+	private StatefulSession session;
 
 	private TemplateContainer templateContainer;
 
@@ -67,9 +69,9 @@
 		this.startCol = startCol - 1;
 		columns = tc.getColumns();
 		this.templateContainer = tc;
-		wm = ruleBase.newWorkingMemory();
+		session = ruleBase.newStatefulSession();
 		this.generator = generator;
-		wm.setGlobal("generator", generator);
+		session.setGlobal("generator", generator);
 	}
 
 	public Properties getProperties() {
@@ -82,10 +84,10 @@
 
 	public void finishSheet() {
 		if (currentRow != null) {
-			wm.assertObject(currentRow);
+			session.assertObject(currentRow);
 		}
-		wm.fireAllRules();
-		wm.dispose();
+		session.fireAllRules();
+		session.dispose();
 	}
 
 	public void newCell(int row, int column, String value, int mergedColStart) {
@@ -97,7 +99,7 @@
 			Column col = columns[column - startCol];
 			Cell cell = new Cell(currentRow, col, value);
 			currentRow.addCell(cell);
-			wm.assertObject(cell);
+			session.assertObject(cell);
 
 		}
 	}
@@ -109,7 +111,7 @@
 				tableFinished = true;
 			} else {
 				if (currentRow != null)
-					wm.assertObject(currentRow);
+					session.assertObject(currentRow);
 				currentRow = new Row(rowNumber);
 			}
 		}

Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/TemplateRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/TemplateRuleBase.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/TemplateRuleBase.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -15,10 +15,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import org.drools.WorkingMemory;
+import org.drools.StatefulSession;
 
 public interface TemplateRuleBase {
 
-	WorkingMemory newWorkingMemory();
+    StatefulSession newStatefulSession();
 
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/acme/insurance/launcher/PricingRuleLauncher.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/acme/insurance/launcher/PricingRuleLauncher.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/acme/insurance/launcher/PricingRuleLauncher.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -35,7 +35,7 @@
 
     	RuleBase ruleBase = buildRuleBase(drl);
     	
-		WorkingMemory wm = ruleBase.newWorkingMemory();
+		WorkingMemory wm = ruleBase.newStatefulSession();
 		
 		//now create some test data
 		Driver driver = new Driver();

Modified: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/ExternalSpreadsheetCompilerIntegrationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/ExternalSpreadsheetCompilerIntegrationTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/ExternalSpreadsheetCompilerIntegrationTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -58,7 +58,7 @@
         rb.addPackage( pkg );
 
         //NEW WORKING MEMORY
-        final WorkingMemory wm = rb.newWorkingMemory();
+        final WorkingMemory wm = rb.newStatefulSession();
 
         //ASSERT AND FIRE
         wm.assertObject( new Cheese( "stilton",
@@ -104,7 +104,7 @@
         final RuleBase rb = RuleBaseFactory.newRuleBase();
         rb.addPackage( pkg );
 
-        WorkingMemory wm = rb.newWorkingMemory();
+        WorkingMemory wm = rb.newStatefulSession();
         
         //now create some test data
         Driver driver = new Driver();

Modified: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/SpreadsheetIntegrationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/SpreadsheetIntegrationTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/SpreadsheetIntegrationTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -53,7 +53,7 @@
         rb.addPackage( pkg );
 
         //NEW WORKING MEMORY
-        final WorkingMemory wm = rb.newWorkingMemory();
+        final WorkingMemory wm = rb.newStatefulSession();
 
         //ASSERT AND FIRE
         wm.assertObject( new Cheese( "stilton",

Modified: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/DefaultTemplateRuleBaseTest.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/DefaultTemplateRuleBaseTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/DefaultTemplateRuleBaseTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -38,7 +38,7 @@
 			
 		};
 		DefaultTemplateRuleBase ruleBase = new DefaultTemplateRuleBase(tc);
-		Package[] packages = ruleBase.newWorkingMemory().getRuleBase().getPackages();
+		Package[] packages = ruleBase.newStatefulSession().getRuleBase().getPackages();
 		assertEquals(1, packages.length);
 		Map globals = packages[0].getGlobals();
 		assertEquals(DefaultGenerator.class, globals.get("generator"));

Modified: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/ExternalSheetListenerTest.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -13,9 +13,13 @@
 import org.drools.FactHandle;
 import org.drools.NoSuchFactHandleException;
 import org.drools.NoSuchFactObjectException;
+import org.drools.ObjectFilter;
 import org.drools.QueryResults;
 import org.drools.RuleBase;
+import org.drools.StatefulSession;
+import org.drools.StatelessSession;
 import org.drools.WorkingMemory;
+import org.drools.concurrent.Future;
 import org.drools.event.AgendaEventListener;
 import org.drools.event.WorkingMemoryEventListener;
 import org.drools.ruleflow.common.instance.IProcessInstance;
@@ -100,8 +104,8 @@
 	
 	private class TestTemplateRuleBase implements TemplateRuleBase {
 
-		public WorkingMemory newWorkingMemory() {
-			return new WorkingMemory() {
+		public StatefulSession newStatefulSession() {
+			return new StatefulSession() {
 
 				public void addEventListener(WorkingMemoryEventListener arg0) {
 
@@ -173,23 +177,11 @@
 					return null;
 				}
 
-				public Map getGlobals() {
-					return null;
-				}
-
 				public Object getObject(FactHandle arg0)
 						throws NoSuchFactObjectException {
 					return null;
 				}
 
-				public List getObjects() {
-					return null;
-				}
-
-				public List getObjects(Class arg0) {
-					return null;
-				}
-
 				public QueryResults getQueryResults(String arg0) {
 					return null;
 				}
@@ -242,6 +234,62 @@
 				public IProcessInstance startProcess(String processId) {
 					return null;
 				}
+
+                public Map getGlobals() {
+                    return null;
+                }
+
+                public Iterator iterateFactHandles() {
+                    return null;
+                }
+
+                public Iterator iterateFactHandles(ObjectFilter filter) {
+                    return null;
+                }
+
+                public Iterator iterateObjects() {
+                    return null;
+                }
+
+                public Iterator iterateObjects(ObjectFilter filter) {
+                    return null;
+                }
+
+                public Future asyncAssertObject(Object object) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
+
+                public Future asyncAssertObjects(Object[] list) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
+
+                public Future asyncAssertObjects(List list) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
+
+                public Future asyncFireAllRules() {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
+
+                public Future asyncFireAllRules(AgendaFilter agendaFilter) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
+
+                public Future asyncModifyObject(FactHandle factHandle,
+                                                Object object) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
+
+                public Future asyncRetractObject(FactHandle factHandle) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 			};
 		}
 	}

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath	2007-04-23 22:54:04 UTC (rev 11274)
@@ -18,5 +18,8 @@
 	<classpathentry exported="true" kind="lib" path="lib/drools-core-3.1.0-M1.jar"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/drools-compiler"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/drools-core"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/drools-decisiontables"/>
 	<classpathentry kind="output" path="target/classes"/>
 </classpath>

Modified: labs/jbossrules/trunk/drools-jbrms/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/.classpath	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-jbrms/.classpath	2007-04-23 22:54:04 UTC (rev 11274)
@@ -4,50 +4,50 @@
 	<classpathentry kind="src" path="src/main/resources"/>
 	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
 	<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-	<classpathentry kind="var" path="M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"/>
-	<classpathentry kind="var" path="M2_REPO/javax/jcr/jcr/1.0/jcr-1.0.jar"/>
-	<classpathentry kind="var" path="M2_REPO/antlr/stringtemplate/3.0/stringtemplate-3.0.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="var" path="M2_REPO/org/mvel/mvel14/1.2beta13/mvel14-1.2beta13.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/hibernate/hibernate-annotations/3.2.1.ga/hibernate-annotations-3.2.1.ga.jar"/>
-	<classpathentry kind="var" path="M2_REPO/janino/janino/2.5.5/janino-2.5.5.jar"/>
-	<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/antlr/antlr/2.7.7/antlr-2.7.7.jar"/>
-	<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
-	<classpathentry kind="var" path="M2_REPO/commons-io/commons-io/1.1/commons-io-1.1.jar"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.5.0_10"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jta_1.0.1B_spec/1.0.1/geronimo-jta_1.0.1B_spec-1.0.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/google/gwt-servlet/1.3.3/gwt-servlet-1.3.3.jar"/>
+	<classpathentry kind="src" path="/drools-compiler"/>
 	<classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
-	<classpathentry kind="var" path="M2_REPO/asm/asm/1.5.3/asm-1.5.3.jar"/>
 	<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.8/log4j-1.2.8.jar"/>
-	<classpathentry kind="var" path="M2_REPO/javax/jms/jms/1.1/jms-1.1.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.0/slf4j-log4j12-1.0.jar"/>
-	<classpathentry kind="var" path="M2_REPO/jboss/seam/jboss-seam/1.2.0.GA/jboss-seam-1.2.0.GA.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/apache/derby/derby/10.2.1.6/derby-10.2.1.6.jar"/>
-	<classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
+	<classpathentry kind="var" path="M2_REPO/antlr/stringtemplate/3.0/stringtemplate-3.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/tmatesoft/javasvn/1.1-beta5/javasvn-1.1-beta5.jar"/>
 	<classpathentry kind="var" path="M2_REPO/org/apache/jackrabbit/jackrabbit-jcr-commons/1.2.2/jackrabbit-jcr-commons-1.2.2.jar"/>
-	<classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.3/servlet-api-2.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/org/antlr/antlr/3.0b5/antlr-3.0b5.jar"/>
+	<classpathentry kind="var" path="M2_REPO/asm/asm/1.5.3/asm-1.5.3.jar"/>
+	<classpathentry kind="src" path="/drools-core"/>
+	<classpathentry kind="var" path="M2_REPO/cglib/cglib/2.1_3/cglib-2.1_3.jar"/>
+	<classpathentry kind="var" path="M2_REPO/commons-collections/commons-collections/3.1/commons-collections-3.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/jackrabbit/jackrabbit-api/1.2.2/jackrabbit-api-1.2.2.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javax/jcr/jcr/1.0/jcr-1.0.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/jackrabbit/jackrabbit-core/1.2.2/jackrabbit-core-1.2.2.jar"/>
 	<classpathentry kind="var" path="M2_REPO/net/sf/ehcache/ehcache/1.2.3/ehcache-1.2.3.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/apache/lucene/lucene-core/2.0.0/lucene-core-2.0.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/hibernate/hibernate/3.2.1.ga/hibernate-3.2.1.ga.jar"/>
 	<classpathentry kind="var" path="M2_REPO/javax/transaction/jta/1.0.1B/jta-1.0.1B.jar"/>
-	<classpathentry kind="var" path="M2_REPO/google/gwt-servlet/1.3.3/gwt-servlet-1.3.3.jar"/>
-	<classpathentry kind="var" path="M2_REPO/commons-fileupload/commons-fileupload/1.1.1/commons-fileupload-1.1.1.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/apache/jackrabbit/jackrabbit-core/1.2.2/jackrabbit-core-1.2.2.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar"/>
+	<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/concurrent/concurrent/1.3.4/concurrent-1.3.4.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.3/servlet-api-2.3.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/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"/>
 	<classpathentry kind="var" path="M2_REPO/jboss/javassist/3.4.ga/javassist-3.4.ga.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/apache/jackrabbit/jackrabbit-api/1.2.2/jackrabbit-api-1.2.2.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/hibernate/hibernate-annotations/3.2.1.ga/hibernate-annotations-3.2.1.ga.jar"/>
+	<classpathentry kind="src" path="/drools-repository"/>
 	<classpathentry kind="var" path="M2_REPO/jboss/seam/profiles/seam-nopersistence/1.2.0.GA/seam-nopersistence-1.2.0.GA.jar"/>
-	<classpathentry kind="var" path="M2_REPO/commons-collections/commons-collections/3.1/commons-collections-3.1.jar"/>
-	<classpathentry kind="var" path="M2_REPO/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/antlr/antlr/3.0b5/antlr-3.0b5.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/tmatesoft/javasvn/1.1-beta5/javasvn-1.1-beta5.jar"/>
-	<classpathentry kind="var" path="M2_REPO/cglib/cglib/2.1_3/cglib-2.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/org/hibernate/hibernate/3.2.1.ga/hibernate-3.2.1.ga.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jta_1.0.1B_spec/1.0.1/geronimo-jta_1.0.1B_spec-1.0.1.jar"/>
-	<classpathentry kind="var" path="M2_REPO/concurrent/concurrent/1.3.4/concurrent-1.3.4.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/derby/derby/10.2.1.6/derby-10.2.1.6.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/seam/jboss-seam/1.2.0.GA/jboss-seam-1.2.0.GA.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="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.0/slf4j-log4j12-1.0.jar"/>
 	<classpathentry kind="var" path="M2_REPO/asm/asm-attrs/1.5.3/asm-attrs-1.5.3.jar"/>
-	<classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar"/>
-	<classpathentry combineaccessrules="false" kind="src" path="/drools-compiler"/>
-	<classpathentry combineaccessrules="false" kind="src" path="/drools-repository"/>
-	<classpathentry combineaccessrules="false" kind="src" path="/drools-core"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/lucene/lucene-core/2.0.0/lucene-core-2.0.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/commons-fileupload/commons-fileupload/1.1.1/commons-fileupload-1.1.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javax/jms/jms/1.1/jms-1.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta15/mvel14-1.2beta15.jar"/>
+	<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/janino/janino/2.5.5/janino-2.5.5.jar"/>
 	<classpathentry kind="output" path="target/classes"/>
 </classpath>

Modified: labs/jbossrules/trunk/drools-jbrms/.project
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/.project	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-jbrms/.project	2007-04-23 22:54:04 UTC (rev 11274)
@@ -1,7 +1,11 @@
 <projectDescription>
   <name>drools-jbrms</name>
   <comment>A rule production system</comment>
-  <projects/>
+  <projects>
+    <project>drools-compiler</project>
+    <project>drools-core</project>
+    <project>drools-repository</project>
+  </projects>
   <buildSpec>
     <buildCommand>
       <name>org.eclipse.jdt.core.javabuilder</name>

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/modeldriven/ui/RuleModeller.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/modeldriven/ui/RuleModeller.java	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/modeldriven/ui/RuleModeller.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -566,6 +566,7 @@
      * either by the rule, or as a global.
      */
     public boolean isVariableNameUsed(String name) {
+        
         return model.isVariableNameUsed( name ) || completions.isGlobalVariable( name );
     }
     

Modified: labs/jbossrules/trunk/drools-jsr94/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/.classpath	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-jsr94/.classpath	2007-04-23 22:54:04 UTC (rev 11274)
@@ -1,24 +1,25 @@
-<classpath>
-  <classpathentry kind="src" path="src/main/java"/>
-  <classpathentry kind="src" path="src/main/resources"/>
-  <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
-  <classpathentry kind="src" path="src/test/resources" output="target/test-classes"/>
-  <classpathentry kind="output" path="target/classes"/>
-  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-  <classpathentry kind="var" path="M2_REPO/jsr94/jsr94-tck/1.0.3/jsr94-tck-1.0.3.jar"/>
-  <classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.7/antlr-2.7.7.jar"/>
-  <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.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="src" path="/drools-core"/>
-  <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="var" path="M2_REPO/janino/janino/2.5.5/janino-2.5.5.jar"/>
-  <classpathentry kind="var" path="M2_REPO/antlr/stringtemplate/3.0/stringtemplate-3.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/jsr94/jsr94/1.1/jsr94-1.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/jsr94/jsr94-sigtest/1.1/jsr94-sigtest-1.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta15/mvel14-1.2beta15.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/antlr/antlr/3.0b5/antlr-3.0b5.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/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
-</classpath>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="src" path="src/main/resources"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="var" path="M2_REPO/jsr94/jsr94-sigtest/1.1/jsr94-sigtest-1.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jsr94/jsr94/1.1/jsr94-1.1.jar"/>
+	<classpathentry kind="src" path="/drools-core"/>
+	<classpathentry kind="var" path="M2_REPO/jsr94/jsr94-tck/1.0.3/jsr94-tck-1.0.3.jar" sourcepath="/M2_REPO/jsr94/jsr94-tck/1.0.3/jsr94-tck-1.0.3-src.jar"/>
+	<classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
+	<classpathentry kind="src" path="/drools-compiler"/>
+	<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="var" path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"/>
+	<classpathentry kind="var" path="M2_REPO/antlr/stringtemplate/3.0/stringtemplate-3.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.7/antlr-2.7.7.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/antlr/antlr/3.0b5/antlr-3.0b5.jar"/>
+	<classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2beta15/mvel14-1.2beta15.jar"/>
+	<classpathentry kind="var" path="M2_REPO/janino/janino/2.5.5/janino-2.5.5.jar"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Modified: labs/jbossrules/trunk/drools-jsr94/.project
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/.project	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-jsr94/.project	2007-04-23 22:54:04 UTC (rev 11274)
@@ -2,8 +2,8 @@
   <name>drools-jsr94</name>
   <comment>A rule production system</comment>
   <projects>
+    <project>drools-core</project>
     <project>drools-compiler</project>
-    <project>drools-core</project>
   </projects>
   <buildSpec>
     <buildCommand>

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-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/AbstractRuleSessionImpl.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -58,17 +58,10 @@
     private RuleExecutionSetRepository repository;
 
     public AbstractRuleSessionImpl(final RuleExecutionSetRepository repository) {
-        super();
         this.repository = repository;
     }
-
+    
     /**
-     * The Drools <code>WorkingMemory</code> associated
-     * with this <code>RuleSession</code>.
-     */
-    protected WorkingMemory        workingMemory;
-
-    /**
      * The Drools <code>RuleExecutionSet</code> associated
      * with this <code>RuleSession</code>.
      */
@@ -81,25 +74,6 @@
     private Map                  properties;
 
     /**
-     * Initialize this <code>RuleSession</code>
-     * with a new <code>WorkingMemory</code>.
-     */
-    protected void initWorkingMemory(boolean keepReference) {        
-        final WorkingMemory newWorkingMemory = this.getRuleExecutionSet().newWorkingMemory(keepReference);
-
-        final Map props = this.getProperties();
-        if ( props != null ) {
-            for ( final Iterator iterator = props.entrySet().iterator(); iterator.hasNext(); ) {
-                final Map.Entry entry = (Map.Entry) iterator.next();
-                newWorkingMemory.setGlobal( (String) entry.getKey(),
-                                            entry.getValue() );
-            }
-        }
-        
-        this.setWorkingMemory( newWorkingMemory );
-    }
-
-    /**
      * Sets additional properties used to create this <code>RuleSession</code>.
      *
      * @param properties additional properties used to create the
@@ -121,32 +95,6 @@
     }
 
     /**
-     * Sets the Drools <code>WorkingMemory</code> associated
-     * with this <code>RuleSession</code>.
-     *
-     * @param workingMemory the <code>WorkingMemory</code> to associate
-     *        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;
-    }
-
-    /**
-     * Returns the Drools <code>WorkingMemory</code> associated
-     * with this <code>RuleSession</code>.
-     *
-     * @return the Drools <code>WorkingMemory</code> to associate
-     *         with this <code>RuleSession</code>.
-     */
-    protected WorkingMemory getWorkingMemory() {
-        return this.workingMemory;
-    }
-
-    /**
      * Sets the Drools <code>RuleExecutionSet</code> associated
      * with this <code>RuleSession</code>.
      *
@@ -167,83 +115,10 @@
     protected RuleExecutionSetImpl getRuleExecutionSet() {
         return this.ruleExecutionSet;
     }
-
-    /**
-     * Ensures this <code>RuleSession</code> is not
-     * in an illegal rule session state.
-     *
-     * @throws InvalidRuleSessionException on illegal rule session state.
-     */
-    protected void checkRuleSessionValidity() throws InvalidRuleSessionException {
-        if ( this.workingMemory == null ) {
-            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() );
-    }    
+    protected abstract void checkRuleSessionValidity() throws InvalidRuleSessionException;    
     
-    /**
-     * 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 {
-        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 ( filter.filter( object ) == null ) {
-                    objectIter.remove();
-                }
-            }
-        }
-
-        return objects;
-    }    
-
     // JSR94 interface methods start here -------------------------------------
 
     /**
@@ -274,11 +149,7 @@
      * it is reacquired through the <code>RuleRuntime</code>.
      */
     public void release() {
-        if ( this.workingMemory != null ) {
-            this.workingMemory.dispose();
-        }
         setProperties( null );
-        setWorkingMemory( null );
         setRuleExecutionSet( null );
     }
 }

Added: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/IteratorToList.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/IteratorToList.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/IteratorToList.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,15 @@
+package org.drools.jsr94.rules;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+class IteratorToList {
+    public static List convert(Iterator it) {
+        List list = new ArrayList();
+        while ( it.hasNext() ) {
+            list.add( it.next() );
+        }
+        return list;
+    }    
+}

Added: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/ObjectFilterAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/ObjectFilterAdapter.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/ObjectFilterAdapter.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -0,0 +1,15 @@
+package org.drools.jsr94.rules;
+
+import javax.rules.ObjectFilter;
+
+public class ObjectFilterAdapter implements org.drools.ObjectFilter {
+    private ObjectFilter filter;
+    
+    public ObjectFilterAdapter(ObjectFilter filter) {
+        this.filter = filter;
+    }
+
+    public boolean accept(Object object) {
+        return ( this.filter == null || this.filter.filter( object ) != null );
+    }
+}

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-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatefulRuleSessionImpl.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -33,6 +33,8 @@
 import org.drools.FactException;
 import org.drools.FactHandle;
 import org.drools.NoSuchFactObjectException;
+import org.drools.StatefulSession;
+import org.drools.WorkingMemory;
 import org.drools.jsr94.rules.admin.RuleExecutionSetImpl;
 import org.drools.jsr94.rules.admin.RuleExecutionSetRepository;
 
@@ -68,6 +70,8 @@
      * 
      */
     private static final long serialVersionUID = 1L;
+    
+    private StatefulSession session;
 
     /**
      * Gets the <code>RuleExecutionSet</code> for this URI and associates it
@@ -96,9 +100,26 @@
 
         this.setRuleExecutionSet( ruleSet );
 
-        initWorkingMemory( true );
+        initSession( true );
     }
+    
+    /**
+     * Initialize this <code>RuleSession</code>
+     * with a new <code>WorkingMemory</code>.
+     */
+    protected void initSession(boolean keepReference) {        
+        this.session = this.getRuleExecutionSet().newStatefulSession( keepReference);
 
+        final Map props = this.getProperties();
+        if ( props != null ) {
+            for ( final Iterator iterator = props.entrySet().iterator(); iterator.hasNext(); ) {
+                final Map.Entry entry = (Map.Entry) iterator.next();
+                this.session.setGlobal( (String) entry.getKey(),
+                                            entry.getValue() );
+            }
+        }               
+    }    
+
     // ----------------------------------------------------------------------
     // Instance methods
     // ----------------------------------------------------------------------
@@ -115,7 +136,7 @@
      */
     public boolean containsObject(final Handle objectHandle) {
         if ( objectHandle instanceof FactHandle ) {
-            return getWorkingMemory().getObject( (FactHandle) objectHandle ) != null;
+            return this.session.getObject( (FactHandle) objectHandle ) != null;
         }
 
         return false;
@@ -138,7 +159,7 @@
      */
     public Handle addObject(final Object object) throws InvalidRuleSessionException {
         checkRuleSessionValidity();
-        return (Handle) getWorkingMemory().assertObject( object );
+        return (Handle) this.session.assertObject( object );
     }
 
     /**
@@ -189,7 +210,7 @@
         checkRuleSessionValidity();
 
         if ( objectHandle instanceof FactHandle ) {
-            getWorkingMemory().modifyObject( (FactHandle) objectHandle,
+            this.session.modifyObject( (FactHandle) objectHandle,
                                              newObject );
         } else {
             throw new InvalidHandleException( "invalid handle" );
@@ -214,7 +235,7 @@
         checkRuleSessionValidity();
 
         if ( handleObject instanceof FactHandle ) {
-            getWorkingMemory().retractObject( (FactHandle) handleObject );
+            this.session.retractObject( (FactHandle) handleObject );
         } else {
             throw new InvalidHandleException( "invalid handle" );
         }
@@ -231,7 +252,7 @@
      */
     public void executeRules() throws InvalidRuleSessionException {
         checkRuleSessionValidity();
-        getWorkingMemory().fireAllRules();
+        this.session.fireAllRules();
     }
 
     /**
@@ -242,7 +263,7 @@
        checkRuleSessionValidity();
 
         if ( handle instanceof FactHandle ) {
-            return getWorkingMemory().getObject( (FactHandle) handle );
+            return this.session.getObject( (FactHandle) handle );
         } else {
             throw new InvalidHandleException( "invalid handle" );
         }
@@ -256,15 +277,58 @@
      *         currect state of the rule session.
      */
     public List getHandles() {
-        final List handles = new LinkedList();
-        for ( final Iterator i = getWorkingMemory().getFactHandles().iterator(); i.hasNext(); ) {
-            final Object object = i.next();
-            if ( object instanceof Handle ) {
-                handles.add( object );
-            }
-        }
-        return handles;
+        return IteratorToList.convert( this.session.iterateFactHandles() );
     }
+    
+    /**
+     * 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() );
+    }    
+    
+    /**
+     * 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 {
+        checkRuleSessionValidity();
+        
+        return IteratorToList.convert( this.session.iterateObjects( new ObjectFilterAdapter( filter ) ) );
+    }     
 
     /**
      * Resets this rule session. Calling this method will bring the rule session
@@ -276,10 +340,35 @@
      */
     public void reset() {
         // stateful rule sessions should not be high load, thus safe to keep references
-        initWorkingMemory( true );
+        initSession( true );
     }
 
     public int getType() throws InvalidRuleSessionException {
         return RuleRuntime.STATEFUL_SESSION_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.session != null ) {
+            this.session.dispose();
+        }
+        this.session = null;
+        super.release();
+    }    
+    
+    /**
+     * Ensures this <code>RuleSession</code> is not
+     * in an illegal rule session state.
+     *
+     * @throws InvalidRuleSessionException on illegal rule session state.
+     */
+    protected void checkRuleSessionValidity() throws InvalidRuleSessionException {
+        if ( this.session == null ) {
+            throw new InvalidRuleSessionException( "invalid rule session" );
+        }
+    }    
 }

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-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatelessRuleSessionImpl.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -26,6 +26,8 @@
 import javax.rules.StatelessRuleSession;
 
 import org.drools.FactException;
+import org.drools.StatelessSession;
+import org.drools.StatelessSessionResult;
 import org.drools.WorkingMemory;
 import org.drools.jsr94.rules.admin.RuleExecutionSetImpl;
 import org.drools.jsr94.rules.admin.RuleExecutionSetRepository;
@@ -42,7 +44,7 @@
  */
 public class StatelessRuleSessionImpl extends AbstractRuleSessionImpl
     implements
-    StatelessRuleSession {
+    StatelessRuleSession {    
     /**
      * Gets the <code>RuleExecutionSet</code> for this URI and associates it
      * with a RuleBase.
@@ -70,7 +72,25 @@
 
         setRuleExecutionSet( ruleSet );
     }
+    
+    /**
+     * Initialize this <code>RuleSession</code>
+     * with a new <code>WorkingMemory</code>.
+     */
+    protected StatelessSession newStatelessSession() {        
+        final StatelessSession session = this.getRuleExecutionSet().newStatelessSession();
 
+        final Map props = this.getProperties();
+        if ( props != null ) {
+            for ( final Iterator iterator = props.entrySet().iterator(); iterator.hasNext(); ) {
+                final Map.Entry entry = (Map.Entry) iterator.next();
+                session.setGlobal( (String) entry.getKey(),
+                                            entry.getValue() );
+            }
+        }
+        return session;
+    }    
+
     /**
      * Executes the rules in the bound rule execution set using the supplied
      * list of objects. A <code>List</code> is returned containing the objects
@@ -125,21 +145,25 @@
      */
     public List executeRules(final List objects,
                              final ObjectFilter filter) throws InvalidRuleSessionException {
-        // get a new working memory with no references kept (i.e. it doesn't need to be disposed)
-        initWorkingMemory( false );
-
-        WorkingMemory workingMemory = getWorkingMemory();
-        for ( final Iterator objectIter = objects.iterator(); objectIter.hasNext(); ) {
-            workingMemory.assertObject( objectIter.next() );
-        }
-        workingMemory.fireAllRules();            
-
-        final List results = getObjects(filter);
-
-        return results;
+        StatelessSession session = newStatelessSession();
+        StatelessSessionResult results = session.executeWithResults( objects );
+        
+        return IteratorToList.convert( results.iterateObjects( new ObjectFilterAdapter( filter ) ) );
     }
     
     public int getType() throws InvalidRuleSessionException {
         return RuleRuntime.STATELESS_SESSION_TYPE;
     }
+    
+    /**
+     * Ensures this <code>RuleSession</code> is not
+     * in an illegal rule session state.
+     *
+     * @throws InvalidRuleSessionException on illegal rule session state.
+     */
+    protected void checkRuleSessionValidity() throws InvalidRuleSessionException {
+        if ( getRuleExecutionSet() == null ) {
+            throw new InvalidRuleSessionException( "invalid rule session" );
+        }
+    }     
 }

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-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetImpl.java	2007-04-23 22:54:04 UTC (rev 11274)
@@ -27,7 +27,8 @@
 import org.drools.IntegrationException;
 import org.drools.RuleBase;
 import org.drools.RuleIntegrationException;
-import org.drools.WorkingMemory;
+import org.drools.StatefulSession;
+import org.drools.StatelessSession;
 import org.drools.jsr94.rules.Jsr94FactHandleFactory;
 import org.drools.rule.Package;
 import org.drools.rule.Rule;
@@ -158,9 +159,18 @@
      *
      * @return A new WorkingMemory object.
      */
-    public WorkingMemory newWorkingMemory(boolean keepReference) {
-        return this.ruleBase.newWorkingMemory(keepReference);
+    public StatefulSession newStatefulSession(boolean keepReference) {
+        return this.ruleBase.newStatefulSession(keepReference);
     }
+    
+    /**
+     * Returns a new WorkingMemory object.
+     *
+     * @return A new WorkingMemory object.
+     */
+    public StatelessSession newStatelessSession() {
+        return this.ruleBase.newStatelessSession();
+    }    
 
     // JSR94 interface methods start here -------------------------------------
 

Modified: labs/jbossrules/trunk/drools-repository/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-repository/.classpath	2007-04-23 22:41:43 UTC (rev 11273)
+++ labs/jbossrules/trunk/drools-repository/.classpath	2007-04-23 22:54:04 UTC (rev 11274)
@@ -1,21 +1,22 @@
-<classpath>
-  <classpathentry kind="src" path="src/main/java"/>
-  <classpathentry kind="src" path="src/main/resources"/>
-  <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
-  <classpathentry kind="src" path="src/test/resources" output="target/test-classes"/>
-  <classpathentry kind="output" path="target/classes"/>
-  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/jackrabbit/jackrabbit-api/1.2.2/jackrabbit-api-1.2.2.jar" sourcepath="M2_REPO/org/apache/jackrabbit/jackrabbit-api/1.2.2/jackrabbit-api-1.2.2-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jta_1.0.1B_spec/1.0.1/geronimo-jta_1.0.1B_spec-1.0.1.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/jackrabbit/jackrabbit-jcr-commons/1.2.2/jackrabbit-jcr-commons-1.2.2.jar" sourcepath="M2_REPO/org/apache/jackrabbit/jackrabbit-jcr-commons/1.2.2/jackrabbit-jcr-commons-1.2.2-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/commons-collections/commons-collections/3.1/commons-collections-3.1.jar" sourcepath="M2_REPO/commons-collections/commons-collections/3.1/commons-collections-3.1-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/jackrabbit/jackrabbit-core/1.2.2/jackrabbit-core-1.2.2.jar" sourcepath="M2_REPO/org/apache/jackrabbit/jackrabbit-core/1.2.2/jackrabbit-core-1.2.2-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.8/log4j-1.2.8.jar" sourcepath="M2_REPO/log4j/log4j/1.2.8/log4j-1.2.8-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.0/slf4j-log4j12-1.0.jar" sourcepath="M2_REPO/org/slf4j/slf4j-log4j12/1.0/slf4j-log4j12-1.0-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/lucene/lucene-core/2.0.0/lucene-core-2.0.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/javax/jcr/jcr/1.0/jcr-1.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/apache/derby/derby/10.2.1.6/derby-10.2.1.6.jar"/>
-  <classpathentry kind="var" path="M2_REPO/concurrent/concurrent/1.3.4/concurrent-1.3.4.jar" sourcepath="M2_REPO/concurrent/concurrent/1.3.4/concurrent-1.3.4-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/tmatesoft/javasvn/1.1-beta5/javasvn-1.1-beta5.jar"/>
-</classpath>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="src" path="src/main/resources"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.5.0_10"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/jackrabbit/jackrabbit-api/1.2.2/jackrabbit-api-1.2.2.jar" sourcepath="M2_REPO/org/apache/jackrabbit/jackrabbit-api/1.2.2/jackrabbit-api-1.2.2-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jta_1.0.1B_spec/1.0.1/geronimo-jta_1.0.1B_spec-1.0.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/jackrabbit/jackrabbit-jcr-commons/1.2.2/jackrabbit-jcr-commons-1.2.2.jar" sourcepath="M2_REPO/org/apache/jackrabbit/jackrabbit-jcr-commons/1.2.2/jackrabbit-jcr-commons-1.2.2-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/commons-collections/commons-collections/3.1/commons-collections-3.1.jar" sourcepath="M2_REPO/commons-collections/commons-collections/3.1/commons-collections-3.1-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/jackrabbit/jackrabbit-core/1.2.2/jackrabbit-core-1.2.2.jar" sourcepath="M2_REPO/org/apache/jackrabbit/jackrabbit-core/1.2.2/jackrabbit-core-1.2.2-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.8/log4j-1.2.8.jar" sourcepath="M2_REPO/log4j/log4j/1.2.8/log4j-1.2.8-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.0/slf4j-log4j12-1.0.jar" sourcepath="M2_REPO/org/slf4j/slf4j-log4j12/1.0/slf4j-log4j12-1.0-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/lucene/lucene-core/2.0.0/lucene-core-2.0.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javax/jcr/jcr/1.0/jcr-1.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/derby/derby/10.2.1.6/derby-10.2.1.6.jar"/>
+	<classpathentry kind="var" path="M2_REPO/concurrent/concurrent/1.3.4/concurrent-1.3.4.jar" sourcepath="M2_REPO/concurrent/concurrent/1.3.4/concurrent-1.3.4-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/tmatesoft/javasvn/1.1-beta5/javasvn-1.1-beta5.jar"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>




More information about the jboss-svn-commits mailing list