[jboss-svn-commits] JBL Code SVN: r14544 - in labs/jbossrules/trunk/drools-core/src/main: java/org/drools/base and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Aug 24 20:32:37 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-08-24 20:32:36 -0400 (Fri, 24 Aug 2007)
New Revision: 14544
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DefaultConsequenceExceptionHandler.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/ConsequenceExceptionHandler.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/drools.default.rulebase.conf
Log:
JBRULES-1123 Custom Consequence Exception handlers
-users can now use the property "drools.consequenceExceptionHandler" or the RuleBaseconfiguration.setConsequenceExceptionHandler to specify a custom user defined handler for consequence exceptions.
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-08-25 00:32:29 UTC (rev 14543)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2007-08-25 00:32:36 UTC (rev 14544)
@@ -28,6 +28,7 @@
import org.drools.common.PriorityQueueAgendaGroupFactory;
import org.drools.concurrent.ExecutorService;
import org.drools.spi.ConflictResolver;
+import org.drools.spi.ConsequenceExceptionHandler;
import org.drools.util.ChainedProperties;
/**
@@ -62,38 +63,40 @@
* drools.logicalOverride = <discard|preserve>
* drools.executorService = <qualified class name>
* drools.conflictResolver = <qualified class name>
+ * drools.conflictExceptionHandler = <qualified class name>
*
*/
public class RuleBaseConfiguration
implements
Serializable {
- private static final long serialVersionUID = 400L;
+ private static final long serialVersionUID = 400L;
- private ChainedProperties chainedProperties;
+ private ChainedProperties chainedProperties;
- private boolean immutable;
+ private boolean immutable;
- private boolean sequential;
- private SequentialAgenda sequentialAgenda;
+ private boolean sequential;
+ private SequentialAgenda sequentialAgenda;
- private boolean maintainTms;
- private boolean removeIdentities;
- private boolean shareAlphaNodes;
- private boolean shareBetaNodes;
- private boolean alphaMemory;
- private int alphaNodeHashingThreshold;
- private int compositeKeyDepth;
- private boolean indexLeftBetaMemory;
- private boolean indexRightBetaMemory;
- private AssertBehaviour assertBehaviour;
- private LogicalOverride logicalOverride;
- private ExecutorService executorService;
+ private boolean maintainTms;
+ private boolean removeIdentities;
+ private boolean shareAlphaNodes;
+ private boolean shareBetaNodes;
+ private boolean alphaMemory;
+ private int alphaNodeHashingThreshold;
+ private int compositeKeyDepth;
+ private boolean indexLeftBetaMemory;
+ private boolean indexRightBetaMemory;
+ private AssertBehaviour assertBehaviour;
+ private LogicalOverride logicalOverride;
+ private ExecutorService executorService;
+ private ConsequenceExceptionHandler consequenceExceptionHandler;
- private ConflictResolver conflictResolver;
+ private ConflictResolver conflictResolver;
- private boolean shadowProxy;
- private Map shadowProxyExcludes;
- private static final String STAR = "*";
+ private boolean shadowProxy;
+ private Map shadowProxyExcludes;
+ private static final String STAR = "*";
public RuleBaseConfiguration(Properties properties) {
init( properties );
@@ -152,6 +155,9 @@
setExecutorService( RuleBaseConfiguration.determineExecutorService( this.chainedProperties.getProperty( "drools.executorService",
"org.drools.concurrent.DefaultExecutorService" ) ) );
+ setConsequenceExceptionHandler( RuleBaseConfiguration.determineConsequenceExceptionHandler( this.chainedProperties.getProperty( "drools.consequenceExceptionHandler",
+ "org.drools.base.DefaultConsequenceExceptionHandler" ) ) );
+
setConflictResolver( RuleBaseConfiguration.determineConflictResolver( this.chainedProperties.getProperty( "drools.conflictResolver",
"org.drools.conflict.DepthConflictResolver" ) ) );
@@ -310,6 +316,15 @@
this.executorService = executorService;
}
+ public ConsequenceExceptionHandler getConsequenceExceptionHandler() {
+ return consequenceExceptionHandler;
+ }
+
+ public void setConsequenceExceptionHandler(ConsequenceExceptionHandler consequenceExceptionHandler) {
+ checkCanChange(); // throws an exception if a change isn't possible;
+ this.consequenceExceptionHandler = consequenceExceptionHandler;
+ }
+
public AgendaGroupFactory getAgendaGroupFactory() {
if ( isSequential() ) {
if ( this.sequentialAgenda == SequentialAgenda.SEQUENTIAL ) {
@@ -330,7 +345,7 @@
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();
@@ -341,7 +356,7 @@
return true;
}
}
- }
+ }
private static ConflictResolver determineConflictResolver(String className) {
Class clazz = null;
@@ -449,6 +464,17 @@
}
private static ExecutorService determineExecutorService(String className) {
+ return (ExecutorService) instantiateClass( "ExecutorService",
+ className );
+ }
+
+ private static ConsequenceExceptionHandler determineConsequenceExceptionHandler(String className) {
+ return (ConsequenceExceptionHandler) instantiateClass( "ConsequenceExceptionHandler",
+ className );
+ }
+
+ private static Object instantiateClass(String type,
+ String className) {
Class clazz = null;
try {
clazz = Thread.currentThread().getContextClassLoader().loadClass( className );
@@ -464,12 +490,12 @@
if ( clazz != null ) {
try {
- return (ExecutorService) clazz.newInstance();
+ return clazz.newInstance();
} catch ( Exception e ) {
- throw new IllegalArgumentException( "Unable to instantiate ExecutorService '" + className + "'" );
+ throw new IllegalArgumentException( "Unable to instantiate " + type + " '" + className + "'" );
}
} else {
- throw new IllegalArgumentException( "ExecutorService '" + className + "' not found" );
+ throw new IllegalArgumentException( type + " '" + className + "' not found" );
}
}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DefaultConsequenceExceptionHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DefaultConsequenceExceptionHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DefaultConsequenceExceptionHandler.java 2007-08-25 00:32:36 UTC (rev 14544)
@@ -0,0 +1,18 @@
+package org.drools.base;
+
+import org.drools.WorkingMemory;
+import org.drools.spi.Activation;
+import org.drools.spi.ConsequenceException;
+import org.drools.spi.ConsequenceExceptionHandler;
+
+public class DefaultConsequenceExceptionHandler implements ConsequenceExceptionHandler {
+
+ public void handleException(Activation activation,
+ WorkingMemory workingMemory,
+ Exception exception) {
+ exception.printStackTrace();
+ throw new ConsequenceException( exception,
+ activation.getRule() );
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java 2007-08-25 00:32:29 UTC (rev 14543)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultAgenda.java 2007-08-25 00:32:36 UTC (rev 14544)
@@ -35,6 +35,7 @@
import org.drools.spi.AgendaGroup;
import org.drools.spi.ConflictResolver;
import org.drools.spi.ConsequenceException;
+import org.drools.spi.ConsequenceExceptionHandler;
import org.drools.spi.KnowledgeHelper;
import org.drools.spi.RuleFlowGroup;
import org.drools.util.LinkedListNode;
@@ -96,6 +97,8 @@
public int activeActivations;
public int dormantActivations;
+
+ private ConsequenceExceptionHandler consequenceExceptionHandler;
// ------------------------------------------------------------
// Constructors
@@ -131,6 +134,8 @@
this.main );
this.focusStack.add( this.main );
+
+ this.consequenceExceptionHandler = ((InternalRuleBase) workingMemory.getRuleBase()).getConfiguration().getConsequenceExceptionHandler();
}
@@ -545,9 +550,7 @@
activation.getRule().getConsequence().evaluate( this.knowledgeHelper,
this.workingMemory );
} catch ( final Exception e ) {
- e.printStackTrace();
- throw new ConsequenceException( e,
- activation.getRule() );
+ this.consequenceExceptionHandler.handleException( activation, this.workingMemory, e );
}
if ( activation.getRuleFlowGroupNode() != null ) {
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/ConsequenceExceptionHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/ConsequenceExceptionHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/ConsequenceExceptionHandler.java 2007-08-25 00:32:36 UTC (rev 14544)
@@ -0,0 +1,15 @@
+package org.drools.spi;
+
+import java.io.Serializable;
+
+import org.drools.WorkingMemory;
+
+/**
+ * Care should be taken when implementing this class. Swallowing of consequence can be dangerous
+ * if the exception occured during a WorkingMemory action, thus leaving the integrity of the
+ * WorkingMemory invalid.
+ *
+ */
+public interface ConsequenceExceptionHandler extends Serializable {
+ void handleException(Activation activation, WorkingMemory workingMemory, Exception exception);
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/drools.default.rulebase.conf
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/drools.default.rulebase.conf 2007-08-25 00:32:29 UTC (rev 14543)
+++ labs/jbossrules/trunk/drools-core/src/main/resources/META-INF/drools.default.rulebase.conf 2007-08-25 00:32:36 UTC (rev 14544)
@@ -10,4 +10,5 @@
drools.assertBehaviour = IDENTITY
drools.logicalOverride = DISCARD
drools.executorService = org.drools.concurrent.DefaultExecutorService
-drools.conflictResolver = org.drools.conflict.DepthConflictResolver
\ No newline at end of file
+drools.conflictResolver = org.drools.conflict.DepthConflictResolver
+drools.drools.consequenceExceptionHandler = org.drools.base.DefaultConsequenceExceptionHandler
\ No newline at end of file
More information about the jboss-svn-commits
mailing list