[jboss-svn-commits] JBL Code SVN: r24247 - in labs/jbossrules/trunk: drools-api/src/main/java/org/drools/builder and 13 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Dec 5 06:30:48 EST 2008
Author: mark.proctor at jboss.com
Date: 2008-12-05 06:30:47 -0500 (Fri, 05 Dec 2008)
New Revision: 24247
Added:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/ResourceType.java
Removed:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/KnowledgeType.java
Modified:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgent.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentConfiguration.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/KnowledgeBuilder.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeListener.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeNotifier.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/builder/impl/KnowledgeBuilderImpl.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/AddHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ModifyHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/RemoveHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ResourceHandler.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/api/KnowledgeBuilderTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/api/KnowledgeSessionTest.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/ExecutionFlowControlTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ProcessWorkItemTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StreamsTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/TruthMaintenanceTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/InternalResource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/BaseResource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ByteArrayResource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/KnowledgeResource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceProviderImpl.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/ChangeSetTest.java
labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/SpreadsheetIntegrationTest.java
Log:
JBRULES-1885 Update KnowledgeAgent to use new Resource api
-should now be thread safe
JBRULES-1874 Create Resource Framework
JBRULES-1875 Load ChangeSet XML files for multiple resources
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgent.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgent.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgent.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -42,4 +42,6 @@
* The KnowledgeBase
*/
KnowledgeBase getKnowledgeBase();
+
+ void monitorResourceChangeEvents(boolean monitor);
}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentConfiguration.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentConfiguration.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -2,6 +2,12 @@
import org.drools.PropertiesConfiguration;
+/**
+ * drools.agent.scanResources = <true|false>
+ * drools.agent.newInstance = <true|false>
+ * drools.agent.monitorChangeSetEvents = <true|false>
+ *
+ */
public interface KnowledgeAgentConfiguration extends PropertiesConfiguration {
}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/KnowledgeBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/KnowledgeBuilder.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/KnowledgeBuilder.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -84,14 +84,14 @@
* @param type
*/
void add(Resource resource,
- KnowledgeType type);
+ ResourceType type);
/**
* A a resource of the KnowledgeType from a given URL, using the provided ResourceConfiguration.
* Currently only only decision tables use this, via the DecisionTableResourceConfiguration class.
*/
void add(Resource resource,
- KnowledgeType type,
+ ResourceType type,
ResourceConfiguration configuration);
/**
Deleted: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/KnowledgeType.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/KnowledgeType.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/KnowledgeType.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -1,27 +0,0 @@
-package org.drools.builder;
-
-public enum KnowledgeType {
- /** Drools Rule Language */
- DRL,
-
- /** Drools XML Rule Language */
- XDRL,
-
- /** Drools DSL */
- DSL,
-
- /** Drools DSL Rule */
- DSLR,
-
- /** Drools Rule Flow Language */
- DRF,
-
- /** Decision Table */
- DTABLE,
-
- /** Binary Package */
- PKG,
-
- /** ChangeSet */
- ChangeSet;
-}
Copied: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/ResourceType.java (from rev 24245, labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/KnowledgeType.java)
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/ResourceType.java (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/ResourceType.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -0,0 +1,27 @@
+package org.drools.builder;
+
+public enum ResourceType {
+ /** Drools Rule Language */
+ DRL,
+
+ /** Drools XML Rule Language */
+ XDRL,
+
+ /** Drools DSL */
+ DSL,
+
+ /** Drools DSL Rule */
+ DSLR,
+
+ /** Drools Rule Flow Language */
+ DRF,
+
+ /** Decision Table */
+ DTABLE,
+
+ /** Binary Package */
+ PKG,
+
+ /** ChangeSet */
+ ChangeSet;
+}
Property changes on: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/ResourceType.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeListener.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeListener.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeListener.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -6,5 +6,5 @@
import org.drools.ChangeSet;
public interface ResourceChangeListener {
- void resourceChanged(ChangeSet changeSet);
+ void resourcesChanged(ChangeSet changeSet);
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeNotifier.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeNotifier.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeNotifier.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -20,5 +20,9 @@
Collection<ResourceChangeMonitor> getResourceChangeMonitor();
- public void publishKnowledgeBaseChangeSet(ChangeSet changeSet);
+ void publishKnowledgeBaseChangeSet(ChangeSet changeSet);
+
+ void start();
+
+ void stop();
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/builder/impl/KnowledgeBuilderImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/builder/impl/KnowledgeBuilderImpl.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/builder/impl/KnowledgeBuilderImpl.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -9,7 +9,7 @@
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.builder.ResourceConfiguration;
import org.drools.compiler.PackageBuilder;
import org.drools.definition.KnowledgePackage;
@@ -26,12 +26,12 @@
this.pkgBuilder = pkgBuilder;
}
- public void add(Resource resource, KnowledgeType type) {
+ public void add(Resource resource, ResourceType type) {
pkgBuilder.addKnowledgeResource( resource, type, null ) ;
}
public void add(Resource resource,
- KnowledgeType type,
+ ResourceType type,
ResourceConfiguration configuration) {
pkgBuilder.addKnowledgeResource( resource, type, configuration );
}
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 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -43,7 +43,7 @@
import org.drools.base.ClassFieldAccessorCache;
import org.drools.base.ClassFieldAccessorStore;
import org.drools.builder.DecisionTableConfiguration;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.builder.ResourceConfiguration;
import org.drools.common.InternalRuleBase;
import org.drools.commons.jci.problems.CompilationProblem;
@@ -448,38 +448,38 @@
}
public void addKnowledgeResource(Resource resource,
- KnowledgeType type,
+ ResourceType type,
ResourceConfiguration configuration) {
try {
switch ( type ) {
case DRL : {
- ((InternalResource)resource).setKnowledgeType( type );
+ ((InternalResource)resource).setResourceType( type );
addPackageFromDrl( resource );
break;
}
case DSLR : {
- ((InternalResource)resource).setKnowledgeType( type );
+ ((InternalResource)resource).setResourceType( type );
addPackageFromDslr( resource );
break;
}
case DSL : {
- ((InternalResource)resource).setKnowledgeType( type );
+ ((InternalResource)resource).setResourceType( type );
addDsl( resource );
break;
}
case XDRL : {
- ((InternalResource)resource).setKnowledgeType( type );
+ ((InternalResource)resource).setResourceType( type );
addPackageFromXml( resource );
break;
}
case DRF : {
- ((InternalResource)resource).setKnowledgeType( type );
+ ((InternalResource)resource).setResourceType( type );
addProcessFromXml( resource );
break;
}
case DTABLE : {
- ((InternalResource)resource).setKnowledgeType( type );
+ ((InternalResource)resource).setResourceType( type );
DecisionTableConfiguration dtableConfiguration = (DecisionTableConfiguration) configuration;
String string = DecisionTableFactory.loadFromInputStream( resource.getInputStream(),
@@ -495,7 +495,7 @@
break;
}
case ChangeSet : {
- ((InternalResource)resource).setKnowledgeType( type );
+ ((InternalResource)resource).setResourceType( type );
XmlChangeSetReader reader = new XmlChangeSetReader( this.configuration.getSemanticModules() );
if ( resource instanceof ClassPathResource ) {
reader.setClassLoader( ((ClassPathResource )resource).getClassLoader() );
@@ -511,11 +511,11 @@
if ( iNestedResourceResource.isDirectory() ) {
this.resourceDirectories.add( iNestedResourceResource );
for ( Resource childResource : iNestedResourceResource.listResources() ) {
- ((InternalResource)childResource).setKnowledgeType( iNestedResourceResource.getKnowledgeType() );
- addKnowledgeResource( childResource, iNestedResourceResource.getKnowledgeType(), iNestedResourceResource.getConfiguration() );
+ ((InternalResource)childResource).setResourceType( iNestedResourceResource.getResourceType() );
+ addKnowledgeResource( childResource, iNestedResourceResource.getResourceType(), iNestedResourceResource.getConfiguration() );
}
} else {
- addKnowledgeResource( iNestedResourceResource, iNestedResourceResource.getKnowledgeType(), iNestedResourceResource.getConfiguration() );
+ addKnowledgeResource( iNestedResourceResource, iNestedResourceResource.getResourceType(), iNestedResourceResource.getConfiguration() );
}
}
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/AddHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/AddHandler.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/AddHandler.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -6,7 +6,7 @@
import java.util.HashSet;
import org.drools.ChangeSet;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.io.Resource;
import org.drools.io.impl.ChangeSetImpl;
import org.drools.io.impl.ClassPathResource;
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ModifyHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ModifyHandler.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ModifyHandler.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -6,7 +6,7 @@
import java.util.HashSet;
import org.drools.ChangeSet;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.io.Resource;
import org.drools.io.impl.ChangeSetImpl;
import org.drools.io.impl.ClassPathResource;
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/RemoveHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/RemoveHandler.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/RemoveHandler.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -6,7 +6,7 @@
import java.util.HashSet;
import org.drools.ChangeSet;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.io.Resource;
import org.drools.io.impl.ChangeSetImpl;
import org.drools.io.impl.ClassPathResource;
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ResourceHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ResourceHandler.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ResourceHandler.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -3,7 +3,7 @@
import java.util.Collection;
import java.util.HashSet;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.io.InternalResource;
import org.drools.io.Resource;
import org.drools.io.impl.ClassPathResource;
@@ -62,7 +62,7 @@
resource = new UrlResource( src );
}
- resource.setKnowledgeType( KnowledgeType.valueOf( type ) );
+ resource.setResourceType( ResourceType.valueOf( type ) );
return resource;
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/api/KnowledgeBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/api/KnowledgeBuilderTest.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/api/KnowledgeBuilderTest.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -7,7 +7,7 @@
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.definition.KnowledgePackage;
import org.drools.definition.process.Process;
import org.drools.definition.rule.Rule;
@@ -33,7 +33,7 @@
str += "when\n";
str += "then\n";
str += "end\n";
- builder.add( ResourceFactory.newByteArrayResource( str.getBytes() ), KnowledgeType.DRL );
+ builder.add( ResourceFactory.newByteArrayResource( str.getBytes() ), ResourceType.DRL );
str = "package org.test2\n";
str += "rule rule3\n";
@@ -44,7 +44,7 @@
str += "when\n";
str += "then\n";
str += "end\n";
- builder.add( ResourceFactory.newByteArrayResource( str.getBytes() ), KnowledgeType.DRL );
+ builder.add( ResourceFactory.newByteArrayResource( str.getBytes() ), ResourceType.DRL );
Collection<KnowledgePackage> pkgs = builder.getKnowledgePackages();
assertNotNull( pkgs );
@@ -78,7 +78,7 @@
str += " <nodes><start id=\"1\" name=\"Start\" /><end id=\"2\" name=\"End\" /></nodes>\n";
str += " <connections><connection from=\"1\" to=\"2\"/></connections>";
str += "</process>";
- builder.add(ResourceFactory.newByteArrayResource( str.getBytes() ), KnowledgeType.DRF );
+ builder.add(ResourceFactory.newByteArrayResource( str.getBytes() ), ResourceType.DRF );
str = "";
str += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
@@ -88,7 +88,7 @@
str += " <nodes><start id=\"1\" name=\"Start\" /><end id=\"2\" name=\"End\" /></nodes>\n";
str += " <connections><connection from=\"1\" to=\"2\"/></connections>";
str += "</process>";
- builder.add( ResourceFactory.newByteArrayResource( str.getBytes() ), KnowledgeType.DRF );
+ builder.add( ResourceFactory.newByteArrayResource( str.getBytes() ), ResourceType.DRF );
Collection<KnowledgePackage> pkgs = builder.getKnowledgePackages();
assertNotNull( pkgs );
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/api/KnowledgeSessionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/api/KnowledgeSessionTest.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/api/KnowledgeSessionTest.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -7,7 +7,7 @@
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.definition.KnowledgePackage;
import org.drools.io.ResourceFactory;
@@ -25,7 +25,7 @@
str += "when\n";
str += "then\n";
str += "end\n";
- builder.add( ResourceFactory.newByteArrayResource( str.getBytes() ), KnowledgeType.DRL );
+ builder.add( ResourceFactory.newByteArrayResource( str.getBytes() ), ResourceType.DRL );
str = "package org.test2\n";
str += "rule rule3\n";
@@ -36,7 +36,7 @@
str += "when\n";
str += "then\n";
str += "end\n";
- builder.add( ResourceFactory.newByteArrayResource( str.getBytes() ), KnowledgeType.DRL );
+ builder.add( ResourceFactory.newByteArrayResource( str.getBytes() ), ResourceType.DRL );
Collection<KnowledgePackage> pkgs = builder.getKnowledgePackages();
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 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DslTest.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -19,7 +19,7 @@
import org.drools.WorkingMemory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.compiler.PackageBuilder;
import org.drools.definition.KnowledgePackage;
import org.drools.io.ResourceFactory;
@@ -56,9 +56,9 @@
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "test_expander.dsl", getClass() ),
- KnowledgeType.DSL );
+ ResourceType.DSL );
kbuilder.add( ResourceFactory.newClassPathResource( "rule_with_expander_dsl.dslr", getClass() ) ,
- KnowledgeType.DSLR );
+ ResourceType.DSLR );
assertFalse( kbuilder.hasErrors() );
@@ -99,9 +99,9 @@
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "test_expander.dsl", getClass() ),
- KnowledgeType.DSL );
+ ResourceType.DSL );
kbuilder.add( ResourceFactory.newClassPathResource( "rule_with_expander_dsl_more.dslr", getClass() ) ,
- KnowledgeType.DSLR );
+ ResourceType.DSLR );
assertFalse( kbuilder.hasErrors() );
@@ -158,9 +158,9 @@
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "test_expander.dsl", getClass() ),
- KnowledgeType.DSL );
+ ResourceType.DSL );
kbuilder.add( ResourceFactory.newReaderResource( new StringReader( DSL) ) ,
- KnowledgeType.DSLR );
+ ResourceType.DSLR );
assertFalse( kbuilder.hasErrors() ); // trying to expand Cheese() pattern
@@ -188,9 +188,9 @@
public void testDSLWithIndividualConstraintMappings() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "test_dslWithIndividualConstraints.dsl", getClass() ),
- KnowledgeType.DSL );
+ ResourceType.DSL );
kbuilder.add( ResourceFactory.newClassPathResource( "test_dslWithIndividualConstraints.dslr", getClass() ) ,
- KnowledgeType.DSLR );
+ ResourceType.DSLR );
assertFalse( kbuilder.hasErrors() );
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 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ExecutionFlowControlTest.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -27,7 +27,7 @@
import org.drools.WorkingMemory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.common.DefaultAgenda;
import org.drools.common.InternalWorkingMemoryActions;
import org.drools.common.RuleFlowGroupImpl;
@@ -516,7 +516,7 @@
public void testAgendaGroups() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newClassPathResource( "test_AgendaGroups.drl", getClass() ), KnowledgeType.DRL );
+ kbuilder.add( ResourceFactory.newClassPathResource( "test_AgendaGroups.drl", getClass() ), ResourceType.DRL );
assertFalse( kbuilder.hasErrors() );
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ProcessWorkItemTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ProcessWorkItemTest.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ProcessWorkItemTest.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -12,7 +12,7 @@
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.definition.KnowledgePackage;
import org.drools.io.ResourceFactory;
import org.drools.process.core.context.variable.VariableScope;
@@ -80,7 +80,7 @@
" </connections>\n" +
"\n" +
"</process>");
- kbuilder.add( ResourceFactory.newReaderResource( source ), KnowledgeType.DRF );
+ kbuilder.add( ResourceFactory.newReaderResource( source ), ResourceType.DRF );
Collection<KnowledgePackage> kpkgs = kbuilder.getKnowledgePackages();
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -24,7 +24,7 @@
import org.drools.base.ReferenceOriginalGlobalExporter;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.compiler.PackageBuilder;
import org.drools.definition.KnowledgePackage;
import org.drools.impl.ParametersImpl;
@@ -395,7 +395,7 @@
private StatelessKnowledgeSession getSession2(String fileName) throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newClassPathResource( fileName, getClass() ), KnowledgeType.DRL );
+ kbuilder.add( ResourceFactory.newClassPathResource( fileName, getClass() ), ResourceType.DRL );
if (kbuilder.hasErrors() ) {
System.out.println( kbuilder.getErrors() );
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StreamsTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StreamsTest.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StreamsTest.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -32,7 +32,7 @@
import org.drools.StockTick;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.common.InternalFactHandle;
import org.drools.compiler.DroolsParserException;
import org.drools.io.ResourceFactory;
@@ -67,7 +67,7 @@
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( fileName,
getClass() ),
- KnowledgeType.DRL );
+ ResourceType.DRL );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
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 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/TruthMaintenanceTest.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -21,7 +21,7 @@
import org.drools.WorkingMemory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.common.InternalWorkingMemory;
import org.drools.common.TruthMaintenanceSystem;
import org.drools.compiler.PackageBuilder;
@@ -61,7 +61,7 @@
public void testLogicalInsertionsDynamicRule() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsDynamicRule.drl", getClass() ), KnowledgeType.DRL );
+ kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsDynamicRule.drl", getClass() ), ResourceType.DRL );
Collection<KnowledgePackage> kpkgs = kbuilder.getKnowledgePackages();
KnowledgeBase kbase = getKnowledgeBase();
@@ -91,7 +91,7 @@
// this rule will make a logical assertion for c1 too
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsDynamicRule2.drl", getClass() ), KnowledgeType.DRL );
+ kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsDynamicRule2.drl", getClass() ), ResourceType.DRL );
Collection<KnowledgePackage> kpkgs2 = kbuilder.getKnowledgePackages();
kbase.addKnowledgePackages( kpkgs2 );
kbase = SerializationHelper.serializeObject( kbase );
@@ -174,7 +174,7 @@
public void testLogicalInsertions() throws Exception {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertions.drl", getClass() ), KnowledgeType.DRL );
+ kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertions.drl", getClass() ), ResourceType.DRL );
Collection<KnowledgePackage> kpkgs = kbuilder.getKnowledgePackages();
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
@@ -215,7 +215,7 @@
public void testLogicalInsertionsBacking() throws Exception {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsBacking.drl", getClass() ), KnowledgeType.DRL );
+ kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsBacking.drl", getClass() ), ResourceType.DRL );
Collection<KnowledgePackage> kpkgs = kbuilder.getKnowledgePackages();
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
@@ -269,7 +269,7 @@
public void testLogicalInsertionsSelfreferencing() throws Exception {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsSelfreferencing.drl", getClass() ), KnowledgeType.DRL );
+ kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsSelfreferencing.drl", getClass() ), ResourceType.DRL );
Collection<KnowledgePackage> kpkgs = kbuilder.getKnowledgePackages();
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
@@ -311,7 +311,7 @@
public void testLogicalInsertionsLoop() throws Exception {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsLoop.drl", getClass() ), KnowledgeType.DRL );
+ kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsLoop.drl", getClass() ), ResourceType.DRL );
Collection<KnowledgePackage> kpkgs = kbuilder.getKnowledgePackages();
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
@@ -791,7 +791,7 @@
// TODO JBRULES-1804
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsModifySameRuleGivesDifferentLogicalInsertion.drl", getClass() ), KnowledgeType.DRL );
+ kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsModifySameRuleGivesDifferentLogicalInsertion.drl", getClass() ), ResourceType.DRL );
Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
KnowledgeBase kbase = getKnowledgeBase();
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -25,7 +25,7 @@
import org.drools.builder.DecisionTableInputType;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.io.Resource;
import org.drools.io.ResourceChangeScannerConfiguration;
@@ -39,6 +39,17 @@
import org.xml.sax.SAXException;
public class ChangeSetTest extends TestCase {
+ protected void setUp() throws Exception {
+ ResourceFactory.getResourceChangeNotifierService().start();
+ ResourceFactory.getResourceChangeScannerService().start();
+ }
+
+
+ protected void tearDown() throws Exception {
+ ResourceFactory.getResourceChangeNotifierService().stop();
+ ResourceFactory.getResourceChangeScannerService().stop();
+ }
+
public void testXmlParser() throws SAXException,
IOException {
@@ -67,15 +78,15 @@
assertNull( resource.getConfiguration() );
assertEquals( "http://www.domain.com/test.drl",
resource.getURL().toString() );
- assertEquals( KnowledgeType.DRL,
- resource.getKnowledgeType() );
+ assertEquals( ResourceType.DRL,
+ resource.getResourceType() );
resource = ( UrlResource ) ((List)changeSet.getResourcesAdded()).get( 1 );
assertEquals( "http://www.domain.com/test.xls",
resource.getURL().toString() );
- assertEquals( KnowledgeType.DTABLE,
- resource.getKnowledgeType() );
+ assertEquals( ResourceType.DTABLE,
+ resource.getResourceType() );
DecisionTableConfiguration dtConf = (DecisionTableConfiguration) resource.getConfiguration();
assertEquals( DecisionTableInputType.XLS,
dtConf.getInputType() );
@@ -85,7 +96,7 @@
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "changeset1Test.xml",
getClass() ),
- KnowledgeType.ChangeSet );
+ ResourceType.ChangeSet );
assertFalse( kbuilder.hasErrors() );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
@@ -151,7 +162,7 @@
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newUrlResource( fxml.toURI().toURL() ),
- KnowledgeType.ChangeSet );
+ ResourceType.ChangeSet );
assertFalse( kbuilder.hasErrors() );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
@@ -270,7 +281,7 @@
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newUrlResource( fxml.toURI().toURL() ),
- KnowledgeType.ChangeSet );
+ ResourceType.ChangeSet );
assertFalse( kbuilder.hasErrors() );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -9,6 +9,7 @@
/**
* drools.agent.scanResources = <true|false>
* drools.agent.newInstance = <true|false>
+ * drools.agent.monitorChangeSetEvents = <true|false>
*
*/
public class KnowledgeAgentConfigurationImpl
@@ -16,6 +17,7 @@
KnowledgeAgentConfiguration {
private boolean scanResources;
+ private boolean monitorChangeSetEvents;
private boolean newInstance;
public KnowledgeAgentConfigurationImpl() {
@@ -37,8 +39,14 @@
}
if ( name.equals( "drools.agent.scanResources" ) ) {
- setScanResources( StringUtils.isEmpty( value ) ? true : Boolean.parseBoolean( value ) );
- } else if ( name.equals( "drools.agent.newInstance" ) ) {
+ setMonitorChangeSetEvents( StringUtils.isEmpty( value ) ? true : Boolean.parseBoolean( value ) );
+ } else if ( name.equals( "drools.agent.monitorChangeSetEvents" ) ) {
+ boolean bool = StringUtils.isEmpty( value ) ? true : Boolean.parseBoolean( value );
+ setScanResources( bool );
+ if ( bool ) {
+ setMonitorChangeSetEvents( true );
+ }
+ }else if ( name.equals( "drools.agent.newInstance" ) ) {
setNewInstance( StringUtils.isEmpty( value ) ? true : Boolean.parseBoolean( value ) );
}
}
@@ -65,7 +73,17 @@
public void setScanResources(boolean scanResources) {
this.scanResources = scanResources;
}
+
+
+ public boolean isMonitorChangeSetEvents() {
+ return monitorChangeSetEvents;
+ }
+
+ public void setMonitorChangeSetEvents(boolean monitorChangeSetEvents) {
+ this.monitorChangeSetEvents = monitorChangeSetEvents;
+ }
+
public boolean isNewInstance() {
return newInstance;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -4,6 +4,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.LinkedBlockingQueue;
import org.drools.KnowledgeBase;
import org.drools.ChangeSet;
@@ -14,7 +15,7 @@
import org.drools.agent.KnowledgeAgentEventListener;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.definition.KnowledgeDefinition;
import org.drools.definition.process.Process;
import org.drools.event.io.ResourceChangeListener;
@@ -31,7 +32,7 @@
public class KnowledgeAgentImpl
implements
KnowledgeAgent,
- ResourceChangeListener {
+ ResourceChangeListener, Runnable {
private String name;
private Map<Resource, ResourceMapping> resources;
private Set<Resource> resourceDirectories;
@@ -39,6 +40,9 @@
private ResourceChangeNotifierImpl notifier;
private boolean newInstance;
private KnowledgeAgentEventListener listener;
+ private LinkedBlockingQueue<ChangeSet> queue;
+ private Thread thread;
+ private volatile boolean monitor;
public KnowledgeAgentImpl(String name,
KnowledgeBase kbase,
@@ -54,6 +58,9 @@
if ( ((KnowledgeAgentConfigurationImpl) configuration).isScanResources() ) {
this.notifier.addResourceChangeMonitor( ResourceFactory.getResourceChangeScannerService() );
}
+ if ( ((KnowledgeAgentConfigurationImpl) configuration).isMonitorChangeSetEvents() ) {
+ this.monitor = true;
+ }
}
buildResourceMapping( kbase );
}
@@ -163,7 +170,34 @@
// }
// }
- public void resourceChanged(ChangeSet changeSet) {
+ public void resourcesChanged(ChangeSet changeSet) {
+ try {
+ this.queue.put( changeSet );
+ } catch ( InterruptedException e ) {
+ // @TODO add proper error message
+ e.printStackTrace();
+ }
+ }
+
+ public static class ResourceMapping {
+ private Resource resource;
+ private Set<KnowledgeDefinition> knowledgeDefinitions;
+
+ public ResourceMapping(Resource resource) {
+ this.knowledgeDefinitions = new HashSet<KnowledgeDefinition>();
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public Set<KnowledgeDefinition> getKnowledgeDefinitions() {
+ return knowledgeDefinitions;
+ }
+
+ }
+
+ private void processChangeSet(ChangeSet changeSet) {
// for now we assume newIntance only, so just blow away the mappings and knowledgedefinition sets.
synchronized ( this.resources ) {
// first remove the unneeded resources
@@ -191,7 +225,7 @@
for ( Resource resource : resourcesClone ) {
System.out.println( "building : " + resource );
kbuilder.add( resource,
- ((InternalResource)resource).getKnowledgeType() );
+ ((InternalResource)resource).getResourceType() );
}
this.kbase = KnowledgeBaseFactory.newKnowledgeBase();
@@ -225,28 +259,38 @@
// }
//
// // final deal with modifies
- // }
+ // }
}
- public static class ResourceMapping {
- private Resource resource;
- private Set<KnowledgeDefinition> knowledgeDefinitions;
-
- public ResourceMapping(Resource resource) {
- this.knowledgeDefinitions = new HashSet<KnowledgeDefinition>();
+ public String getName() {
+ return this.name;
+ }
+
+ public void monitorResourceChangeEvents(boolean monitor) {
+ if ( !this.monitor && monitor ) {
+ // If the thread is not running and we are trying to start it, we must create a new Thread
+ this.monitor = monitor;
+ this.thread = new Thread( this );
+ this.thread.start();
}
-
- public Resource getResource() {
- return resource;
+ this.monitor = monitor;
+ }
+
+ public void run() {
+ while ( this.monitor ) {
+ try {
+ processChangeSet( this.queue.take() );
+ } catch ( InterruptedException e ) {
+ // @TODO print proper error message
+ e.printStackTrace();
+ }
+ Thread.yield();
}
-
- public Set<KnowledgeDefinition> getKnowledgeDefinitions() {
- return knowledgeDefinitions;
- }
-
}
-
- public String getName() {
- return this.name;
+
+ @Override
+ protected void finalize() throws Throwable {
+ // users should turn off monitoring, but just in case when this class is GC'd we turn off the thread
+ this.monitor = false;
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/InternalResource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/InternalResource.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/InternalResource.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -4,13 +4,13 @@
import java.net.URL;
import java.util.Collection;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.builder.ResourceConfiguration;
public interface InternalResource extends Resource {
- void setKnowledgeType(KnowledgeType knowledgeType);
+ void setResourceType(ResourceType resourceType);
- KnowledgeType getKnowledgeType();
+ ResourceType getResourceType();
ResourceConfiguration getConfiguration();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/BaseResource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/BaseResource.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/BaseResource.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -2,14 +2,14 @@
import java.io.Externalizable;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.builder.ResourceConfiguration;
import org.drools.io.InternalResource;
public abstract class BaseResource
implements
InternalResource {
- private KnowledgeType KnowledgeType;
+ private ResourceType resourceType;
private ResourceConfiguration configuration;
public ResourceConfiguration getConfiguration() {
@@ -20,12 +20,12 @@
this.configuration = configuration;
}
- public void setKnowledgeType(KnowledgeType knowledgeType) {
- this.KnowledgeType = knowledgeType;
+ public void setResourceType(ResourceType resourceType) {
+ this.resourceType = resourceType;
}
- public KnowledgeType getKnowledgeType() {
- return this.KnowledgeType;
+ public ResourceType getResourceType() {
+ return this.resourceType;
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ByteArrayResource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ByteArrayResource.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ByteArrayResource.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -14,7 +14,7 @@
import java.util.Date;
import java.util.List;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.io.InternalResource;
import org.drools.io.Resource;
import org.drools.util.StringUtils;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/KnowledgeResource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/KnowledgeResource.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/KnowledgeResource.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -1,22 +1,22 @@
package org.drools.io.impl;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.builder.ResourceConfiguration;
import org.drools.io.Resource;
public class KnowledgeResource {
private String source;
- private KnowledgeType type;
+ private ResourceType type;
private ResourceConfiguration configuration;
public KnowledgeResource(String src,
- KnowledgeType type) {
+ ResourceType type) {
this.source = src;
this.type = type;
}
public KnowledgeResource(String src,
- KnowledgeType type,
+ ResourceType type,
ResourceConfiguration configuration) {
this.source = src;
this.type = type;
@@ -31,11 +31,11 @@
this.source = src;
}
- public KnowledgeType getType() {
+ public ResourceType getType() {
return type;
}
- public void setType(KnowledgeType type) {
+ public void setType(ResourceType type) {
this.type = type;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -10,6 +10,7 @@
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.LinkedBlockingQueue;
import org.drools.ChangeSet;
import org.drools.event.io.ResourceChangeListener;
@@ -19,93 +20,114 @@
public class ResourceChangeNotifierImpl
implements
- ResourceChangeNotifier
-{
- private Map<Resource, Set<ResourceChangeListener>> subscriptions;
- private List<ResourceChangeMonitor> monitors;
+ ResourceChangeNotifier,
+ Runnable {
+ private Map<Resource, Set<ResourceChangeListener>> subscriptions;
+ private List<ResourceChangeMonitor> monitors;
+ private volatile boolean notify;
-
+ private LinkedBlockingQueue<ChangeSet> queue;
+
public ResourceChangeNotifierImpl() {
this.subscriptions = new HashMap<Resource, Set<ResourceChangeListener>>();
this.monitors = new CopyOnWriteArrayList<ResourceChangeMonitor>();
}
-
+
public void addResourceChangeMonitor(ResourceChangeMonitor monitor) {
- if ( !this.monitors.contains( monitor )) {
+ if ( !this.monitors.contains( monitor ) ) {
this.monitors.add( monitor );
}
}
-
+
public void removeResourceChangeMonitor(ResourceChangeMonitor monitor) {
this.monitors.remove( monitor );
}
-
+
public Collection<ResourceChangeMonitor> getResourceChangeMonitor() {
return Collections.unmodifiableCollection( this.monitors );
- }
+ }
public void subscribeResourceChangeListener(ResourceChangeListener listener,
- Resource resource
- ) {
+ Resource resource) {
System.out.println( "notifier : " + resource );
- Set<ResourceChangeListener> listeners = this.subscriptions.get( resource );
- if ( listeners == null ) {
- listeners = new HashSet<ResourceChangeListener>();
- this.subscriptions.put( resource, listeners );
- for ( ResourceChangeMonitor monitor : this.monitors ) {
- monitor.subscribeNotifier( this, resource );
- }
+ synchronized ( this.subscriptions ) {
+ Set<ResourceChangeListener> listeners = this.subscriptions.get( resource );
+ if ( listeners == null ) {
+ listeners = new HashSet<ResourceChangeListener>();
+ this.subscriptions.put( resource,
+ listeners );
+ for ( ResourceChangeMonitor monitor : this.monitors ) {
+ monitor.subscribeNotifier( this,
+ resource );
+ }
+ }
+ listeners.add( listener );
}
- listeners.add( listener );
}
+
+ public void unsubscribeResourceChangeListener(ResourceChangeListener listener,
+ Resource resource) {
+ synchronized ( this.subscriptions ) {
+ Set<ResourceChangeListener> listeners = this.subscriptions.get( resource );
+ if ( listeners == null ) {
+ return;
+ }
- public void unsubscribeResourceChangeListener(ResourceChangeListener listener,
- Resource resource) {
- Set<ResourceChangeListener> listeners = this.subscriptions.get( resource );
- if ( listeners == null ) {
- return;
+ if ( listeners.isEmpty() ) {
+ this.subscriptions.remove( resource );
+ for ( ResourceChangeMonitor monitor : this.monitors ) {
+ monitor.unsubscribeNotifier( this,
+ resource );
+ }
+ }
}
-
-
- if ( listeners.isEmpty() ) {
- this.subscriptions.remove( resource );
- for ( ResourceChangeMonitor monitor : this.monitors ) {
- monitor.unsubscribeNotifier( this, resource );
- }
- }
}
-
- public void subscribeChildResource(Resource directory, Resource child) {
+
+ public void subscribeChildResource(Resource directory,
+ Resource child) {
for ( ResourceChangeListener listener : this.subscriptions.get( directory ) ) {
- subscribeResourceChangeListener( listener, child );
+ subscribeResourceChangeListener( listener,
+ child );
}
}
public void publishKnowledgeBaseChangeSet(ChangeSet changeSet) {
+ try {
+ this.queue.put( changeSet );
+ } catch ( InterruptedException e ) {
+ // @TODO print proper error message
+ e.printStackTrace();
+ }
+
+ }
+
+ private void processChangeSet(ChangeSet changeSet) {
// this provides the complete published change set for this notifier.
// however different listeners might be listening to different resources, so provide
// listener change specified change sets.
-
+
+
Map<ResourceChangeListener, ChangeSetImpl> localChangeSets = new HashMap<ResourceChangeListener, ChangeSetImpl>();
-
- for ( Resource resource : changeSet.getResourcesAdded() ) {
+
+ for ( Resource resource : changeSet.getResourcesAdded() ) {
Set<ResourceChangeListener> listeners = this.subscriptions.get( resource );
- for ( ResourceChangeListener listener : listeners ) {
+ for ( ResourceChangeListener listener : listeners ) {
ChangeSetImpl localChangeSet = localChangeSets.get( listener );
-
+
if ( localChangeSet == null ) {
// lazy initialise changeSet
localChangeSet = new ChangeSetImpl();
- localChangeSets.put( listener, localChangeSet );
- }
- if ( localChangeSet.getResourcesAdded().isEmpty() ) {
- localChangeSet.setResourcesAdded( new ArrayList<Resource>() );
- }
- localChangeSet.getResourcesAdded().add( resource );
-
+ localChangeSets.put( listener,
+ localChangeSet );
+ }
+ if ( localChangeSet.getResourcesAdded().isEmpty() ) {
+ localChangeSet.setResourcesAdded( new ArrayList<Resource>() );
+ }
+ localChangeSet.getResourcesAdded().add( resource );
+
}
}
-
+
for ( Resource resource : changeSet.getResourcesRemoved() ) {
Set<ResourceChangeListener> listeners = this.subscriptions.remove( resource );
for ( ResourceChangeListener listener : listeners ) {
@@ -113,16 +135,16 @@
if ( localChangeSet == null ) {
// lazy initialise changeSet
localChangeSet = new ChangeSetImpl();
- localChangeSets.put( listener, localChangeSet );
- }
- if ( localChangeSet.getResourcesRemoved().isEmpty() ) {
- localChangeSet.setResourcesRemoved( new ArrayList<Resource>() );
- }
- localChangeSet.getResourcesRemoved().add( resource );
- }
- }
-
-
+ localChangeSets.put( listener,
+ localChangeSet );
+ }
+ if ( localChangeSet.getResourcesRemoved().isEmpty() ) {
+ localChangeSet.setResourcesRemoved( new ArrayList<Resource>() );
+ }
+ localChangeSet.getResourcesRemoved().add( resource );
+ }
+ }
+
for ( Resource resource : changeSet.getResourcesModified() ) {
Set<ResourceChangeListener> listeners = this.subscriptions.get( resource );
for ( ResourceChangeListener listener : listeners ) {
@@ -130,32 +152,51 @@
if ( localChangeSet == null ) {
// lazy initialise changeSet
localChangeSet = new ChangeSetImpl();
- localChangeSets.put( listener, localChangeSet );
- }
- if ( localChangeSet.getResourcesModified().isEmpty() ) {
- localChangeSet.setResourcesModified( new ArrayList<Resource>() );
- }
- localChangeSet.getResourcesModified().add( resource );
- }
- }
-
+ localChangeSets.put( listener,
+ localChangeSet );
+ }
+ if ( localChangeSet.getResourcesModified().isEmpty() ) {
+ localChangeSet.setResourcesModified( new ArrayList<Resource>() );
+ }
+ localChangeSet.getResourcesModified().add( resource );
+ }
+ }
+
for ( Entry<ResourceChangeListener, ChangeSetImpl> entry : localChangeSets.entrySet() ) {
ResourceChangeListener listener = entry.getKey();
ChangeSetImpl localChangeSet = entry.getValue();
- listener.resourceChanged( localChangeSet );
+ listener.resourcesChanged( localChangeSet );
}
-
-
-// ResourceModifiedEvent event = new ResourceModifiedEventImpl( resource,
-// resource.getLastModified() );
-// Set<ResourceChangeListener> listeners = this.subscriptions.get( resource );
-//
-// if ( listeners != null ) {
-// for ( ResourceChangeListener listener : listeners ) {
-// listener.resourceModified( event );
-// }
-// }
+
+ // ResourceModifiedEvent event = new ResourceModifiedEventImpl( resource,
+ // resource.getLastModified() );
+ // Set<ResourceChangeListener> listeners = this.subscriptions.get( resource );
+ //
+ // if ( listeners != null ) {
+ // for ( ResourceChangeListener listener : listeners ) {
+ // listener.resourceModified( event );
+ // }
+ // }
}
+
+ public void start() {
+ this.notify = true;
+ }
+ public void stop() {
+ this.notify = false;
+ }
+ public void run() {
+ while ( this.notify ) {
+ try {
+ processChangeSet( this.queue.take() );
+ } catch ( InterruptedException e ) {
+ // @TODO print proper error message
+ e.printStackTrace();
+ }
+ Thread.yield();
+ }
+ }
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -105,7 +105,7 @@
if ( !this.resources.containsKey( child ) ) {
System.out.println( "found new file : " + child );
// child is new
- ((InternalResource)child).setKnowledgeType( ((InternalResource)resource).getKnowledgeType() );
+ ((InternalResource)child).setResourceType( ((InternalResource)resource).getResourceType() );
Set<ResourceChangeNotifier> notifiers = this.resources.get( resource ); // get notifiers for this directory
for ( ResourceChangeNotifier notifier : notifiers ) {
ChangeSetImpl changeSet = (ChangeSetImpl) notifications.get( notifier );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceProviderImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceProviderImpl.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceProviderImpl.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -17,12 +17,15 @@
private ResourceChangeNotifier notifier;
private ResourceChangeScanner scanner;
private Object lock = new Object();
- private Thread thread;
+ private Thread scannerThread;
+ private Thread notifierThread;
public ResourceChangeNotifier getResourceChangeNotifierService() {
synchronized ( this.lock ) {
if ( this.notifier == null ) {
this.notifier = new ResourceChangeNotifierImpl();
+ this.notifierThread = new Thread( (ResourceChangeScannerImpl) this.notifier );
+ //this.scannerThread.start();
}
return this.notifier;
}
@@ -32,8 +35,8 @@
synchronized ( this.lock ) {
if ( scanner == null ) {
this.scanner = new ResourceChangeScannerImpl( );
- this.thread = new Thread( (ResourceChangeScannerImpl) this.scanner );
- this.thread.start();
+ this.scannerThread = new Thread( (ResourceChangeScannerImpl) this.scanner );
+ //this.scannerThread.start();
}
return this.scanner;
}
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 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/acme/insurance/launcher/PricingRuleLauncher.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -16,7 +16,7 @@
import org.drools.builder.DecisionTableInputType;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilder;
import org.drools.decisiontable.InputType;
@@ -41,7 +41,7 @@
dtconf.setInputType( DecisionTableInputType.XLS );
kbuilder.add( ResourceFactory.newClassPathResource( "/data/ExamplePolicyPricing.xls", getClass() ),
- KnowledgeType.DTABLE,
+ ResourceType.DTABLE,
dtconf );
if ( kbuilder.hasErrors() ) {
Modified: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/ChangeSetTest.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/ChangeSetTest.java 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/ChangeSetTest.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -14,7 +14,7 @@
import org.drools.builder.DecisionTableInputType;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.io.ResourceFactory;
import org.drools.io.impl.ClassPathResource;
@@ -25,9 +25,20 @@
public class ChangeSetTest extends TestCase {
+ protected void setUp() throws Exception {
+ ResourceFactory.getResourceChangeNotifierService().start();
+ ResourceFactory.getResourceChangeScannerService().start();
+ }
+
+
+ protected void tearDown() throws Exception {
+ ResourceFactory.getResourceChangeNotifierService().stop();
+ ResourceFactory.getResourceChangeScannerService().stop();
+ }
+
public void testIntegregation() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newClassPathResource( "changeset1Test.xml", getClass()), KnowledgeType.ChangeSet );
+ kbuilder.add( ResourceFactory.newClassPathResource( "changeset1Test.xml", getClass()), ResourceType.ChangeSet );
assertFalse( kbuilder.hasErrors() );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
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 2008-12-05 10:10:16 UTC (rev 24246)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/SpreadsheetIntegrationTest.java 2008-12-05 11:30:47 UTC (rev 24247)
@@ -29,7 +29,7 @@
import org.drools.builder.DecisionTableInputType;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeType;
+import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
@@ -42,7 +42,7 @@
dtconf.setInputType( DecisionTableInputType.XLS );
kbuilder.add( ResourceFactory.newClassPathResource( "/data/IntegrationExampleTest.xls", getClass() ),
- KnowledgeType.DTABLE,
+ ResourceType.DTABLE,
dtconf );
assertFalse( kbuilder.hasErrors() );
@@ -78,7 +78,7 @@
dtconf.setWorksheetName( "Tables_2" );
kbuilder.add( ResourceFactory.newClassPathResource( "/data/IntegrationExampleTest.xls", getClass() ),
- KnowledgeType.DTABLE,
+ ResourceType.DTABLE,
dtconf );
assertFalse( kbuilder.hasErrors() );
More information about the jboss-svn-commits
mailing list