[jboss-svn-commits] JBL Code SVN: r30354 - in labs/jbossrules/trunk: drools-compiler/src/main/java/org/drools/lang and 6 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Nov 26 11:29:29 EST 2009
Author: tirelli
Date: 2009-11-26 11:29:28 -0500 (Thu, 26 Nov 2009)
New Revision: 30354
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DrlParser.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/Expander.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultExpander.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MultithreadTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/remoteapi/RestAPI.java
Log:
JBRULES-2262: several code cleanups
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DrlParser.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DrlParser.java 2009-11-26 09:02:08 UTC (rev 30353)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DrlParser.java 2009-11-26 16:29:28 UTC (rev 30354)
@@ -20,7 +20,6 @@
import java.io.InputStream;
import java.io.Reader;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.antlr.runtime.ANTLRInputStream;
@@ -49,12 +48,12 @@
*/
public class DrlParser {
- private static final String GENERIC_ERROR_MESSAGE = "Unknown error while parsing. This is a bug. Please contact the Development team.";
- private final List results = new ArrayList();
- private List<DroolsSentence> editorSentences = null;
- private Location location = new Location( Location.LOCATION_UNKNOWN );
- private DescrBuilderTree walker = null;
- private DRLLexer lexer = null;
+ private static final String GENERIC_ERROR_MESSAGE = "Unknown error while parsing. This is a bug. Please contact the Development team.";
+ private final List<DroolsError> results = new ArrayList<DroolsError>();
+ private List<DroolsSentence> editorSentences = null;
+ private Location location = new Location( Location.LOCATION_UNKNOWN );
+ private DescrBuilderTree walker = null;
+ private DRLLexer lexer = null;
public DrlParser() {
}
@@ -185,8 +184,7 @@
final String expanded = expander.expand( source );
if ( expander.hasErrors() ) {
String err = "";
- for ( Iterator iter = expander.getErrors().iterator(); iter.hasNext(); ) {
- ExpanderException ex = (ExpanderException) iter.next();
+ for ( ExpanderException ex : expander.getErrors() ) {
err = err + "\n Line:[" + ex.getLine() + "] " + ex.getMessage();
}
@@ -195,12 +193,6 @@
return expanded;
}
- private StringBuilder getDRLText(final InputStream is) throws IOException {
-
-
- return null;
- }
-
private StringBuilder getDRLText(final Reader reader) throws IOException {
final StringBuilder text = new StringBuilder();
@@ -219,13 +211,13 @@
* @return true if there were parser errors.
*/
public boolean hasErrors() {
- return this.results.size() > 0;
+ return !this.results.isEmpty();
}
/**
- * @return a list of ParserError's.
+ * @return a list of errors found while parsing. DroolsError: either ParserError, or ExpanderException
*/
- public List getErrors() {
+ public List<DroolsError> getErrors() {
return this.results;
}
@@ -274,15 +266,13 @@
/** Convert the antlr exceptions to drools parser exceptions */
private void makeErrorList(final DRLParser parser) {
- for ( final Iterator iter = lexer.getErrors().iterator(); iter.hasNext(); ) {
- final DroolsParserException recogErr = (DroolsParserException) iter.next();
+ for ( final DroolsParserException recogErr : lexer.getErrors() ) {
final ParserError err = new ParserError( recogErr.getMessage(),
recogErr.getLineNumber(),
recogErr.getColumn() );
this.results.add( err );
}
- for ( final Iterator iter = parser.getErrors().iterator(); iter.hasNext(); ) {
- final DroolsParserException recogErr = (DroolsParserException) iter.next();
+ for ( final DroolsParserException recogErr : parser.getErrors() ) {
final ParserError err = new ParserError( recogErr.getMessage(),
recogErr.getLineNumber(),
recogErr.getColumn() );
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2009-11-26 09:02:08 UTC (rev 30353)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2009-11-26 16:29:28 UTC (rev 30354)
@@ -106,35 +106,33 @@
*/
public class PackageBuilder {
- //private DialectRegistry dialectRegistry;
+ private Map<String, PackageRegistry> pkgRegistryMap;
- private Map<String, PackageRegistry> pkgRegistryMap;
+ private List<DroolsError> results;
- private List<DroolsError> results;
+ private final PackageBuilderConfiguration configuration;
- private PackageBuilderConfiguration configuration;
+ public static final RuleBuilder ruleBuilder = new RuleBuilder();
- public static final RuleBuilder ruleBuilder = new RuleBuilder();
-
/**
* Optional RuleBase for incremental live building
*/
- private ReteooRuleBase ruleBase;
+ private ReteooRuleBase ruleBase;
/**
* default dialect
*/
- private final String defaultDialect;
+ private final String defaultDialect;
- private CompositeClassLoader rootClassLoader;
+ private CompositeClassLoader rootClassLoader;
- private Map<String, Class< ? >> globals;
+ private Map<String, Class< ? >> globals;
- private Resource resource;
+ private Resource resource;
- private List<DSLTokenizedMappingFile> dslFiles;
+ private List<DSLTokenizedMappingFile> dslFiles;
- private TimeIntervalParser timeParser;
+ private TimeIntervalParser timeParser;
/**
* Use this when package is starting from scratch.
@@ -173,60 +171,20 @@
configuration );
}
- // /**
- // * This allows you to pass in a pre existing package, and a configuration
- // * (for instance to set the classloader).
- // *
- // * @param pkg
- // * A pre existing package (can be null if none exists)
- // * @param configuration
- // * Optional configuration for this builder.
- // */
- // public PackageBuilder(final Package pkg,
- // PackageBuilderConfiguration configuration) {
- // if ( configuration == null ) {
- // configuration = new PackageBuilderConfiguration();
- // }
- //
- // this.configuration = configuration;
- // this.results = new ArrayList();
- // this.pkg = pkg;
- // this.classFieldExtractorCache = ClassFieldAccessorCache.getInstance();
- //
- // if ( this.pkg != null ) {
- // ClassLoader cl = this.pkg.getDialectRuntimeRegistry().getClassLoader();
- // this.typeResolver = new ClassTypeResolver( new HashSet<String>( this.pkg.getImports().keySet() ),
- // cl );
- // // make an automatic import for the current package
- // this.typeResolver.addImport( this.pkg.getName() + ".*" );
- // } else {
- // // this.typeResolver = new ClassTypeResolver( new HashSet<String>(),
- // // this.configuration.getClassLoader() );
- // }
- //
- // this.dialectRegistry = this.configuration.buildDialectRegistry();
- //
- // this.dialect = this.dialectRegistry.getDialect( this.configuration.getDefaultDialect() );
- //
- // if ( this.pkg != null ) {
- // this.dialectRegistry.initAll( this );
- // }
- //
- // }
-
public PackageBuilder(Package pkg,
PackageBuilderConfiguration configuration) {
if ( configuration == null ) {
- configuration = new PackageBuilderConfiguration();
+ this.configuration = new PackageBuilderConfiguration();
+ } else {
+ this.configuration = configuration;
}
- this.configuration = configuration;
this.rootClassLoader = new CompositeClassLoader( this.configuration.getClassLoader() );
this.defaultDialect = this.configuration.getDefaultDialect();
this.pkgRegistryMap = new HashMap<String, PackageRegistry>();
- this.results = new ArrayList();
+ this.results = new ArrayList<DroolsError>();
PackageRegistry pkgRegistry = new PackageRegistry( this,
pkg );
@@ -240,9 +198,10 @@
public PackageBuilder(RuleBase ruleBase,
PackageBuilderConfiguration configuration) {
if ( configuration == null ) {
- configuration = new PackageBuilderConfiguration();
+ this.configuration = new PackageBuilderConfiguration();
+ } else {
+ this.configuration = configuration;
}
- this.configuration = configuration;
if ( ruleBase != null ) {
this.rootClassLoader = ((InternalRuleBase) ruleBase).getRootClassLoader();
@@ -255,7 +214,7 @@
this.defaultDialect = this.configuration.getDefaultDialect();
this.pkgRegistryMap = new HashMap<String, PackageRegistry>();
- this.results = new ArrayList();
+ this.results = new ArrayList<DroolsError>();
this.ruleBase = (ReteooRuleBase) ruleBase;
@@ -522,11 +481,11 @@
} else {
reader.setClassLoader( this.configuration.getClassLoader() );
}
- ChangeSet chageSet = reader.read( resource.getReader() );
- if ( chageSet == null ) {
+ ChangeSet changeSet = reader.read( resource.getReader() );
+ if ( changeSet == null ) {
// @TODO should log an error
}
- for ( Resource nestedResource : chageSet.getResourcesAdded() ) {
+ for ( Resource nestedResource : changeSet.getResourcesAdded() ) {
InternalResource iNestedResourceResource = (InternalResource) nestedResource;
if ( iNestedResourceResource.isDirectory() ) {
this.resourceDirectories.add( iNestedResourceResource );
@@ -1267,7 +1226,7 @@
* compiling phase
*/
public boolean hasErrors() {
- return this.results.size() > 0;
+ return !this.results.isEmpty();
}
/**
@@ -1275,7 +1234,7 @@
* the package.
*/
public PackageBuilderErrors getErrors() {
- return new PackageBuilderErrors( (DroolsError[]) this.results.toArray( new DroolsError[this.results.size()] ) );
+ return new PackageBuilderErrors( this.results.toArray( new DroolsError[this.results.size()] ) );
}
/**
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/Expander.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/Expander.java 2009-11-26 09:02:08 UTC (rev 30353)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/Expander.java 2009-11-26 16:29:28 UTC (rev 30354)
@@ -76,7 +76,7 @@
* Returns the list of errors from the last expansion made
* @return A list of <code>ExpanderException</code>
*/
- public List getErrors();
+ public List<ExpanderException> getErrors();
/**
* Returns true in case the last expansion had any errors
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultExpander.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultExpander.java 2009-11-26 09:02:08 UTC (rev 30353)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DefaultExpander.java 2009-11-26 16:29:28 UTC (rev 30354)
@@ -21,14 +21,12 @@
import java.io.Reader;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.drools.compiler.DroolsError;
import org.drools.lang.Expander;
import org.drools.lang.ExpanderException;
@@ -45,23 +43,23 @@
// Be EXTREMELLY careful if you decide to change bellow regexp's
//
// bellow regexp is used to find and parse rule parts: header, LHS, RHS, trailer, etc
- private static final String rulesExpr = "(^\\s*rule.*?$.*?^\\s*when.*?)$(.*?)(^\\s*then.*?$)(.*?)(^\\s*end)";
+ private static final String rulesExpr = "(^\\s*rule.*?$.*?^\\s*when.*?)$(.*?)(^\\s*then.*?$)(.*?)(^\\s*end)";
// bellow regexp is used to find and parse query parts: header, condition, trailer
- private static final String queryExpr = "(^\\s*query.*?)$(.*?)(^\\s*end)";
+ private static final String queryExpr = "(^\\s*query.*?)$(.*?)(^\\s*end)";
// bellow we combine and compile above expressions into a pattern object
- private static final Pattern finder = Pattern.compile( "(" + rulesExpr + "|" + queryExpr + ")",
- Pattern.DOTALL | Pattern.MULTILINE );
+ private static final Pattern finder = Pattern.compile( "(" + rulesExpr + "|" + queryExpr + ")",
+ Pattern.DOTALL | Pattern.MULTILINE );
// bellow pattern is used to find a pattern's constraint list
- private static final Pattern patternFinder = Pattern.compile( "\\((.*?)\\)" );
+ private static final Pattern patternFinder = Pattern.compile( "\\((.*?)\\)" );
- private final Map mappings = new HashMap();
- private final List keywords = new LinkedList();
- private final List condition = new LinkedList();
- private final List consequence = new LinkedList();
- private final List cleanup = new LinkedList();
+ private final Map<String, DSLMapping> mappings = new HashMap<String, DSLMapping>();
+ private final List<DSLMappingEntry> keywords = new LinkedList<DSLMappingEntry>();
+ private final List<DSLMappingEntry> condition = new LinkedList<DSLMappingEntry>();
+ private final List<DSLMappingEntry> consequence = new LinkedList<DSLMappingEntry>();
+ private final List<DSLMappingEntry> cleanup = new LinkedList<DSLMappingEntry>();
- private List errors = Collections.EMPTY_LIST;
+ private List<ExpanderException> errors = Collections.emptyList();
/**
* Creates a new DefaultExpander
@@ -69,10 +67,10 @@
public DefaultExpander() {
this.cleanup.add( new AntlrDSLMappingEntry( DSLMappingEntry.KEYWORD,
DSLMappingEntry.EMPTY_METADATA,
- "expander {name}",
- "",
- "expander (.*?)",
- "") );
+ "expander {name}",
+ "",
+ "expander (.*?)",
+ "" ) );
}
/**
@@ -82,13 +80,12 @@
public void addDSLMapping(final DSLMapping mapping) {
this.mappings.put( mapping.getIdentifier(),
mapping );
- for ( final Iterator it = mapping.getEntries().iterator(); it.hasNext(); ) {
- final DSLMappingEntry entry = (DSLMappingEntry) it.next();
- if ( DSLMappingEntry.KEYWORD.equals(entry.getSection()) ) {
+ for ( DSLMappingEntry entry : mapping.getEntries() ) {
+ if ( DSLMappingEntry.KEYWORD.equals( entry.getSection() ) ) {
this.keywords.add( entry );
- } else if ( DSLMappingEntry.CONDITION.equals(entry.getSection()) ) {
+ } else if ( DSLMappingEntry.CONDITION.equals( entry.getSection() ) ) {
this.condition.add( entry );
- } else if ( DSLMappingEntry.CONSEQUENCE.equals(entry.getSection()) ) {
+ } else if ( DSLMappingEntry.CONSEQUENCE.equals( entry.getSection() ) ) {
this.consequence.add( entry );
} else {
// if any, then add to them both condition and consequence
@@ -126,9 +123,7 @@
private StringBuffer expandConstructions(final String drl) {
// parse and expand specific areas
final Matcher m = finder.matcher( drl );
-
-
-
+
final StringBuffer buf = new StringBuffer();
while ( m.find() ) {
final StringBuilder expanded = new StringBuilder();
@@ -138,18 +133,21 @@
String headerFragment = m.group( 2 );
expanded.append( headerFragment ); // adding rule header and attributes
String lhsFragment = m.group( 3 );
- expanded.append( this.expandLHS( lhsFragment, countNewlines( headerFragment ) + 1 ) ); // adding expanded LHS
- String thenFragment = m.group( 4 );
-
+ expanded.append( this.expandLHS( lhsFragment,
+ countNewlines( headerFragment ) + 1 ) ); // adding expanded LHS
+ String thenFragment = m.group( 4 );
+
expanded.append( thenFragment ); // adding "then" header
- expanded.append( this.expandRHS( m.group( 5 ), countNewlines( headerFragment + lhsFragment + thenFragment ) + 1 ) ); // adding expanded RHS
+ expanded.append( this.expandRHS( m.group( 5 ),
+ countNewlines( headerFragment + lhsFragment + thenFragment ) + 1 ) ); // adding expanded RHS
expanded.append( m.group( 6 ) ); // adding rule trailer
expanded.append( "\n" );
} else if ( constr.startsWith( "query" ) ) {
// match query
String fragment = m.group( 7 );
expanded.append( fragment ); // adding query header and attributes
- expanded.append( this.expandLHS( m.group( 8 ), countNewlines( fragment ) + 1 ) ); // adding expanded LHS
+ expanded.append( this.expandLHS( m.group( 8 ),
+ countNewlines( fragment ) + 1 ) ); // adding expanded LHS
expanded.append( m.group( 9 ) ); // adding query trailer
expanded.append( "\n" );
} else {
@@ -169,7 +167,9 @@
char[] cs = drl.toCharArray();
int count = 0;
for ( int i = 0; i < cs.length; i++ ) {
- { if (cs[i] == '\n') count++; }
+ {
+ if ( cs[i] == '\n' ) count++;
+ }
}
return count;
}
@@ -182,8 +182,7 @@
*/
private String cleanupExpressions(String drl) {
// execute cleanup
- for ( final Iterator it = this.cleanup.iterator(); it.hasNext(); ) {
- final DSLMappingEntry entry = (DSLMappingEntry) it.next();
+ for ( final DSLMappingEntry entry : this.cleanup ) {
drl = entry.getKeyPattern().matcher( drl ).replaceAll( entry.getValuePattern() );
}
return drl;
@@ -197,8 +196,7 @@
*/
private String expandKeywords(String drl) {
// apply all keywords templates
- for ( final Iterator it = this.keywords.iterator(); it.hasNext(); ) {
- final DSLMappingEntry entry = (DSLMappingEntry) it.next();
+ for ( final DSLMappingEntry entry : this.keywords ) {
drl = entry.getKeyPattern().matcher( drl ).replaceAll( entry.getValuePattern() );
}
return drl;
@@ -210,7 +208,8 @@
* @param lineOffset
* @return
*/
- private String expandLHS(final String lhs, int lineOffset) {
+ private String expandLHS(final String lhs,
+ int lineOffset) {
final StringBuilder buf = new StringBuilder();
final String[] lines = lhs.split( "\n" ); // since we assembled the string, we know line breaks are \n
final String[] expanded = new String[lines.length]; // buffer for expanded lines
@@ -228,19 +227,19 @@
" " );
} else { // regular expansion
// expand the expression
- for ( final Iterator it = this.condition.iterator(); it.hasNext(); ) {
- final DSLMappingEntry entry = (DSLMappingEntry) it.next();
+ for ( final DSLMappingEntry entry : this.condition ) {
String vp = entry.getValuePattern();
-// System.out.println("toExpand, st: " + expanded[lastExpanded] + "|");
-// System.out.println("kp: " + entry.getKeyPattern());
-// System.out.println("vp: " + vp);
- expanded[lastExpanded] = entry.getKeyPattern().matcher(expanded[lastExpanded]).replaceAll(vp);
+ // System.out.println("toExpand, st: " + expanded[lastExpanded] + "|");
+ // System.out.println("kp: " + entry.getKeyPattern());
+ // System.out.println("vp: " + vp);
+ expanded[lastExpanded] = entry.getKeyPattern().matcher( expanded[lastExpanded] ).replaceAll( vp );
}
// do we need to report errors for that?
if ( lines[i].equals( expanded[lastExpanded] ) ) {
// report error
- this.addError( new ExpanderException( "Unable to expand: " + lines[i].replaceAll( "[\n\r]", "" ).trim(),
+ this.addError( new ExpanderException( "Unable to expand: " + lines[i].replaceAll( "[\n\r]",
+ "" ).trim(),
i + lineOffset ) );
}
// but if the original starts with a "-", it means we need to add it
@@ -260,10 +259,10 @@
if ( lastMatchStart > -1 ) {
// rebuilding previous pattern structure
expanded[lastPattern] = expanded[lastPattern].substring( 0,
- lastMatchStart ) + "( " + constraints + ((constraints.length() == 0) ? "" : ", ") + expanded[lastExpanded].trim() + " )" + expanded[lastPattern].substring( lastMatchEnd );
+ lastMatchStart ) + "( " + constraints + ((constraints.length() == 0) ? "" : ", ") + expanded[lastExpanded].trim() + " )"
+ + expanded[lastPattern].substring( lastMatchEnd );
} else {
// error, pattern not found to add constraint to
- // TODO: can we report character position?
this.addError( new ExpanderException( "No pattern was found to add the constraint to: " + lines[i].trim(),
i + lineOffset ) );
}
@@ -287,7 +286,8 @@
* @param lhs
* @return
*/
- private String expandRHS(final String lhs, int lineOffset) {
+ private String expandRHS(final String lhs,
+ int lineOffset) {
final StringBuilder buf = new StringBuilder();
final String[] lines = lhs.split( "\n" ); // since we assembled the string, we know line breaks are \n
for ( int i = 0; i < lines.length; i++ ) {
@@ -300,8 +300,7 @@
"" ) );
} else { // regular expansions
String expanded = lines[i];
- for ( final Iterator it = this.consequence.iterator(); it.hasNext(); ) {
- final DSLMappingEntry entry = (DSLMappingEntry) it.next();
+ for ( final DSLMappingEntry entry : this.consequence ) {
expanded = entry.getKeyPattern().matcher( expanded ).replaceAll( entry.getValuePattern() );
}
buf.append( expanded );
@@ -314,7 +313,7 @@
}
buf.append( "\n" );
}
- if( lines.length == 0 ) {
+ if ( lines.length == 0 ) {
buf.append( "\n" );
}
return buf.toString();
@@ -332,9 +331,9 @@
return buf.toString();
}
- private void addError(final DroolsError error) {
+ private void addError(final ExpanderException error) {
if ( this.errors == Collections.EMPTY_LIST ) {
- this.errors = new LinkedList();
+ this.errors = new LinkedList<ExpanderException>();
}
this.errors.add( error );
}
@@ -342,7 +341,7 @@
/**
* @inheritDoc
*/
- public List getErrors() {
+ public List<ExpanderException> getErrors() {
return this.errors;
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MultithreadTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MultithreadTest.java 2009-11-26 09:02:08 UTC (rev 30353)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MultithreadTest.java 2009-11-26 16:29:28 UTC (rev 30354)
@@ -38,10 +38,8 @@
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.StatelessSession;
-import org.drools.compiler.DrlParser;
import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilder;
-import org.drools.lang.descr.PackageDescr;
import org.drools.rule.Package;
/**
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-11-26 09:02:08 UTC (rev 30353)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2009-11-26 16:29:28 UTC (rev 30354)
@@ -21,7 +21,6 @@
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
-import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.Collection;
@@ -101,16 +100,13 @@
private transient ObjectHashSet statefulSessions;
- // indexed used to track invariant lock
- private int lastAquiredLock;
-
// lock for entire rulebase, used for dynamic updates
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
/**
* This lock is used when adding to, or reading the <field>statefulSessions</field>
*/
- private final ReentrantLock statefuleSessionLock = new ReentrantLock();
+ private final ReentrantLock statefulSessionLock = new ReentrantLock();
private int additionsSinceLock;
private int removalsSinceLock;
@@ -132,7 +128,7 @@
public synchronized int nextWorkingMemoryCounter() {
return this.workingMemoryCounter++;
}
-
+
public synchronized long getWorkingMemoryCounter() {
return this.workingMemoryCounter;
}
@@ -145,7 +141,7 @@
public AbstractRuleBase(final String id,
final RuleBaseConfiguration config,
final FactHandleFactory factHandleFactory) {
-
+
this.config = (config != null) ? config : new RuleBaseConfiguration();
this.config.makeImmutable();
createRulebaseId( id );
@@ -168,15 +164,15 @@
}
private void createRulebaseId(final String id) {
- if( id != null ) {
+ if ( id != null ) {
this.id = id;
} else {
- String key = "";
- if( config.isMBeansEnabled() ) {
+ String key = "";
+ if ( config.isMBeansEnabled() ) {
DroolsManagementAgent agent = DroolsManagementAgent.getInstance();
key = String.valueOf( agent.getNextKnowledgeBaseId() );
}
- this.id = "default"+key;
+ this.id = "default" + key;
}
}
@@ -358,15 +354,15 @@
}
public void disposeStatefulSession(final StatefulSession statefulSession) {
- try {
- statefuleSessionLock.lock();
+ statefulSessionLock.lock();
+ try {
this.statefulSessions.remove( statefulSession );
for ( Object listener : statefulSession.getRuleBaseUpdateListeners() ) {
this.removeEventListener( (RuleBaseEventListener) listener );
}
} finally {
- statefuleSessionLock.unlock();
+ statefulSessionLock.unlock();
}
}
@@ -428,11 +424,11 @@
this.lock.writeLock().unlock();
this.eventSupport.fireAfterRuleBaseUnlocked();
}
-
+
public void readLock() {
this.lock.readLock().lock();
}
-
+
public void readUnlock() {
this.lock.readLock().unlock();
}
@@ -788,12 +784,12 @@
}
public void addStatefulSession(final StatefulSession statefulSession) {
- try {
- statefuleSessionLock.lock();
+ statefulSessionLock.lock();
+ try {
this.statefulSessions.add( statefulSession );
} finally {
- statefuleSessionLock.unlock();
+ statefulSessionLock.unlock();
}
}
@@ -803,31 +799,25 @@
}
public StatefulSession[] getStatefulSessions() {
- final StatefulSession[] copyOfSessions;
+ statefulSessionLock.lock();
try {
- statefuleSessionLock.lock();
- copyOfSessions = new StatefulSession[this.statefulSessions.size()];
-
+ final StatefulSession[] copyOfSessions = new StatefulSession[this.statefulSessions.size()];
this.statefulSessions.toArray( copyOfSessions );
+ return copyOfSessions;
} finally {
- statefuleSessionLock.unlock();
+ statefulSessionLock.unlock();
}
-
- return copyOfSessions;
}
public InternalWorkingMemory[] getWorkingMemories() {
- final InternalWorkingMemory[] copyOfMemories;
+ statefulSessionLock.lock();
try {
- statefuleSessionLock.lock();
- copyOfMemories = new InternalWorkingMemory[this.statefulSessions.size()];
-
+ final InternalWorkingMemory[] copyOfMemories = new InternalWorkingMemory[this.statefulSessions.size()];
this.statefulSessions.toArray( copyOfMemories );
+ return copyOfMemories;
} finally {
- statefuleSessionLock.unlock();
+ statefulSessionLock.unlock();
}
-
- return copyOfMemories;
}
public RuleBaseConfiguration getConfiguration() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java 2009-11-26 09:02:08 UTC (rev 30353)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java 2009-11-26 16:29:28 UTC (rev 30354)
@@ -109,6 +109,7 @@
// Instance methods
// ------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
super.readExternal( in );
@@ -182,8 +183,6 @@
final PropagationContext context,
final ObjectTypeConf objectTypeConf,
final InternalWorkingMemory workingMemory) {
- final Object object = handle.getObject();
-
ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
if ( cachedNodes == null ) {
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 2009-11-26 09:02:08 UTC (rev 30353)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java 2009-11-26 16:29:28 UTC (rev 30354)
@@ -103,7 +103,6 @@
public BuildContext(final InternalRuleBase rulebase,
final ReteooBuilder.IdGenerator idGenerator) {
this.rulebase = rulebase;
- this.rule = rule;
this.idGenerator = idGenerator;
@@ -225,7 +224,7 @@
*/
public InternalWorkingMemory[] getWorkingMemories() {
if ( this.workingMemories == null ) {
- this.workingMemories = (InternalWorkingMemory[]) this.rulebase.getWorkingMemories();
+ this.workingMemories = this.rulebase.getWorkingMemories();
}
return this.workingMemories;
}
Modified: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/remoteapi/RestAPI.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/remoteapi/RestAPI.java 2009-11-26 09:02:08 UTC (rev 30353)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/remoteapi/RestAPI.java 2009-11-26 16:29:28 UTC (rev 30354)
@@ -20,8 +20,6 @@
import org.drools.repository.remoteapi.Response.Binary;
import org.drools.repository.remoteapi.Response.Text;
-import com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt.GetOpt;
-
/**
* This provides a simple REST style remote friendly API.
*
More information about the jboss-svn-commits
mailing list