[jboss-svn-commits] JBL Code SVN: r24770 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: event and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jan 18 20:10:15 EST 2009
Author: mark.proctor at jboss.com
Date: 2009-01-18 20:10:14 -0500 (Sun, 18 Jan 2009)
New Revision: 24770
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java
Log:
JBRULES-1776 Lock on AbstractRuleBase object is not released when an error occurs.
-Added try/finally blocks
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 2009-01-18 23:54:16 UTC (rev 24769)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2009-01-19 01:10:14 UTC (rev 24770)
@@ -417,92 +417,94 @@
*/
public synchronized void addPackages(final Collection<Package> newPkgs) {
synchronized ( this.pkgs ) {
+ boolean doUnlock = false;
// only acquire the lock if it hasn't been done explicitely
- boolean doUnlock = false;
if ( !this.lock.isHeldByCurrentThread() && (this.wms == null || this.wms.length == 0) ) {
lock();
doUnlock = true;
- }
-
- // we need to merge all byte[] first, so that the root classloader can resolve classes
- for ( Package newPkg : newPkgs ) {
- newPkg.checkValidity();
- this.additionsSinceLock++;
- this.eventSupport.fireBeforePackageAdded( newPkg );
+ }
+ try {
+ // we need to merge all byte[] first, so that the root classloader can resolve classes
+ for ( Package newPkg : newPkgs ) {
+ newPkg.checkValidity();
+ this.additionsSinceLock++;
+ this.eventSupport.fireBeforePackageAdded( newPkg );
+
+ Package pkg = this.pkgs.get( newPkg.getName() );
+ if ( pkg == null ) {
+ pkg = new Package( newPkg.getName() );
+
+ // @TODO we really should have a single root cache
+ pkg.setClassFieldAccessorCache( this.classFieldAccessorCache );
+ pkgs.put( pkg.getName(),
+ pkg );
+ }
+
+ // first merge anything related to classloader re-wiring
+ pkg.getDialectRuntimeRegistry().merge( newPkg.getDialectRuntimeRegistry(), this.rootClassLoader );
+ }
- Package pkg = this.pkgs.get( newPkg.getName() );
- if ( pkg == null ) {
- pkg = new Package( newPkg.getName() );
+ for ( Package newPkg : newPkgs ) {
+ Package pkg = this.pkgs.get( newPkg.getName() );
- // @TODO we really should have a single root cache
- pkg.setClassFieldAccessorCache( this.classFieldAccessorCache );
- pkgs.put( pkg.getName(),
- pkg );
- }
-
- // first merge anything related to classloader re-wiring
- pkg.getDialectRuntimeRegistry().merge( newPkg.getDialectRuntimeRegistry(), this.rootClassLoader );
- }
-
- for ( Package newPkg : newPkgs ) {
- Package pkg = this.pkgs.get( newPkg.getName() );
-
- if ( newPkg.getFunctions() != null ) {
- for ( Map.Entry<String, Function> entry : newPkg.getFunctions().entrySet() ) {
- pkg.addFunction( entry.getValue() );
- }
- }
- pkg.getClassFieldAccessorStore().merge( newPkg.getClassFieldAccessorStore() );
- pkg.getDialectRuntimeRegistry().onBeforeExecute();
-
- // we have to do this before the merging, as it does some classloader resolving
- TypeDeclaration lastType = null;
- try {
- // Add the type declarations to the RuleBase
- if ( newPkg.getTypeDeclarations() != null ) {
- // add type declarations
- for ( TypeDeclaration type : newPkg.getTypeDeclarations().values() ) {
- lastType = type;
- type.setTypeClass( this.rootClassLoader.loadClass( type.getTypeClassName() ) );
- // @TODO should we allow overrides? only if the class is not in use.
- if ( !this.classTypeDeclaration.containsKey( type.getTypeClass() ) ) {
- // add to rulebase list of type declarations
- this.classTypeDeclaration.put( type.getTypeClass(),
- type );
+ if ( newPkg.getFunctions() != null ) {
+ for ( Map.Entry<String, Function> entry : newPkg.getFunctions().entrySet() ) {
+ pkg.addFunction( entry.getValue() );
+ }
+ }
+ pkg.getClassFieldAccessorStore().merge( newPkg.getClassFieldAccessorStore() );
+ pkg.getDialectRuntimeRegistry().onBeforeExecute();
+
+ // we have to do this before the merging, as it does some classloader resolving
+ TypeDeclaration lastType = null;
+ try {
+ // Add the type declarations to the RuleBase
+ if ( newPkg.getTypeDeclarations() != null ) {
+ // add type declarations
+ for ( TypeDeclaration type : newPkg.getTypeDeclarations().values() ) {
+ lastType = type;
+ type.setTypeClass( this.rootClassLoader.loadClass( type.getTypeClassName() ) );
+ // @TODO should we allow overrides? only if the class is not in use.
+ if ( !this.classTypeDeclaration.containsKey( type.getTypeClass() ) ) {
+ // add to rulebase list of type declarations
+ this.classTypeDeclaration.put( type.getTypeClass(),
+ type );
+ }
}
}
+ } catch ( ClassNotFoundException e ) {
+ throw new RuntimeDroolsException( "unable to resolve Type Declaration class '" + lastType.getTypeName()+"'" );
+ }
+
+ // now merge the new package into the existing one
+ mergePackage( pkg,
+ newPkg );
+
+ // add the rules to the RuleBase
+ final Rule[] rules = newPkg.getRules();
+ for ( int i = 0; i < rules.length; ++i ) {
+ addRule( newPkg,
+ rules[i] );
}
- } catch ( ClassNotFoundException e ) {
- throw new RuntimeDroolsException( "unable to resolve Type Declaration class '" + lastType.getTypeName()+"'" );
- }
-
- // now merge the new package into the existing one
- mergePackage( pkg,
- newPkg );
-
- // add the rules to the RuleBase
- final Rule[] rules = newPkg.getRules();
- for ( int i = 0; i < rules.length; ++i ) {
- addRule( newPkg,
- rules[i] );
- }
-
- // add the flows to the RuleBase
- if ( newPkg.getRuleFlows() != null ) {
- final Map flows = newPkg.getRuleFlows();
- for ( final Object object : newPkg.getRuleFlows().entrySet() ) {
- final Entry flow = (Entry) object;
- this.processes.put( flow.getKey(),
- flow.getValue() );
+
+ // add the flows to the RuleBase
+ if ( newPkg.getRuleFlows() != null ) {
+ final Map flows = newPkg.getRuleFlows();
+ for ( final Object object : newPkg.getRuleFlows().entrySet() ) {
+ final Entry flow = (Entry) object;
+ this.processes.put( flow.getKey(),
+ flow.getValue() );
+ }
}
+
+ this.eventSupport.fireAfterPackageAdded( newPkg );
}
-
- this.eventSupport.fireAfterPackageAdded( newPkg );
+ } finally {
+ // only unlock if it had been acquired implicitely
+ if ( doUnlock ) {
+ unlock();
+ }
}
- // only unlock if it had been acquired implicitely
- if ( doUnlock ) {
- unlock();
- }
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java 2009-01-18 23:54:16 UTC (rev 24769)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java 2009-01-19 01:10:14 UTC (rev 24770)
@@ -19,6 +19,7 @@
import org.drools.spi.Activation;
public class ActivationCancelledEvent extends ActivationEvent {
+
/**
*
*/
More information about the jboss-svn-commits
mailing list