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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Jul 1 23:24:12 EDT 2007


Author: mark.proctor at jboss.com
Date: 2007-07-01 23:24:12 -0400 (Sun, 01 Jul 2007)
New Revision: 12991

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java
Log:
JBRULES-947 sequential rete
-shadowproxy is on by default for rete mode and off by default for sequential mode.

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java	2007-07-02 03:02:56 UTC (rev 12990)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java	2007-07-02 03:24:12 UTC (rev 12991)
@@ -51,6 +51,8 @@
  */
 
 /**
+ * drools.shadowproxy = <true|false>
+ * drools.shadowproxy.exclude = org.domainy.* org.domainx.ClassZ
  * drools.sequential = <true|false>
  * drools.sequential.agenda = <sequential|dynamic>
  * drools.removeIdentities = <true|false>
@@ -66,7 +68,6 @@
  * drools.executorService = <qualified class name>
  * drools.conflictResolver = <qualified class name>
  * 
- * drools.shadowproxy.exclude = org.domainy.* org.domainx.ClassZ
  */
 public class RuleBaseConfiguration
     implements
@@ -95,6 +96,7 @@
 
     private ConflictResolver    conflictResolver;
 
+    private boolean             shadowProxy;
     private Map                 shadowProxyExcludes;
     private static final String STAR             = "*";
 
@@ -158,6 +160,12 @@
         setConflictResolver( RuleBaseConfiguration.determineConflictResolver( this.chainedProperties.getProperty( "drools.conflictResolver",
                                                                                                                   "org.drools.conflict.DepthConflictResolver" ) ) );
 
+        setShareBetaNodes( Boolean.valueOf( this.chainedProperties.getProperty( "drools.shadowproxy",
+                                                                                "true" ) ).booleanValue() );
+
+        setShadowProxy( determineShadowProxy( this.chainedProperties.getProperty( "drools.shadowproxy",
+                                                                                  null ) ) );
+
         setShadowProxyExcludes( this.chainedProperties.getProperty( "drools.shadowProxyExcludes",
                                                                     "" ) );
     }
@@ -307,6 +315,144 @@
         this.executorService = executorService;
     }
 
+    public AgendaGroupFactory getAgendaGroupFactory() {
+        if ( isSequential() ) {
+            if ( this.sequentialAgenda == SequentialAgenda.SEQUENTIAL ) {
+                return ArrayAgendaGroupFactory.getInstance();
+            } else {
+                return PriorityQueueAgendaGroupFactory.getInstance();
+            }
+        } else {
+            return PriorityQueueAgendaGroupFactory.getInstance();
+        }
+    }
+
+    public SequentialAgenda getSequentialAgenda() {
+        return this.sequentialAgenda;
+    }
+
+    public void setSequentialAgenda(final SequentialAgenda sequentialAgenda) {
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.sequentialAgenda = sequentialAgenda;
+    }
+    
+    private boolean determineShadowProxy(String userValue) {
+        if ( userValue != null ) {
+            return Boolean.valueOf( userValue ).booleanValue();
+        } else {
+            if ( this.isSequential() ) {
+                return false;
+            } else {
+                return true;
+            }
+        }
+    }    
+
+    private static ConflictResolver determineConflictResolver(String className) {
+        Class clazz = null;
+        try {
+            clazz = Thread.currentThread().getContextClassLoader().loadClass( className );
+        } catch ( ClassNotFoundException e ) {
+        }
+
+        if ( clazz == null ) {
+            try {
+                clazz = RuleBaseConfiguration.class.getClassLoader().loadClass( className );
+            } catch ( ClassNotFoundException e ) {
+            }
+        }
+
+        if ( clazz != null ) {
+            try {
+                return (ConflictResolver) clazz.getMethod( "getInstance",
+                                                           null ).invoke( null,
+                                                                          null );
+            } catch ( Exception e ) {
+                throw new IllegalArgumentException( "Unable to Conflict Resolver '" + className + "'" );
+            }
+        } else {
+            throw new IllegalArgumentException( "conflict Resolver '" + className + "' not found" );
+        }
+    }
+
+    public void setConflictResolver(ConflictResolver conflictResolver) {
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.conflictResolver = conflictResolver;
+    }
+
+    public ConflictResolver getConflictResolver() {
+        return this.conflictResolver;
+    }
+
+    public void setShadowProxy(boolean shadowProxy) {
+        checkCanChange(); // throws an exception if a change isn't possible;
+        this.shadowProxy = shadowProxy;
+    }
+
+    public boolean isShadowProxy() {
+        return this.shadowProxy;
+    }
+
+    private void setShadowProxyExcludes(String excludes) {
+        checkCanChange(); // throws an exception if a change isn't possible;
+        if ( excludes == null || "".equals( excludes.trim() ) ) {
+            return;
+        }
+
+        if ( this.shadowProxyExcludes == null ) {
+            this.shadowProxyExcludes = new HashMap();
+        }
+
+        String[] items = excludes.split( " " );
+        for ( int i = 0; i < items.length; i++ ) {
+            String qualifiedNamespace = items[i].substring( 0,
+                                                            items[i].lastIndexOf( '.' ) ).trim();
+            String name = items[i].substring( items[i].lastIndexOf( '.' ) + 1 ).trim();
+            Object object = this.shadowProxyExcludes.get( qualifiedNamespace );
+            if ( object == null ) {
+                if ( STAR.equals( name ) ) {
+                    this.shadowProxyExcludes.put( qualifiedNamespace,
+                                                  STAR );
+                } else {
+                    // create a new list and add it
+                    List list = new ArrayList();
+                    list.add( name );
+                    this.shadowProxyExcludes.put( qualifiedNamespace,
+                                                  list );
+                }
+            } else if ( name.equals( STAR ) ) {
+                // if its a STAR now add it anyway, we don't care if it was a STAR or a List before
+                this.shadowProxyExcludes.put( qualifiedNamespace,
+                                              STAR );
+            } else {
+                // its a list so add it if it doesn't already exist
+                List list = (List) object;
+                if ( !list.contains( object ) ) {
+                    list.add( name );
+                }
+            }
+        }
+    }
+
+    public boolean isShadowed(String className) {
+        if ( this.shadowProxyExcludes == null ) {
+            return true;
+        }
+
+        String qualifiedNamespace = className.substring( 0,
+                                                         className.lastIndexOf( '.' ) ).trim();
+        String name = className.substring( className.lastIndexOf( '.' ) + 1 ).trim();
+        Object object = this.shadowProxyExcludes.get( qualifiedNamespace );
+        if ( object == null ) {
+            return true;
+        } else if ( STAR.equals( object ) ) {
+            return false;
+        } else {
+            List list = (List) object;
+            return !list.contains( name );
+        }
+    }
+
     private static ExecutorService determineExecutorService(String className) {
         Class clazz = null;
         try {
@@ -415,10 +561,10 @@
     public static class SequentialAgenda
         implements
         Serializable {
-        private static final long            serialVersionUID  = 320L;
+        private static final long            serialVersionUID = 320L;
 
-        public static final SequentialAgenda SEQUENTIAL = new SequentialAgenda( 0 );
-        public static final SequentialAgenda DYNAMIC    = new SequentialAgenda( 1 );
+        public static final SequentialAgenda SEQUENTIAL       = new SequentialAgenda( 0 );
+        public static final SequentialAgenda DYNAMIC          = new SequentialAgenda( 1 );
 
         private int                          value;
 
@@ -451,120 +597,4 @@
             return "SequentialAgenda : " + ((this.value == 0) ? "sequential" : "dynamic");
         }
     }
-
-    public AgendaGroupFactory getAgendaGroupFactory() {
-        if ( isSequential() ) {
-            if ( this.sequentialAgenda == SequentialAgenda.SEQUENTIAL ) {
-                return ArrayAgendaGroupFactory.getInstance();
-            } else {
-                return PriorityQueueAgendaGroupFactory.getInstance();
-            }
-        } else {
-            return PriorityQueueAgendaGroupFactory.getInstance();
-        }
-    }
-
-    public SequentialAgenda getSequentialAgenda() {
-        return this.sequentialAgenda;
-    }
-
-    public void setSequentialAgenda(final SequentialAgenda sequentialAgenda) {
-        checkCanChange(); // throws an exception if a change isn't possible;
-        this.sequentialAgenda = sequentialAgenda;
-    }
-
-    private static ConflictResolver determineConflictResolver(String className) {
-        Class clazz = null;
-        try {
-            clazz = Thread.currentThread().getContextClassLoader().loadClass( className );
-        } catch ( ClassNotFoundException e ) {
-        }
-
-        if ( clazz == null ) {
-            try {
-                clazz = RuleBaseConfiguration.class.getClassLoader().loadClass( className );
-            } catch ( ClassNotFoundException e ) {
-            }
-        }
-
-        if ( clazz != null ) {
-            try {
-                return (ConflictResolver) clazz.getMethod( "getInstance",
-                                                           null ).invoke( null,
-                                                                          null );
-            } catch ( Exception e ) {
-                throw new IllegalArgumentException( "Unable to Conflict Resolver '" + className + "'" );
-            }
-        } else {
-            throw new IllegalArgumentException( "conflict Resolver '" + className + "' not found" );
-        }
-    }
-
-    public void setConflictResolver(ConflictResolver conflictResolver) {
-        this.conflictResolver = conflictResolver;
-    }
-
-    public ConflictResolver getConflictResolver() {
-        return this.conflictResolver;
-    }
-
-    private void setShadowProxyExcludes(String excludes) {
-        if ( excludes == null || "".equals( excludes.trim() ) ) {
-            return;
-        }
-
-        if ( this.shadowProxyExcludes == null ) {
-            this.shadowProxyExcludes = new HashMap();
-        }
-
-        String[] items = excludes.split( " " );
-        for ( int i = 0; i < items.length; i++ ) {
-            String qualifiedNamespace = items[i].substring( 0,
-                                                            items[i].lastIndexOf( '.' ) ).trim();
-            String name = items[i].substring( items[i].lastIndexOf( '.' ) + 1 ).trim();
-            Object object = this.shadowProxyExcludes.get( qualifiedNamespace );
-            if ( object == null ) {
-                if ( STAR.equals( name ) ) {
-                    this.shadowProxyExcludes.put( qualifiedNamespace,
-                                                  STAR );
-                } else {
-                    // create a new list and add it
-                    List list = new ArrayList();
-                    list.add( name );
-                    this.shadowProxyExcludes.put( qualifiedNamespace,
-                                                  list );
-                }
-            } else if ( name.equals( STAR ) ) {
-                // if its a STAR now add it anyway, we don't care if it was a STAR or a List before
-                this.shadowProxyExcludes.put( qualifiedNamespace,
-                                              STAR );
-            } else {
-                // its a list so add it if it doesn't already exist
-                List list = (List) object;
-                if ( !list.contains( object ) ) {
-                    list.add( name );
-                }
-            }
-        }
-    }
-
-    public boolean isShadowed(String className) {
-        if ( this.shadowProxyExcludes == null ) {
-            return true;
-        }
-
-        String qualifiedNamespace = className.substring( 0,
-                                                         className.lastIndexOf( '.' ) ).trim();
-        String name = className.substring( className.lastIndexOf( '.' ) + 1 ).trim();
-        Object object = this.shadowProxyExcludes.get( qualifiedNamespace );
-        if ( object == null ) {
-            return true;
-        } else if ( STAR.equals( object ) ) {
-            return false;
-        } else {
-            List list = (List) object;
-            return !list.contains( name );
-        }
-    }
-
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java	2007-07-02 03:02:56 UTC (rev 12990)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java	2007-07-02 03:24:12 UTC (rev 12991)
@@ -320,7 +320,7 @@
             this.ruleBase = ruleBase;
             Rete rete = ruleBase.getRete();
 
-            if ( cls == null || !ruleBase.getConfiguration().isShadowed( cls.getName() ) ) {
+            if ( !ruleBase.getConfiguration().isShadowProxy() || cls == null || !ruleBase.getConfiguration().isShadowed( cls.getName() ) ) {
                 return;
             }
             

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java	2007-07-02 03:02:56 UTC (rev 12990)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java	2007-07-02 03:24:12 UTC (rev 12991)
@@ -42,6 +42,30 @@
         System.getProperties().remove( "drools.indexLeftBetaMemory" );        
     }
     
+    public void testShadowProxy() {
+        // check default for rete
+        RuleBaseConfiguration cfg = new RuleBaseConfiguration();        
+        assertTrue( cfg.isShadowProxy() );
+
+        // check default for sequentail
+        Properties properties = new Properties();
+        properties.setProperty( "drools.sequential", "true" );
+        cfg = new RuleBaseConfiguration(properties);        
+        assertFalse(  cfg.isShadowProxy() );
+        
+        properties = new Properties();
+        properties.setProperty( "drools.shadowproxy", "false" );
+        cfg = new RuleBaseConfiguration(properties);        
+        assertFalse(  cfg.isShadowProxy() );
+        
+        
+        properties = new Properties();
+        properties.setProperty( "drools.sequential", "true" );
+        properties.setProperty( "drools.shadowproxy", "false" );
+        cfg = new RuleBaseConfiguration(properties);        
+        assertFalse(  cfg.isShadowProxy() );         
+    }
+    
     public void testShadowProxyExcludes() {
         RuleBaseConfiguration cfg = new RuleBaseConfiguration();
         




More information about the jboss-svn-commits mailing list