[jboss-svn-commits] JBL Code SVN: r24229 - in labs/jbossrules/trunk: drools-api/src/main/java/org/drools/definition and 21 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 3 16:18:16 EST 2008
Author: mark.proctor at jboss.com
Date: 2008-12-03 16:18:15 -0500 (Wed, 03 Dec 2008)
New Revision: 24229
Added:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentConfiguration.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentEventListener.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/KnowledgeDefinition.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/
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/ResourceChangeManager.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeNotifier.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceModifiedEvent.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeMonitor.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeScanner.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeScannerConfiguration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/
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/agent/impl/KnowledgeAgentProviderImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/definition/
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/ResourceChangeScannerConfigurationImpl.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/ResourceModifiedEventImpl.java
Removed:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeEventListener.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/KnowledgeAgentProviderImpl.java
Modified:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentFactory.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentProvider.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/process/Process.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/rule/Rule.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/Resource.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceFactory.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceProvider.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/ProcessBuilder.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/FunctionDescr.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/ProcessDescr.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/RuleDescr.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/composition/CompositionTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/AgentEventListener.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleAgent.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/definitions/impl/KnowledgePackageImp.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseImpl.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/ClassPathResource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/EncodedResource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/FileSystemResource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/InputStreamResource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ReaderResource.java
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/UrlResource.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/Process.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/impl/ProcessImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Function.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java
Log:
JBRULES-1885 Update KnowledgeAgent to use new Resource api
JBRULES-1874 Create Resource Framework
Added: 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 (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentConfiguration.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,7 @@
+package org.drools.agent;
+
+import org.drools.PropertiesConfiguration;
+
+public interface KnowledgeAgentConfiguration extends PropertiesConfiguration {
+
+}
Copied: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentEventListener.java (from rev 24130, labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeEventListener.java)
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentEventListener.java (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentEventListener.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,27 @@
+package org.drools.agent;
+
+/**
+ * This interface is used to provide callback style logging for the agents events.
+ *
+ */
+public interface KnowledgeAgentEventListener {
+ /**
+ * For general info messages
+ */
+ public void info(String message);
+
+ /**
+ * For a warning (useful when tracking down problems).
+ */
+ public void warning(String message);
+
+ /**
+ * An exception occurred.
+ */
+ public void exception(Exception e);
+
+ /**
+ * These should not be logged, just shown if needed.
+ */
+ public void debug(String message);
+}
Property changes on: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentEventListener.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentFactory.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentFactory.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -6,135 +6,27 @@
import org.drools.KnowledgeBaseConfiguration;
import org.drools.ProviderInitializationException;
-/**
- * <p>
- * KnowledgeAgents can build and cache KnowledgeBases using resources from different locations,
- * such as file for http. It can be set to poll that location for updates and will rebuild, or update
- * depending on the configuration, the cached KnowledgeBase.
- * </p>
- *
- * <p>
- * All KnowledgeAgents must be given a name.
- * </p>
- *
- * <p>
- * You should only have ONE instance of this agent per KnowledeBase configuration.
- * You can get the KnowledeBase from this agent repeatedly, as needed, or if you keep the KnowledeBase,
- * under most configurations it will be automatically updated.
- * </p>
- *
- * <p>
- * How this behaves depends on the properties that you pass into it (documented below)
- * </p>
- *
- * <p>
- * CONFIG OPTIONS (to be passed in as properties):
- * <ul>
- * <li><code>newInstance</code>: setting this to "true" means that each time the rules are changed
- * a new instance of the KnowledeBase is created (as opposed to updated in place)
- * the default is to update in place. DEFAULT: false. If you set this to true,
- * then you will need to call getRuleBase() each time you want to use it. If it is false,
- * then it means you can keep your reference to the KnowledeBase and it will be updated automatically
- * (as well as any StatefulKnowlegeSessions).
- * </li>
- *
- * <li>
- * <code>poll</code>The number of seconds to poll for changes. Polling
- * happens in a background thread. eg: poll=30 #30 second polling.
- * </li>
- *
- * <li>
- * <code>file</code>: a space separated listing of files that make up the
- * packages of the KnowledeBase. Each package can only be in one file. You can't have
- * packages spread across files. eg: file=/your/dir/file1.pkg file=/your/dir/file2.pkg
- * If the file has a .pkg extension, then it will be loaded as a binary Package (eg from the BRMS). If its a
- * DRL file (ie a file with a .drl extension with rule source in it), then it will attempt to compile it (of course, you will need the drools-compiler and its dependencies
- * available on your classpath).
- * </li>
- *
- * <li>
- * <code>dir</code>: a single file system directory to monitor for packages.
- * As with files, each package must be in its own file.
- * eg: dir=/your/dir
- * </li>
- *
- * <li>
- * <code>url</code>: A space separated URL to a binary KnowledeBase in the BRMS.
- * eg: url=http://server/drools-guvnor/packages/somePakage/VERSION_1
- * For URL you will also want a local cache directory setup:
- * eg: localCacheDir=/some/dir/that/exists
- * This is needed so that the runtime can startup and load packages even if the BRMS
- * is not available (or the network).
- * </li>
- * </p>
- *
- * <p>
- * There is also an KnowledgeAgentEventListener interface which you can provide which will call back when lifecycle
- * events happen, or errors/warnings occur. As the updating happens in a background thread, this may be important.
- * The default event listener logs to the System.err output stream.
- * </p>
- *
- * <p>
- * The Follow example constructs an agent that will build a new KnowledgeBase from the files specified in the path String.
- * It will poll those files every 30 seconds to see if they are updated. If new files are found it will construct a new
- * KnowledgeBase, instead of upating the existing one, due to the "newInstance" set to "true":
- * <p/>
- * <pre>
- * Properties props = new Properties();
- * props.setProperty( "file", path );
- *
- * props.setProperty( "newInstance", "true" );
- * props.setProperty( "poll", "30" );
- * KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "agent1", props );
- * KnowledgeBase kbase = kagent.getKnowledgeBase();
- * </pre>
- *
- * Notice the 'k' for Knowledge prefix for the variable names.
- *
- * * @see org.drools.agent.KnowledgeAgent
- *
- */
+
public class KnowledgeAgentFactory {
private static KnowledgeAgentProvider provider;
- /**
- * Create and return a new KnowlegeAgent using the given name and configuration.
- *
- * @param name
- * @param config
- * @return
- * The KnowledgeAgent
- */
public static KnowledgeAgent newKnowledgeAgent(String name,
- Properties config) {
- return newKnowledgeAgent( name,
- config,
- null,
- null );
+ KnowledgeBase kbase) {
+ return getKnowledgeAgentProvider().newKnowledgeAgent( name, kbase );
}
+
+ public static KnowledgeAgent newKnowledgeAgent(String name,
+ KnowledgeBase kbase,
+ KnowledgeAgentConfiguration configuration) {
+ return getKnowledgeAgentProvider().newKnowledgeAgent( name, kbase, configuration );
+ }
- /**
- * Create and return a new KnowlegeAgent using the given name and configuration.
- * A listener is also specified for callback type logging on for info, warning,
- * exception and debug. The KnowledgeBaseConfiguration will be used by the
- * KnowledgeBases that the RuleAgent creates.
- *
- * @param name
- * @param config
- * @param listener
- * @param kbaseConf
- * @return
- * The KnowledgeAgent
- */
public static KnowledgeAgent newKnowledgeAgent(String name,
- Properties config,
- KnowledgeEventListener listener,
- KnowledgeBaseConfiguration kbaseConf) {
+ KnowledgeBase kbase,
+ KnowledgeAgentConfiguration configuration,
+ KnowledgeAgentEventListener listener) {
- return getKnowledgeAgentProvider().newKnowledgeAgent( name,
- config,
- listener,
- kbaseConf );
+ return getKnowledgeAgentProvider().newKnowledgeAgent( name, kbase, configuration, listener );
}
private static synchronized void setKnowledgeAgentProvider(KnowledgeAgentProvider provider) {
@@ -151,7 +43,7 @@
private static void loadProvider() {
try {
// we didn't find anything in properties so lets try and us reflection
- Class<KnowledgeAgentProvider> cls = (Class<KnowledgeAgentProvider>) Class.forName( "org.drools.agent.KnowledgeAgentProviderImpl" );
+ Class<KnowledgeAgentProvider> cls = (Class<KnowledgeAgentProvider>) Class.forName( "org.drools.agent.impl.KnowledgeAgentProviderImpl" );
setKnowledgeAgentProvider( cls.newInstance() );
} catch ( Exception e ) {
throw new ProviderInitializationException( "Provider org.drools.agent.KnowledgeAgentProvider could not be set." );
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentProvider.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgentProvider.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -2,43 +2,18 @@
import java.util.Properties;
-import org.drools.KnowledgeBaseConfiguration;
+import org.drools.KnowledgeBase;
-/**
- * KnowledgeAgentProvider is used by the KnowledgeAgentFacotry to "provide" it's concrete implementation.
- *
- * This class is not considered stable and may change, the user is protected from this change by using
- * the Factory api, which is consiered stable.
- *
- */
public interface KnowledgeAgentProvider {
+ KnowledgeAgent newKnowledgeAgent(String name,
+ KnowledgeBase kbase);
- /**
- * Create and return a new KnowlegeAgent using the given name and configuration.
- *
- * @param name
- * @param config
- * @return
- * The KnowledgeAgent
- */
KnowledgeAgent newKnowledgeAgent(String name,
- Properties config);
+ KnowledgeBase kbase,
+ KnowledgeAgentConfiguration configuration);
- /**
- * Create and return a new KnowlegeAgent using the given name and configuration.
- * A listener is also specified for callback type logging on for info, warning,
- * exception and debug. The KnowledgeBaseConfiguration will be used by the
- * KnowledgeBases that the RuleAgent creates.
- *
- * @param name
- * @param config
- * @param listener
- * @param kbaseConf
- * @return
- * The KnowledgeAgent
- */
KnowledgeAgent newKnowledgeAgent(String name,
- Properties config,
- KnowledgeEventListener listener,
- KnowledgeBaseConfiguration ruleBaseConf);
+ KnowledgeBase kbase,
+ KnowledgeAgentConfiguration configuration,
+ KnowledgeAgentEventListener listener);
}
Deleted: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeEventListener.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeEventListener.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeEventListener.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -1,27 +0,0 @@
-package org.drools.agent;
-
-/**
- * This interface is used to provide callback style logging for the agents
- * async events.
- */
-public interface KnowledgeEventListener {
- /**
- * For general info messages
- */
- public void info(String message);
-
- /**
- * For a warning (useful when tracking down problems).
- */
- public void warning(String message);
-
- /**
- * An exception occurred.
- */
- public void exception(Exception e);
-
- /**
- * These should not be logged, just shown if needed.
- */
- public void debug(String message);
-}
Added: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/KnowledgeDefinition.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/KnowledgeDefinition.java (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/KnowledgeDefinition.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,5 @@
+package org.drools.definition;
+
+public interface KnowledgeDefinition {
+
+}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/process/Process.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/process/Process.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/process/Process.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -1,7 +1,9 @@
package org.drools.definition.process;
-public interface Process {
+import org.drools.definition.KnowledgeDefinition;
+public interface Process extends KnowledgeDefinition {
+
String getId();
String getName();
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/rule/Rule.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/rule/Rule.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/rule/Rule.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -1,7 +1,9 @@
package org.drools.definition.rule;
-public interface Rule {
+import org.drools.definition.KnowledgeDefinition;
+public interface Rule extends KnowledgeDefinition {
+
String getName();
public String getPackageName();
Added: 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 (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeListener.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,12 @@
+/**
+ *
+ */
+package org.drools.event.io;
+
+
+
+public interface ResourceChangeListener {
+ public void resourceAdded(ResourceModifiedEvent event);
+ public void resourceModified(ResourceModifiedEvent event);
+ public void resourceRemoved(ResourceModifiedEvent event);
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeManager.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeManager.java (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeManager.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,21 @@
+package org.drools.event.io;
+
+import java.util.Collection;
+
+import org.drools.definition.KnowledgeDefinition;
+import org.drools.io.Resource;
+import org.drools.io.ResourceChangeMonitor;
+
+public interface ResourceChangeManager {
+ void subscribeResourceChangeListener(ResourceChangeListener listener,
+ Resource resource);
+
+ void unsubscribeResourceChangeListener(ResourceChangeListener listener,
+ Resource resource);
+
+ void addResourceChangeMonitor(ResourceChangeMonitor monitor);
+
+ void removeResourceChangeMonitor(ResourceChangeMonitor monitor);
+
+ Collection<ResourceChangeMonitor> getResourceChangeMonitor();
+}
Added: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeNotifier.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeNotifier.java (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceChangeNotifier.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,9 @@
+package org.drools.event.io;
+
+import org.drools.io.Resource;
+
+public interface ResourceChangeNotifier extends ResourceChangeManager {
+ public void resourceAdded(Resource resource);
+ public void resourceModified(Resource resource);
+ public void resourceRemoved(Resource resource);
+}
Added: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceModifiedEvent.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceModifiedEvent.java (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/event/io/ResourceModifiedEvent.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,12 @@
+package org.drools.event.io;
+
+import org.drools.io.Resource;
+
+
+public interface ResourceModifiedEvent {
+
+ public abstract Resource getResource();
+
+ public abstract long getTime();
+
+}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/Resource.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/Resource.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/Resource.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -10,4 +10,6 @@
public Reader getReader() throws IOException;
URL getURL() throws IOException;
boolean hasURL();
+ long getLastModified();
+ public long getLastRead();
}
Added: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeMonitor.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeMonitor.java (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeMonitor.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,8 @@
+package org.drools.io;
+
+import org.drools.event.io.ResourceChangeNotifier;
+
+public interface ResourceChangeMonitor {
+ void subscribeNotifier(ResourceChangeNotifier notifier, Resource resource);
+ void unsubscribeNotifier(ResourceChangeNotifier notifier, Resource resource);
+}
Added: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeScanner.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeScanner.java (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeScanner.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,25 @@
+package org.drools.io;
+
+import java.util.Properties;
+
+
+public interface ResourceChangeScanner extends ResourceChangeMonitor {
+
+ public ResourceChangeScannerConfiguration newResourceChangeScannerConfiguration();
+
+ public ResourceChangeScannerConfiguration newResourceChangeScannerConfiguration(Properties properties);
+
+ public void configure(ResourceChangeScannerConfiguration configuration);
+
+ public void scan();
+
+ public void start();
+
+ public void stop();
+
+ public void setInterval(int interval);
+
+ public int getInterval();
+
+}
+
Added: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeScannerConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeScannerConfiguration.java (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceChangeScannerConfiguration.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,12 @@
+package org.drools.io;
+
+import org.drools.PropertiesConfiguration;
+
+/**
+ *
+ * drools.resource.scanner.interval = <number of seconds> : default 60s
+ *
+ */
+public interface ResourceChangeScannerConfiguration extends PropertiesConfiguration {
+
+}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceFactory.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceFactory.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -4,12 +4,23 @@
import java.io.InputStream;
import java.io.Reader;
import java.net.URL;
+import java.util.Properties;
import org.drools.ProviderInitializationException;
+import org.drools.event.io.ResourceChangeNotifier;
public class ResourceFactory {
private static ResourceProvider resourceProvider;
+
+ public static ResourceChangeNotifier getResourceChangeNotifierService() {
+ return getResourceProvider().getResourceChangeNotifierService();
+ }
+
+ public static ResourceChangeScanner getResourceChangeScannerService() {
+ return getResourceProvider().getResourceChangeScannerService();
+ }
+
public static Resource newUrlResource(URL url) {
return getResourceProvider().newUrlResource( url );
}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceProvider.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/io/ResourceProvider.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -3,10 +3,15 @@
import java.io.File;
import java.io.InputStream;
import java.io.Reader;
-import java.net.URI;
import java.net.URL;
+import org.drools.event.io.ResourceChangeNotifier;
+
public interface ResourceProvider {
+ ResourceChangeNotifier getResourceChangeNotifierService();
+
+ ResourceChangeScanner getResourceChangeScannerService();
+
Resource newUrlResource(URL url);
Resource newUrlResource(String path);
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -5,6 +5,7 @@
import java.util.Set;
import org.drools.base.TypeResolver;
+import org.drools.io.Resource;
import org.drools.lang.descr.BaseDescr;
import org.drools.lang.descr.FunctionDescr;
import org.drools.lang.descr.ProcessDescr;
@@ -95,8 +96,9 @@
void addProcess(final ProcessBuildContext context);
- void addFunction(final FunctionDescr functionDescr,
- TypeResolver typeResolver);
+ void addFunction(FunctionDescr functionDescr,
+ TypeResolver typeResolver,
+ Resource resource);
public void addImport(String importEntry);
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-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -50,6 +50,7 @@
import org.drools.facttemplates.FieldTemplateImpl;
import org.drools.io.Resource;
import org.drools.io.impl.ClassPathResource;
+import org.drools.io.impl.ReaderResource;
import org.drools.io.impl.UrlResource;
import org.drools.lang.descr.AttributeDescr;
import org.drools.lang.descr.BaseDescr;
@@ -123,7 +124,7 @@
private Map<String, Class> globals;
- private String url;
+ private Resource resource;
private List<DSLTokenizedMappingFile> dslFiles;
@@ -263,26 +264,26 @@
*/
public void addPackageFromDrl(final Reader reader) throws DroolsParserException,
IOException {
+ this.resource = new ReaderResource( reader );
final DrlParser parser = new DrlParser();
final PackageDescr pkg = parser.parse( reader );
this.results.addAll( parser.getErrors() );
if ( !parser.hasErrors() ) {
addPackage( pkg );
}
+ this.resource = null;
}
public void addPackageFromDrl(Resource resource) throws DroolsParserException,
IOException {
- if ( resource.hasURL() ) {
- this.url = resource.getURL().toExternalForm();
- }
+ this.resource = resource;
final DrlParser parser = new DrlParser();
final PackageDescr pkg = parser.parse( resource.getInputStream() );
this.results.addAll( parser.getErrors() );
if ( !parser.hasErrors() ) {
addPackage( pkg );
}
- this.url = null;
+ this.resource = null;
}
/**
@@ -294,6 +295,7 @@
*/
public void addPackageFromXml(final Reader reader) throws DroolsParserException,
IOException {
+ this.resource = new ReaderResource( reader );
final XmlPackageReader xmlReader = new XmlPackageReader( this.configuration.getSemanticModules() );
try {
@@ -304,13 +306,12 @@
}
addPackage( xmlReader.getPackageDescr() );
+ this.resource = null;
}
public void addPackageFromXml(final Resource resource) throws DroolsParserException,
IOException {
- if ( resource.hasURL() ) {
- this.url = resource.getURL().toExternalForm();
- }
+ this.resource = resource;
final XmlPackageReader xmlReader = new XmlPackageReader( this.configuration.getSemanticModules() );
@@ -322,7 +323,7 @@
}
addPackage( xmlReader.getPackageDescr() );
- this.url = null;
+ this.resource = null;
}
/**
@@ -338,6 +339,8 @@
public void addPackageFromDrl(final Reader source,
final Reader dsl) throws DroolsParserException,
IOException {
+ this.resource = new ReaderResource( source );
+
final DrlParser parser = new DrlParser();
final PackageDescr pkg = parser.parse( source,
dsl );
@@ -345,13 +348,12 @@
if ( !parser.hasErrors() ) {
addPackage( pkg );
}
+ this.resource = null;
}
public void addPackageFromDslr(final Resource resource) throws DroolsParserException,
IOException {
- if ( resource.hasURL() ) {
- this.url = resource.getURL().toExternalForm();
- }
+ this.resource = resource;
final DrlParser parser = new DrlParser();
DefaultExpander expander = getDslExpander();
@@ -370,26 +372,11 @@
} catch ( IOException e ) {
throw new RuntimeException( e );
}
- this.url = null;
+ this.resource = null;
}
- public void addDsl(Reader dsl) {
- try {
- DSLTokenizedMappingFile file = new DSLTokenizedMappingFile();
- file.parseAndLoad( dsl );
- if ( this.dslFiles == null ) {
- this.dslFiles = new ArrayList<DSLTokenizedMappingFile>();
- }
- this.dslFiles.add( file );
- } catch ( Exception e ) {
- throw new RuntimeException( e );
- }
- }
-
public void addDsl(Resource resource) throws IOException {
- if ( resource.hasURL() ) {
- this.url = resource.getURL().toExternalForm();
- }
+ this.resource = resource;
DSLTokenizedMappingFile file = new DSLTokenizedMappingFile();
file.parseAndLoad( resource.getReader() );
@@ -398,19 +385,9 @@
}
this.dslFiles.add( file );
- this.url = null;
+ this.resource = null;
}
- public void addDsl(URL url) {
- this.url = url.toExternalForm();
- try {
- addDsl( new InputStreamReader( url.openStream() ) );
- } catch ( IOException e ) {
- throw new RuntimeException( e );
- }
- this.url = null;
- }
-
/**
* Add a ruleflow (.rfm) asset to this package.
*/
@@ -419,14 +396,12 @@
}
public void addProcessFromXml(Resource resource) throws IOException {
- if ( resource.hasURL() ) {
- this.url = resource.getURL().toExternalForm();
- }
+ this.resource = resource;
ProcessBuilder processBuilder = new ProcessBuilder( this );
try {
processBuilder.addProcessFromFile( resource.getReader(),
- url );
+ resource );
this.results.addAll( processBuilder.getErrors() );
} catch ( Exception e ) {
if ( e instanceof RuntimeException ) {
@@ -437,14 +412,16 @@
}
this.results = getResults( this.results );
- this.url = null;
+ this.resource = null;
}
public void addProcessFromXml(Reader processSource) {
+ this.resource = new ReaderResource( processSource );
+
ProcessBuilder processBuilder = new ProcessBuilder( this );
try {
processBuilder.addProcessFromFile( processSource,
- url );
+ resource );
this.results.addAll( processBuilder.getErrors() );
} catch ( Exception e ) {
if ( e instanceof RuntimeException ) {
@@ -455,6 +432,7 @@
}
this.results = getResults( this.results );
+ this.resource = null;
}
public void addKnowledgeResource(Resource resource,
@@ -789,6 +767,7 @@
}
TypeDeclaration type = new TypeDeclaration( typeDescr.getTypeName() );
+ type.setResource( this.resource );
// is it a regular fact or an event?
String role = typeDescr.getMetaAttribute( TypeDeclaration.Role.ID );
@@ -939,11 +918,12 @@
}
private void addFunction(final FunctionDescr functionDescr) {
- functionDescr.setUrl( this.url );
+ functionDescr.setResource( this.resource );
PackageRegistry pkgRegistry = this.pkgRegistryMap.get( functionDescr.getNamespace() );
Dialect dialect = pkgRegistry.getDialectCompiletimeRegistry().getDialect( functionDescr.getDialect() );
dialect.addFunction( functionDescr,
- pkgRegistry.getTypeResolver() );
+ pkgRegistry.getTypeResolver(),
+ this.resource );
}
private void preCompileAddFunction(final FunctionDescr functionDescr) {
@@ -987,7 +967,7 @@
private void addRule(final RuleDescr ruleDescr) {
// this.dialect.init( ruleDescr );
- ruleDescr.setUrl( url );
+ ruleDescr.setResource( resource );
if ( ruleDescr instanceof QueryDescr ) {
// ruleDescr.getLhs().insertDescr( 0, baseDescr );
@@ -1005,7 +985,7 @@
this.results.addAll( context.getErrors() );
- context.getRule().setUrl( url );
+ context.getRule().setResource( resource );
context.getDialect().addRule( context );
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/ProcessBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/ProcessBuilder.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/ProcessBuilder.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -40,6 +40,7 @@
import org.drools.definition.process.NodeContainer;
import org.drools.definition.process.Process;
import org.drools.definition.process.WorkflowProcess;
+import org.drools.io.Resource;
import org.drools.lang.descr.ActionDescr;
import org.drools.lang.descr.ProcessDescr;
import org.drools.process.builder.ProcessNodeBuilder;
@@ -89,8 +90,8 @@
return errors;
}
- public void buildProcess(final Process process, String url) {
- ((org.drools.process.core.Process) process).setURL( url );
+ public void buildProcess(final Process process, Resource resource) {
+ ((org.drools.process.core.Process) process).setResource( resource );
boolean hasErrors = false;
ProcessValidator validator = processValidators.get(((Process)process).getType());
if (validator == null) {
@@ -124,7 +125,7 @@
ProcessDescr processDescr = new ProcessDescr();
processDescr.setName(process.getPackageName());
- processDescr.setUrl( url );
+ processDescr.setResource( resource );
PackageRegistry pkgRegistry = this.packageBuilder.getPackageRegistry( this.packageBuilder.getPackage().getName() );
DialectCompiletimeRegistry dialectRegistry = pkgRegistry.getDialectCompiletimeRegistry();
Dialect dialect = dialectRegistry.getDialect( "java" );
@@ -205,7 +206,7 @@
}
}
- public void addProcessFromFile(final Reader reader, final String url) throws Exception {
+ public void addProcessFromFile(final Reader reader, final Resource resource) throws Exception {
PackageBuilderConfiguration configuration = packageBuilder.getPackageBuilderConfiguration();
XmlProcessReader xmlReader = new XmlProcessReader( configuration.getSemanticModules() );
@@ -221,7 +222,7 @@
portedReader = reader;
}
Process process = xmlReader.read(portedReader);
- buildProcess( process, url );
+ buildProcess( process, resource );
} finally {
Thread.currentThread().setContextClassLoader( oldLoader );
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/FunctionDescr.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/FunctionDescr.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/FunctionDescr.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;
+import org.drools.io.Resource;
import org.drools.rule.Dialectable;
import org.drools.rule.Namespaceable;
@@ -43,7 +44,7 @@
private String className;
- private String url;
+ private Resource resource;
public FunctionDescr(final String name,
final String returnType) {
@@ -59,12 +60,12 @@
return this.namespace;
}
- public String getUrl() {
- return url;
+ public Resource getResource() {
+ return resource;
}
- public void setUrl(String url) {
- this.url = url;
+ public void setResource(Resource resource) {
+ this.resource = resource;
}
public String getName() {
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/ProcessDescr.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/ProcessDescr.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/ProcessDescr.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -1,5 +1,6 @@
package org.drools.lang.descr;
+import org.drools.io.Resource;
import org.drools.rule.Dialectable;
import org.drools.rule.Namespaceable;
@@ -12,7 +13,7 @@
private String dialect;
private String name;
private String className;
- private String url;
+ private Resource resource;
public ProcessDescr() {
@@ -23,12 +24,12 @@
this.name = name;
}
- public String getUrl() {
- return url;
+ public Resource getResource() {
+ return resource;
}
- public void setUrl(String url) {
- this.url = url;
+ public void setResource(Resource resource) {
+ this.resource = resource;
}
public String getName() {
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/RuleDescr.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/RuleDescr.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/descr/RuleDescr.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;
+import org.drools.io.Resource;
import org.drools.rule.Dialectable;
import org.drools.rule.Namespaceable;
@@ -51,7 +52,7 @@
private String className;
- private String url;
+ private Resource resource;
public RuleDescr() {
}
@@ -84,7 +85,7 @@
attributes = (List<AttributeDescr>) in.readObject();
salience = (String) in.readObject();
className = (String) in.readObject();
- url = ( String ) in.readObject();
+ resource = ( Resource ) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
@@ -102,7 +103,7 @@
out.writeObject( attributes );
out.writeObject( salience );
out.writeObject( className );
- out.writeObject( url );
+ out.writeObject( resource );
}
public void setNamespace(String namespace) {
@@ -113,12 +114,12 @@
return this.namespace;
}
- public String getUrl() {
- return url;
+ public Resource getResource() {
+ return resource;
}
- public void setUrl(String url) {
- this.url = url;
+ public void setResource(Resource resource) {
+ this.resource = resource;
}
public String getName() {
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialect.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -32,6 +32,7 @@
import org.drools.compiler.PackageBuilder.RuleInvokerErrorHandler;
import org.drools.compiler.PackageBuilder.SrcErrorHandler;
import org.drools.definition.process.Process;
+import org.drools.io.Resource;
import org.drools.lang.descr.AccumulateDescr;
import org.drools.lang.descr.AndDescr;
import org.drools.lang.descr.BaseDescr;
@@ -578,7 +579,8 @@
}
public void addFunction(final FunctionDescr functionDescr,
- final TypeResolver typeResolver) {
+ final TypeResolver typeResolver,
+ final Resource resource) {
JavaDialectRuntimeData data = (JavaDialectRuntimeData) this.pkg.getDialectRuntimeRegistry().getDialectData( this.ID );
//System.out.println( functionDescr + " : " + typeResolver );
@@ -589,6 +591,7 @@
Function function = new Function( functionDescr.getName(),
this.ID );
+ function.setResource( resource );
this.pkg.addFunction( function );
final String functionSrc = getFunctionBuilder().build( this.pkg,
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -26,6 +26,7 @@
import org.drools.compiler.ImportError;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageRegistry;
+import org.drools.io.Resource;
import org.drools.lang.descr.AccumulateDescr;
import org.drools.lang.descr.AndDescr;
import org.drools.lang.descr.BaseDescr;
@@ -332,7 +333,8 @@
}
public void addFunction(FunctionDescr functionDescr,
- TypeResolver typeResolver) {
+ TypeResolver typeResolver,
+ Resource resource) {
Serializable s1 = compile( (String) functionDescr.getContent(),
null,
null,
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -9,6 +9,7 @@
import junit.framework.TestCase;
import org.drools.base.TypeResolver;
+import org.drools.io.Resource;
import org.drools.lang.descr.AndDescr;
import org.drools.lang.descr.AttributeDescr;
import org.drools.lang.descr.BaseDescr;
@@ -441,6 +442,13 @@
// TODO Auto-generated method stub
return null;
}
+
+ public void addFunction(FunctionDescr functionDescr,
+ TypeResolver typeResolver,
+ Resource resource) {
+ // TODO Auto-generated method stub
+
+ }
}
public static class MockEvalBuilder
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -46,6 +46,7 @@
import org.drools.commons.jci.compilers.JavaCompiler;
import org.drools.facttemplates.Fact;
import org.drools.integrationtests.SerializationHelper;
+import org.drools.io.Resource;
import org.drools.lang.descr.AndDescr;
import org.drools.lang.descr.BaseDescr;
import org.drools.lang.descr.ConditionalElementDescr;
@@ -1496,11 +1497,11 @@
Object value) {
}
- public String getURL() {
+ public Resource getResource() {
return null;
}
- public void setURL(String url) {
+ public void setResource(Resource resource) {
}
public String[] getGlobalNames() {
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/composition/CompositionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/composition/CompositionTest.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/composition/CompositionTest.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -1,7 +1,11 @@
package org.drools.xml.composition;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
+import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -10,6 +14,11 @@
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
+import org.drools.agent.KnowledgeAgent;
+import org.drools.agent.KnowledgeAgentConfiguration;
+import org.drools.agent.KnowledgeAgentFactory;
+import org.drools.agent.impl.KnowledgeAgentConfigurationImpl;
+import org.drools.agent.impl.KnowledgeAgentImpl;
import org.drools.builder.DecisionTableConfiguration;
import org.drools.builder.DecisionTableInputType;
import org.drools.builder.KnowledgeBuilder;
@@ -18,8 +27,9 @@
import org.drools.compiler.KnowledgeComposition;
import org.drools.compiler.KnowledgeResource;
import org.drools.compiler.PackageBuilderConfiguration;
+import org.drools.io.ResourceChangeScannerConfiguration;
import org.drools.io.ResourceFactory;
-import org.drools.io.impl.ClassPathResource;
+import org.drools.io.impl.ResourceChangeNotifierImpl;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.xml.XmlCompositionReader;
import org.xml.sax.SAXException;
@@ -77,7 +87,101 @@
ksession.dispose();
assertEquals( 2, list.size() );
- assertTrue ( list.containsAll( Arrays.asList( new String[] { "rule1", "rule2" } ) ) );
+ assertTrue ( list.containsAll( Arrays.asList( new String[] { "rule1", "rule2" } ) ) );
+ }
+
+ public void testIntegregation2() throws IOException, InterruptedException {
+ String rule1 = "";
+ rule1 += "package org.drools.test\n";
+ rule1 += "global java.util.List list\n";
+ rule1 += "rule rule1\n";
+ rule1 += "when\n";
+ rule1 += "then\n";
+ rule1 += "list.add( drools.getRule().getName() );\n";
+ rule1 += "end\n";
+ File f1 = File.createTempFile( "rule1", ".drl" );
+ f1.deleteOnExit();
+ Writer output = new BufferedWriter(new FileWriter(f1));
+ output.write( rule1 );
+ output.close();
- }
+ String rule2 = "";
+ rule2 += "package org.drools.test\n";
+ rule2 += "global java.util.List list\n";
+ rule2 += "rule rule2\n";
+ rule2 += "when\n";
+ rule2 += "then\n";
+ rule2 += "list.add( drools.getRule().getName() );\n";
+ rule2 += "end\n";
+ File f2 = File.createTempFile( "rule2", ".drl" );
+ f2.deleteOnExit();
+ output = new BufferedWriter(new FileWriter(f2));
+ output.write( rule2 );
+ output.close();
+
+ String xml = "";
+ xml += "<composition xmlns='http://drools.org/drools-4.0/composition'";
+ xml += " xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'";
+ xml += " xs:schemaLocation='http://drools.org/drools-4.0/composition drools-composition-4.0.xsd' >";
+ xml += " <resource source='" + f1.toURI().toURL() + "' type='DRL' />";
+ xml += " <resource source='" + f2.toURI().toURL() + "' type='DRL' />";
+ xml += "</composition>";
+ File fxml = File.createTempFile( "composition", ".xml" );
+ fxml.deleteOnExit();
+ output = new BufferedWriter(new FileWriter(fxml));
+ output.write( xml );
+ output.close();
+
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ kbuilder.add( ResourceFactory.newUrlResource( fxml.toURI().toURL() ), KnowledgeType.COMPOSITION );
+ assertFalse( kbuilder.hasErrors() );
+
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+ ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
+ sconf.setProperty( "drools.resource.scanner.interval", "2" );
+ ResourceFactory.getResourceChangeScannerService().configure( sconf );
+
+ KnowledgeAgentConfiguration aconf = new KnowledgeAgentConfigurationImpl();
+ aconf.setProperty( "drools.agent.scanResources", "true" );
+ aconf.setProperty( "drools.agent.newInstance", "true" );
+ KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("test agent", kbase, aconf);
+
+ StatefulKnowledgeSession ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
+ List list = new ArrayList();
+ ksession.setGlobal( "list", list );
+ ksession.fireAllRules();
+ ksession.dispose();
+
+ assertEquals( 2, list.size() );
+ assertTrue( list.contains( "rule1" ));
+ assertTrue( list.contains( "rule2" ));
+
+ list.clear();
+ rule1 = "";
+ rule1 += "package org.drools.test\n";
+ rule1 += "global java.util.List list\n";
+ rule1 += "rule rule3\n";
+ rule1 += "when\n";
+ rule1 += "then\n";
+ rule1 += "list.add( drools.getRule().getName() );\n";
+ rule1 += "end\n";
+ output = new BufferedWriter(new FileWriter(f1));
+ output.write( rule1 );
+ output.close();
+ Thread.sleep( 3000 );
+
+ ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
+ list = new ArrayList();
+ ksession.setGlobal( "list", list );
+ ksession.fireAllRules();
+ ksession.dispose();
+
+ assertEquals( 2, list.size() );
+ assertTrue( list.contains( "rule3" ));
+ assertTrue( list.contains( "rule2" ));
+ }
+
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/AgentEventListener.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/AgentEventListener.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/AgentEventListener.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -6,7 +6,7 @@
*
* @author Michael Neale
*/
-public interface AgentEventListener extends KnowledgeEventListener {
+public interface AgentEventListener extends KnowledgeAgentEventListener {
/**
* This sets the name for logging.
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/KnowledgeAgentProviderImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/KnowledgeAgentProviderImpl.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/KnowledgeAgentProviderImpl.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -1,75 +0,0 @@
-package org.drools.agent;
-
-import java.util.Properties;
-
-import org.drools.KnowledgeBase;
-import org.drools.KnowledgeBaseConfiguration;
-import org.drools.RuleBase;
-import org.drools.RuleBaseConfiguration;
-import org.drools.impl.KnowledgeBaseImpl;
-
-public class KnowledgeAgentProviderImpl
- implements
- KnowledgeAgentProvider {
-
- public KnowledgeAgent newKnowledgeAgent(String name,
- Properties config) {
- return new KnowledgeAgentWrapper( name,
- RuleAgent.newRuleAgent( config ) );
- }
-
- public KnowledgeAgent newKnowledgeAgent(String name,
- Properties config,
- KnowledgeBaseConfiguration kbaseConf) {
- return new KnowledgeAgentWrapper( name,
- RuleAgent.newRuleAgent( config ) );
- }
-
- public KnowledgeAgent newKnowledgeAgent(String name,
- Properties config,
- KnowledgeEventListener listener) {
- return new KnowledgeAgentWrapper( name,
- RuleAgent.newRuleAgent( config ) );
- }
-
- public KnowledgeAgent newKnowledgeAgent(String name,
- Properties config,
- KnowledgeEventListener listener,
- KnowledgeBaseConfiguration kbaseConf) {
- return new KnowledgeAgentWrapper( name,
- RuleAgent.newRuleAgent( config,
- null,
- ((RuleBaseConfiguration) kbaseConf) ) );
- }
-
- public static class KnowledgeAgentWrapper
- implements
- KnowledgeAgent {
- private String name;
- private RuleAgent ruleAgent;
- private RuleBase ruleBase;
- private KnowledgeBase kbase;
-
- KnowledgeAgentWrapper(String name,
- RuleAgent ruleAgent) {
- this.ruleAgent = ruleAgent;
- ruleAgent.listener.setAgentName( name );
- this.name = name;
- }
-
- public String getName() {
- return this.name;
- }
-
- public synchronized KnowledgeBase getKnowledgeBase() {
- RuleBase newRuleBase = this.ruleAgent.getRuleBase();
- if ( newRuleBase != this.ruleBase ) {
- // if ruleBase is null or newRuleBase is a new instance then create a new kbase.
- this.ruleBase = newRuleBase;
- this.kbase = new KnowledgeBaseImpl( this.ruleBase );
- }
- return this.kbase;
- }
- }
-
-}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleAgent.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleAgent.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleAgent.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -230,7 +230,6 @@
config.getProperty( key ) );
} else {
-
PackageProvider prov = getProvider( key,
config );
if ( prov != null ) {
Added: 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 (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,76 @@
+package org.drools.agent.impl;
+
+import java.util.Properties;
+
+import org.drools.PropertiesConfiguration;
+import org.drools.agent.KnowledgeAgentConfiguration;
+import org.drools.util.StringUtils;
+
+/**
+ * drools.agent.scanResources = <true|false>
+ * drools.agent.newInstance = <true|false>
+ *
+ */
+public class KnowledgeAgentConfigurationImpl
+ implements
+ KnowledgeAgentConfiguration {
+
+ private boolean scanResources;
+ private boolean newInstance;
+
+ public KnowledgeAgentConfigurationImpl() {
+
+ }
+
+ public KnowledgeAgentConfigurationImpl(Properties properties) {
+ for ( Object key : properties.keySet() ) {
+ setProperty( (String) key,
+ (String) properties.get( key ) );
+ }
+ }
+
+ public void setProperty(String name,
+ String value) {
+ name = name.trim();
+ if ( StringUtils.isEmpty( name ) ) {
+ return;
+ }
+
+ if ( name.equals( "drools.agent.scanResources" ) ) {
+ setScanResources( StringUtils.isEmpty( value ) ? true : Boolean.parseBoolean( value ) );
+ } else if ( name.equals( "drools.agent.newInstance" ) ) {
+ setNewInstance( StringUtils.isEmpty( value ) ? true : Boolean.parseBoolean( value ) );
+ }
+ }
+
+ public String getProperty(String name) {
+ name = name.trim();
+ if ( StringUtils.isEmpty( name ) ) {
+ return null;
+ }
+
+ if ( name.equals( "drools.agent.scanResources " ) ) {
+ return Boolean.toString( this.scanResources );
+ } else if ( name.equals( "drools.agent.newInstance " ) ) {
+ return Boolean.toString( this.newInstance );
+ }
+
+ return null;
+ }
+
+ public boolean isScanResources() {
+ return scanResources;
+ }
+
+ public void setScanResources(boolean scanResources) {
+ this.scanResources = scanResources;
+ }
+
+ public boolean isNewInstance() {
+ return newInstance;
+ }
+
+ public void setNewInstance(boolean newInstance) {
+ this.newInstance = newInstance;
+ }
+}
Added: 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 (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,187 @@
+package org.drools.agent.impl;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.drools.KnowledgeBase;
+import org.drools.KnowledgeBaseFactory;
+import org.drools.RuleBase;
+import org.drools.agent.KnowledgeAgent;
+import org.drools.agent.KnowledgeAgentConfiguration;
+import org.drools.agent.KnowledgeAgentEventListener;
+import org.drools.builder.KnowledgeBuilder;
+import org.drools.builder.KnowledgeBuilderFactory;
+import org.drools.builder.KnowledgeType;
+import org.drools.definition.process.Process;
+import org.drools.event.io.ResourceChangeListener;
+import org.drools.event.io.ResourceModifiedEvent;
+import org.drools.impl.KnowledgeBaseImpl;
+import org.drools.io.Resource;
+import org.drools.io.ResourceFactory;
+import org.drools.io.impl.ResourceChangeNotifierImpl;
+import org.drools.rule.Function;
+import org.drools.rule.Package;
+import org.drools.rule.Rule;
+import org.drools.rule.TypeDeclaration;
+
+public class KnowledgeAgentImpl
+ implements
+ KnowledgeAgent,
+ ResourceChangeListener {
+ private String name;
+ private Map<Resource, ResourceMapping> resources;
+ private KnowledgeBase kbase;
+ private ResourceChangeNotifierImpl notifier;
+ private boolean newInstance;
+ private KnowledgeAgentEventListener listener;
+
+ public KnowledgeAgentImpl(String name,
+ KnowledgeBase kbase,
+ KnowledgeAgentConfiguration configuration,
+ KnowledgeAgentEventListener listener) {
+ this.kbase = kbase;
+ this.resources = new HashMap<Resource, ResourceMapping>();
+ this.listener = listener;
+ if ( configuration != null ) {
+ this.newInstance = ((KnowledgeAgentConfigurationImpl) configuration).isNewInstance();
+ this.notifier = (ResourceChangeNotifierImpl) ResourceFactory.getResourceChangeNotifierService();
+ if ( ((KnowledgeAgentConfigurationImpl) configuration).isScanResources() ) {
+ this.notifier.addResourceChangeMonitor( ResourceFactory.getResourceChangeScannerService() );
+ }
+ }
+ buildResourceMapping( kbase );
+ }
+
+ public void buildResourceMapping(KnowledgeBase kbase) {
+ RuleBase rbase = ((KnowledgeBaseImpl) kbase).ruleBase;
+
+ synchronized ( this.resources ) {
+
+ for ( Package pkg : rbase.getPackages() ) {
+ for ( Rule rule : pkg.getRules() ) {
+ Resource resource = rule.getResource();
+ if ( resource == null || !resource.hasURL() ) {
+ continue;
+ }
+ ResourceMapping mapping = this.resources.get( resource );
+ if ( mapping == null ) {
+ this.notifier.subscribeResourceChangeListener( this,
+ resource );
+ mapping = new ResourceMapping( resource );
+ this.resources.put( resource,
+ mapping );
+ }
+ mapping.getObjects().add( rule );
+ System.out.println( "agent : " + resource );
+ }
+
+ for ( Process process : pkg.getRuleFlows().values() ) {
+ Resource resource = ((org.drools.process.core.Process) process).getResource();
+ if ( resource == null || !resource.hasURL() ) {
+ continue;
+ }
+ ResourceMapping mapping = this.resources.get( resource );
+ if ( mapping == null ) {
+ this.notifier.subscribeResourceChangeListener( this,
+ resource );
+ mapping = new ResourceMapping( resource );
+ this.resources.put( resource,
+ mapping );
+ }
+ mapping.getObjects().add( process );
+ System.out.println( "agent : " + resource );
+ }
+
+ for ( TypeDeclaration typeDeclaration : pkg.getTypeDeclarations().values() ) {
+ Resource resource = typeDeclaration.getResource();
+ if ( resource == null || !resource.hasURL() ) {
+ continue;
+ }
+ ResourceMapping mapping = this.resources.get( resource );
+ if ( mapping == null ) {
+ this.notifier.subscribeResourceChangeListener( this,
+ resource );
+ mapping = new ResourceMapping( resource );
+ this.resources.put( resource,
+ mapping );
+ }
+ mapping.getObjects().add( typeDeclaration );
+ System.out.println( "agent : " + resource );
+ }
+
+ for ( Function function : pkg.getFunctions().values() ) {
+ Resource resource = function.getResource();
+ if ( resource == null || !resource.hasURL() ) {
+ continue;
+ }
+ ResourceMapping mapping = this.resources.get( resource );
+ if ( mapping == null ) {
+ this.notifier.subscribeResourceChangeListener( this,
+ resource );
+ mapping = new ResourceMapping( resource );
+ this.resources.put( resource,
+ mapping );
+ }
+ mapping.getObjects().add( function );
+ System.out.println( "agent : " + resource );
+ }
+ }
+ }
+ }
+
+ public KnowledgeBase getKnowledgeBase() {
+ synchronized ( this.resources ) {
+ return this.kbase;
+ }
+ }
+
+ public void resourceModified(ResourceModifiedEvent event) {
+ ResourceMapping mapping = this.resources.get( event.getResource() );
+ System.out.println( "modified : " + event.getResource() );
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ synchronized ( this.resources ) {
+ for ( Resource resource : this.resources.keySet() ) {
+ System.out.println( "building : " + resource );
+ kbuilder.add( resource,
+ KnowledgeType.DRL );
+ }
+
+ this.kbase = KnowledgeBaseFactory.newKnowledgeBase();
+ this.kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+ }
+ }
+
+ public void resourceAdded(ResourceModifiedEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void resourceRemoved(ResourceModifiedEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public static class ResourceMapping {
+ private Resource resource;
+ private Set objects;
+
+ public ResourceMapping(Resource resource) {
+ this.objects = new HashSet<Object>();
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public Set getObjects() {
+ return objects;
+ }
+
+ }
+
+ public String getName() {
+ return this.name;
+ }
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentProviderImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentProviderImpl.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentProviderImpl.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,31 @@
+package org.drools.agent.impl;
+
+import java.util.Properties;
+
+import org.drools.KnowledgeBase;
+import org.drools.agent.KnowledgeAgent;
+import org.drools.agent.KnowledgeAgentConfiguration;
+import org.drools.agent.KnowledgeAgentProvider;
+import org.drools.agent.KnowledgeAgentEventListener;
+
+public class KnowledgeAgentProviderImpl implements KnowledgeAgentProvider {
+
+ public KnowledgeAgent newKnowledgeAgent(String name,
+ KnowledgeBase kbase) {
+ return new KnowledgeAgentImpl(name, kbase, null, null);
+ }
+
+ public KnowledgeAgent newKnowledgeAgent(String name,
+ KnowledgeBase kbase,
+ KnowledgeAgentConfiguration configuration) {
+ return new KnowledgeAgentImpl(name, kbase, configuration, null);
+ }
+
+ public KnowledgeAgent newKnowledgeAgent(String name,
+ KnowledgeBase kbase,
+ KnowledgeAgentConfiguration configuration,
+ KnowledgeAgentEventListener listener) {
+ return new KnowledgeAgentImpl(name, kbase, configuration, listener);
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/definitions/impl/KnowledgePackageImp.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/definitions/impl/KnowledgePackageImp.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/definitions/impl/KnowledgePackageImp.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -31,9 +31,9 @@
}
public Collection<Process> getProcesses() {
- Collection<org.drools.process.core.Process> processes = ( Collection<org.drools.process.core.Process> ) pkg.getRuleFlows().values();
+ Collection<org.drools.definition.process.Process> processes = ( Collection<org.drools.definition.process.Process> ) pkg.getRuleFlows().values();
List<Process> list = new ArrayList<Process>( processes.size() );
- for( org.drools.process.core.Process process : processes ) {
+ for( org.drools.definition.process.Process process : processes ) {
list.add( process );
}
return list;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseImpl.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/KnowledgeBaseImpl.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -58,7 +58,7 @@
implements
KnowledgeBase,
Externalizable {
- private RuleBase ruleBase;
+ public RuleBase ruleBase;
public Map<KnowledgeBaseEventListener, KnowledgeBaseEventListenerWrapper> mappedKnowledgeBaseListeners;
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-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ByteArrayResource.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -8,6 +8,7 @@
import java.io.Reader;
import java.net.URL;
import java.util.Arrays;
+import java.util.Date;
import org.drools.io.Resource;
@@ -39,6 +40,14 @@
public URL getURL() throws IOException {
throw new FileNotFoundException( "byte[] cannot be resolved to URL" );
}
+
+ public long getLastModified() {
+ throw new IllegalStateException( "reader does have a modified date" );
+ }
+
+ public long getLastRead() {
+ throw new IllegalStateException( "reader does have a modified date" );
+ }
public boolean equals(Object object) {
return (object == this || (object instanceof ByteArrayResource && Arrays.equals( ((ByteArrayResource) object).bytes,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ClassPathResource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ClassPathResource.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ClassPathResource.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -6,12 +6,14 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
+import java.net.URLConnection;
import org.drools.io.Resource;
/**
* Borrowed gratuitously from Spring under ASL2.0.
*
+ *+
*/
public class ClassPathResource
@@ -20,6 +22,7 @@
private String path;
private ClassLoader classLoader;
private Class clazz;
+ private long lastRead;
public ClassPathResource(String path) {
this( path,
@@ -76,6 +79,7 @@
if ( is == null ) {
throw new FileNotFoundException( "'" + this.path + "' cannot be opened because it does not exist" );
}
+ this.lastRead = getLastModified();
return is;
}
@@ -109,6 +113,21 @@
public boolean hasURL() {
return true;
}
+
+ public long getLastModified() {
+ try {
+ URLConnection conn = getURL().openConnection();
+ long date = conn.getLastModified();
+ return date;
+ } catch ( IOException e ) {
+ throw new RuntimeException( "Unable to get LastMofified for ClasspathResource",
+ e );
+ }
+ }
+
+ public long getLastRead() {
+ return this.lastRead;
+ }
public Reader getReader() throws IOException {
return new InputStreamReader( getInputStream() );
@@ -130,7 +149,7 @@
public int hashCode() {
return this.path.hashCode();
}
-
+
public String toString() {
return "[ClassPathResource path='" + this.path + "']";
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/EncodedResource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/EncodedResource.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/EncodedResource.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -76,8 +76,16 @@
public InputStream getInputStream() throws IOException {
return this.resource.getInputStream();
+ }
+
+ public long getLastModified() {
+ return this.resource.getLastModified();
}
+ public long getLastRead() {
+ return this.resource.getLastRead();
+ }
+
public String toString() {
return "[EncodedResource resource=" + this.resource + " encoding='" + this.encoding + "']";
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/FileSystemResource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/FileSystemResource.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/FileSystemResource.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -7,6 +7,7 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
+import java.util.Date;
import org.drools.io.Resource;
import org.drools.util.StringUtils;
@@ -17,6 +18,7 @@
*/
public class FileSystemResource implements Resource {
private File file;
+ private long lastRead = -1;
/**
* Create a new FileSystemResource from a File handle.
@@ -58,12 +60,17 @@
* @see java.io.FileInputStream
*/
public InputStream getInputStream() throws IOException {
+ this.lastRead = getLastModified();
return new FileInputStream(this.file);
}
public Reader getReader() throws IOException {
return new InputStreamReader( getInputStream() );
}
+
+ public File getFile() {
+ return this.file;
+ }
/**
* This implementation returns a URL for the underlying file.
@@ -75,8 +82,18 @@
public boolean hasURL() {
return true;
- }
+ }
+ public long getLastModified() {
+ long date = this.file.lastModified();
+ return date;
+ }
+
+ public long getLastRead() {
+ return this.lastRead;
+ }
+
+
public String toString() {
return "[FileResource file='" + this.file.toString() + "']";
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/InputStreamResource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/InputStreamResource.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/InputStreamResource.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -33,6 +33,14 @@
public boolean hasURL() {
return false;
- }
+ }
+
+ public long getLastModified() {
+ throw new IllegalStateException( "InputStream does have a modified date" );
+ }
+
+ public long getLastRead() {
+ throw new IllegalStateException( "InputStream does have a modified date" );
+ }
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ReaderResource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ReaderResource.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ReaderResource.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -6,6 +6,7 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
+import java.util.Date;
import org.drools.io.Resource;
@@ -30,7 +31,7 @@
}
public URL getURL() throws IOException {
- throw new FileNotFoundException( "byte[] cannot be resolved to URL");
+ throw new FileNotFoundException( "reader cannot be resolved to URL");
}
public InputStream getInputStream() throws IOException {
@@ -41,6 +42,14 @@
}
}
+ public long getLastModified() {
+ throw new IllegalStateException( "reader does have a modified date" );
+ }
+
+ public long getLastRead() {
+ throw new IllegalStateException( "reader does have a modified date" );
+ }
+
public Reader getReader() {
return this.reader;
}
Added: 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 (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,98 @@
+package org.drools.io.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.drools.event.io.ResourceChangeListener;
+import org.drools.event.io.ResourceChangeNotifier;
+import org.drools.event.io.ResourceModifiedEvent;
+import org.drools.io.Resource;
+import org.drools.io.ResourceChangeMonitor;
+
+public class ResourceChangeNotifierImpl
+ implements
+ ResourceChangeNotifier
+{
+ private Map<Resource, Set<ResourceChangeListener>> subscriptions;
+ private List<ResourceChangeMonitor> monitors;
+
+
+ public ResourceChangeNotifierImpl() {
+ this.subscriptions = new HashMap<Resource, Set<ResourceChangeListener>>();
+ this.monitors = new CopyOnWriteArrayList<ResourceChangeMonitor>();
+ }
+
+ public void addResourceChangeMonitor(ResourceChangeMonitor 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
+ ) {
+ 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 );
+ }
+ }
+ listeners.add( listener );
+ }
+
+ 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 );
+ }
+ }
+ }
+
+ public void resourceAdded(Resource resource) {
+
+ }
+
+ public void resourceModified(Resource resource) {
+ 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 resourceRemoved(Resource resource) {
+
+ }
+
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerConfigurationImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerConfigurationImpl.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerConfigurationImpl.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,55 @@
+package org.drools.io.impl;
+
+import java.util.Properties;
+
+import org.drools.io.ResourceChangeScannerConfiguration;
+import org.drools.util.StringUtils;
+
+public class ResourceChangeScannerConfigurationImpl implements ResourceChangeScannerConfiguration {
+
+ private int interval;
+
+ public ResourceChangeScannerConfigurationImpl() {
+
+ }
+
+ public ResourceChangeScannerConfigurationImpl(Properties properties) {
+ for( Object key : properties.keySet() ) {
+ setProperty( (String) key, (String) properties.get( key ) );
+ }
+ }
+
+ public void setProperty(String name,
+ String value) {
+ name = name.trim();
+ if ( StringUtils.isEmpty( name ) ) {
+ return;
+ }
+
+ if ( name.equals( "drools.resource.scanner.interval" ) ) {
+ setInterval( StringUtils.isEmpty( value ) ? 60 : Integer.parseInt( value ) );
+ }
+ }
+
+ public String getProperty(String name) {
+ name = name.trim();
+ if ( StringUtils.isEmpty( name ) ) {
+ return null;
+ }
+
+ if ( name.equals( "drools.resource.scanner.interval" ) ) {
+ return Integer.toString( this.interval );
+ }
+
+ return null;
+ }
+
+ public int getInterval() {
+ return interval;
+ }
+
+ public void setInterval(int interval) {
+ this.interval = interval * 1000;
+ }
+
+}
Added: 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 (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,118 @@
+package org.drools.io.impl;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.drools.event.io.ResourceChangeNotifier;
+import org.drools.io.Resource;
+import org.drools.io.ResourceChangeScanner;
+import org.drools.io.ResourceChangeScannerConfiguration;
+
+public class ResourceChangeScannerImpl
+ implements
+ ResourceChangeScanner,
+ Runnable {
+
+ private Map<Resource, Set<ResourceChangeNotifier>> resources;
+
+ private volatile boolean scan;
+
+ private volatile long interval;
+
+ public ResourceChangeScannerImpl() {
+ this.resources = new HashMap<Resource, Set<ResourceChangeNotifier>>();
+ setInterval( 60 );
+ this.scan = true;
+ }
+
+ public void configure(ResourceChangeScannerConfiguration configuration) {
+ this.interval = ((ResourceChangeScannerConfigurationImpl) configuration).getInterval();
+ System.out.println( this.interval );
+ synchronized ( this.resources ) {
+ this.resources.notify(); // notify wait, so that it will wait again
+ }
+ }
+
+ public ResourceChangeScannerConfiguration newResourceChangeScannerConfiguration() {
+ return new ResourceChangeScannerConfigurationImpl();
+ }
+
+ public ResourceChangeScannerConfiguration newResourceChangeScannerConfiguration(Properties properties) {
+ return new ResourceChangeScannerConfigurationImpl( properties );
+ }
+
+ public void subscribeNotifier(ResourceChangeNotifier notifier,
+ Resource resource) {
+ System.out.println( "scanner : " + resource );
+ synchronized ( this.resources ) {
+ Set<ResourceChangeNotifier> notifiers = this.resources.get( resource );
+ if ( notifiers == null ) {
+ notifiers = new HashSet<ResourceChangeNotifier>();
+ this.resources.put( resource,
+ notifiers );
+ }
+ notifiers.add( notifier );
+ }
+ }
+
+ public void unsubscribeNotifier(ResourceChangeNotifier notifier,
+ Resource resource) {
+ synchronized ( this.resources ) {
+ Set<ResourceChangeNotifier> notifiers = this.resources.get( resource );
+ if ( notifiers == null ) {
+ return;
+ }
+ notifiers.remove( notifier );
+ if ( notifiers.isEmpty() ) {
+ this.resources.remove( resource );
+ }
+ }
+ }
+
+ public void scan() {
+ System.out.println( "attempt scan : " + this.resources.size() );
+ for ( Entry<Resource, Set<ResourceChangeNotifier>> entry : this.resources.entrySet() ) {
+ Resource resource = entry.getKey();
+ for ( ResourceChangeNotifier notifier : entry.getValue() ) {
+ System.out.println( "scan " + resource + ": " + resource.getLastModified() + " : " + resource.getLastRead() );
+ if ( resource.getLastRead() < resource.getLastModified() ) {
+ notifier.resourceModified( resource );
+ }
+ }
+ }
+ }
+
+ public void start() {
+ this.scan = true;
+ }
+
+ public void stop() {
+ this.scan = false;
+ }
+
+ public void run() {
+ synchronized ( this.resources ) {
+ while ( scan ) {
+ scan();
+ try {
+ this.resources.wait( this.interval );
+ } catch ( InterruptedException e ) {
+ System.out.println( "wait interrupted, new interval is " + this.interval + "s" );
+ // swallow, this will happen when we are waiting and the interval changes
+ }
+ }
+ }
+ }
+
+ public void setInterval(int interval) {
+ this.interval = interval * 1000;
+ }
+
+ public int getInterval() {
+ return (int) this.interval / 1000;
+ }
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceModifiedEventImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceModifiedEventImpl.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceModifiedEventImpl.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -0,0 +1,34 @@
+/**
+ *
+ */
+package org.drools.io.impl;
+
+import org.drools.event.io.ResourceModifiedEvent;
+import org.drools.io.Resource;
+
+public class ResourceModifiedEventImpl implements ResourceModifiedEvent {
+ private Resource resource;
+ private long time;
+
+ public ResourceModifiedEventImpl(Resource resource,
+ long time) {
+ super();
+ this.resource = resource;
+ this.time = time;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.io.impl.ResourceModifiedEvent#getResource()
+ */
+ public Resource getResource() {
+ return resource;
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.io.impl.ResourceModifiedEvent#getTime()
+ */
+ public long getTime() {
+ return time;
+ }
+
+}
\ No newline at end of file
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-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceProviderImpl.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -5,13 +5,40 @@
import java.io.Reader;
import java.net.URL;
+import org.drools.event.io.ResourceChangeNotifier;
import org.drools.io.Resource;
+import org.drools.io.ResourceChangeScanner;
import org.drools.io.ResourceProvider;
public class ResourceProviderImpl
implements
ResourceProvider {
+ private ResourceChangeNotifier notifier;
+ private ResourceChangeScanner scanner;
+ private Object lock = new Object();
+ private Thread thread;
+
+ public ResourceChangeNotifier getResourceChangeNotifierService() {
+ synchronized ( this.lock ) {
+ if ( this.notifier == null ) {
+ this.notifier = new ResourceChangeNotifierImpl();
+ }
+ return this.notifier;
+ }
+ }
+
+ public ResourceChangeScanner getResourceChangeScannerService() {
+ synchronized ( this.lock ) {
+ if ( scanner == null ) {
+ this.scanner = new ResourceChangeScannerImpl( );
+ this.thread = new Thread( (ResourceChangeScannerImpl) this.scanner );
+ this.thread.start();
+ }
+ return this.scanner;
+ }
+ }
+
public Resource newByteArrayResource(byte[] bytes) {
return new ByteArrayResource( bytes );
}
@@ -22,12 +49,14 @@
public Resource newClassPathResource(String path,
ClassLoader classLoader) {
- return new ClassPathResource(path, classLoader);
+ return new ClassPathResource( path,
+ classLoader );
}
public Resource newClassPathResource(String path,
Class clazz) {
- return new ClassPathResource(path, clazz);
+ return new ClassPathResource( path,
+ clazz );
}
public Resource newFileSystemResource(File file) {
@@ -48,15 +77,15 @@
public Resource newReaderResource(Reader reader,
String encoding) {
- return new ReaderResource( reader, encoding);
+ return new ReaderResource( reader,
+ encoding );
}
public Resource newUrlResource(URL url) {
- return new UrlResource(url);
+ return new UrlResource( url );
}
public Resource newUrlResource(String path) {
return new UrlResource( path );
}
-
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/UrlResource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/UrlResource.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/UrlResource.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -7,6 +7,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
+import java.util.Date;
import org.drools.io.Resource;
import org.drools.util.StringUtils;
@@ -17,6 +18,7 @@
*/
public class UrlResource implements Resource {
private URL url;
+ private long lastRead = -1;
public UrlResource(URL url) {
this.url = getCleanedUrl( url,
@@ -41,6 +43,7 @@
* @see java.net.URLConnection#getInputStream()
*/
public InputStream getInputStream() throws IOException {
+ this.lastRead = getLastModified();
URLConnection con = this.url.openConnection();
con.setUseCaches(false);
return con.getInputStream();
@@ -75,8 +78,23 @@
public boolean hasURL() {
return true;
- }
+ }
+ public long getLastModified() {
+ try {
+ URLConnection conn = getURL().openConnection();
+ long date = conn.getLastModified();
+ return date;
+ } catch ( IOException e ) {
+ throw new RuntimeException( "Unable to get LastMofified for ClasspathResource",
+ e );
+ }
+ }
+
+ public long getLastRead() {
+ return this.lastRead;
+ }
+
/**
* This implementation compares the underlying URL references.
*/
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/Process.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/Process.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/Process.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -3,6 +3,8 @@
import java.util.List;
import java.util.Map;
+import org.drools.io.Resource;
+
public interface Process extends org.drools.definition.process.Process, ContextContainer {
/**
@@ -30,9 +32,9 @@
*/
void setType(String type);
- void setURL(String url);
+ void setResource(Resource resource);
- String getURL();
+ Resource getResource();
/**
* Sets the package name of this RuleFlow process
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/impl/ProcessImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/impl/ProcessImpl.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/core/impl/ProcessImpl.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;
+import org.drools.io.Resource;
import org.drools.process.core.Context;
import org.drools.process.core.ContextContainer;
import org.drools.process.core.Process;
@@ -42,7 +43,7 @@
private String version;
private String type;
private String packageName;
- private String url;
+ private Resource resource;
private ContextContainer contextContainer = new ContextContainerImpl();
private Map<String, Object> metaData = new HashMap<String, Object>();
private List<String> imports;
@@ -141,12 +142,12 @@
return this.metaData.get(name);
}
- public String getURL() {
- return this.url;
+ public Resource getResource() {
+ return this.resource;
}
- public void setURL(String url) {
- this.url = url;
+ public void setResource(Resource resource) {
+ this.resource = resource;
}
public List<String> getImports() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Function.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Function.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Function.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -5,9 +5,13 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
-public class Function implements Dialectable, Externalizable {
+import org.drools.definition.KnowledgeDefinition;
+import org.drools.io.Resource;
+
+public class Function implements KnowledgeDefinition, Dialectable, Externalizable {
private String name;
private String dialect;
+ private Resource resource;
public Function() {
@@ -26,14 +30,24 @@
public String getDialect() {
return this.dialect;
}
+
+ public Resource getResource() {
+ return this.resource;
+ }
+ public void setResource(Resource resource) {
+ this.resource = resource;
+ }
+
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
name = (String)in.readObject();
dialect = (String)in.readObject();
+ resource = ( Resource ) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(name);
out.writeObject(dialect);
+ out.writeObject(resource);
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -77,15 +77,15 @@
private Map factTemplates;
- private Map ruleFlows;
+ private Map<String, Process> ruleFlows;
// private JavaDialectData packageCompilationData;
private DialectRuntimeRegistry dialectRuntimeRegistry;
private Map<String, TypeDeclaration> typeDeclarations;
-
- private ClassFieldAccessorStore classFieldAccessorStore;
+ private ClassFieldAccessorStore classFieldAccessorStore;
+
/**
* This is to indicate the the package has no errors during the
* compilation/building phase
@@ -125,10 +125,10 @@
this.ruleFlows = Collections.EMPTY_MAP;
this.globals = Collections.EMPTY_MAP;
this.factTemplates = Collections.EMPTY_MAP;
- this.functions = Collections.EMPTY_MAP;
- this.dialectRuntimeRegistry = new DialectRuntimeRegistry( );
+ this.functions = Collections.EMPTY_MAP;
+ this.dialectRuntimeRegistry = new DialectRuntimeRegistry();
this.classFieldAccessorStore = new ClassFieldAccessorStore();
- }
+ }
/**
* Handles the write serialization of the Package. Patterns in Rules may
@@ -205,7 +205,7 @@
this.globals = (Map<String, String>) in.readObject();
this.valid = in.readBoolean();
this.rules = (Map) in.readObject();
- this.classFieldAccessorStore = ( ClassFieldAccessorStore ) in.readObject();
+ this.classFieldAccessorStore = (ClassFieldAccessorStore) in.readObject();
if ( !isDroolsStream ) {
in.close();
}
@@ -292,7 +292,7 @@
addGlobal( identifier,
clazz.getName() );
}
-
+
public void addGlobal(final String identifier,
final String className) {
if ( this.globals == Collections.EMPTY_MAP ) {
@@ -300,7 +300,7 @@
}
this.globals.put( identifier,
className );
- }
+ }
public void removeGlobal(final String identifier) {
this.globals.remove( identifier );
@@ -365,7 +365,7 @@
* Get the rule flows for this package. The key is the ruleflow id. It will
* be Collections.EMPTY_MAP if none have been added.
*/
- public Map getRuleFlows() {
+ public Map<String, Process> getRuleFlows() {
return this.ruleFlows;
}
@@ -559,5 +559,5 @@
public void setClassFieldAccessorCache(ClassFieldAccessorCache classFieldAccessorCache) {
this.classFieldAccessorStore.setClassFieldAccessorCache( classFieldAccessorCache );
}
-
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -28,6 +28,7 @@
import org.drools.WorkingMemory;
import org.drools.base.EnabledBoolean;
import org.drools.base.SalienceInteger;
+import org.drools.io.Resource;
import org.drools.spi.AgendaGroup;
import org.drools.spi.CompiledInvoker;
import org.drools.spi.Consequence;
@@ -121,7 +122,7 @@
private Enabled enabled;
- private String url;
+ private Resource resource;
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(pkg);
@@ -154,6 +155,7 @@
out.writeObject(dateEffective);
out.writeObject(dateExpires);
out.writeObject(enabled);
+ out.writeObject( resource );
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
@@ -183,6 +185,7 @@
dateEffective = (Calendar) in.readObject();
dateExpires = (Calendar) in.readObject();
enabled = (Enabled) in.readObject();
+ resource = ( Resource ) in.readObject();
}
// ------------------------------------------------------------
@@ -235,12 +238,12 @@
- public String getUrl() {
- return url;
+ public Resource getResource() {
+ return resource;
}
- public void setUrl(String url) {
- this.url = url;
+ public void setResource(Resource resource) {
+ this.resource = resource;
}
public String getDialect() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -26,6 +26,7 @@
import org.drools.factmodel.ClassDefinition;
import org.drools.facttemplates.FactTemplate;
+import org.drools.io.Resource;
import org.drools.spi.AcceptsReadAccessor;
import org.drools.spi.InternalReadAccessor;
@@ -84,6 +85,7 @@
private transient Class< ? > typeClass;
private FactTemplate typeTemplate;
private ClassDefinition typeClassDef;
+ private Resource resource;
public TypeDeclaration() {
}
@@ -110,6 +112,7 @@
this.typeClassDef = (ClassDefinition) in.readObject();
this.durationExtractor = (InternalReadAccessor) in.readObject();
this.timestampExtractor = (InternalReadAccessor) in.readObject();
+ this.resource = ( Resource ) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
@@ -123,6 +126,7 @@
out.writeObject( typeClassDef );
out.writeObject( durationExtractor );
out.writeObject( timestampExtractor );
+ out.writeObject( this.resource );
}
/**
@@ -298,4 +302,14 @@
setTimestampExtractor( readAccessor );
}
}
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public void setResource(Resource resource) {
+ this.resource = resource;
+ }
+
+
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java 2008-12-03 20:52:58 UTC (rev 24228)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java 2008-12-03 21:18:15 UTC (rev 24229)
@@ -271,65 +271,65 @@
}
- // FIXME - for some reason failing on hudson
- public void FIXME_testPollingFilesRuleBaseReplace2() throws Exception {
- File dir = RuleBaseAssemblerTest.getTempDirectory();
+// // FIXME - for some reason failing on hudson
+// public void FIXME_testPollingFilesRuleBaseReplace2() throws Exception {
+// File dir = RuleBaseAssemblerTest.getTempDirectory();
+//
+// Package p1 = new Package( "p1" );
+// File p1f = new File( dir,
+// "p43_.pkg" );
+// RuleBaseAssemblerTest.writePackage( p1,
+// p1f );
+//
+// Package p2 = new Package( "p2" );
+// File p2f = new File( dir,
+// "p44_.pkg" );
+// RuleBaseAssemblerTest.writePackage( p2,
+// p2f );
+//
+// String path = dir.getPath() + "/" + "p43_.pkg " + dir.getPath() + "/p44_.pkg";
+//
+// Properties props = new Properties();
+// props.setProperty( "file",
+// path );
+//
+// props.setProperty( "newInstance",
+// "true" );
+//
+// props.setProperty( "poll", "1" );
+//
+// KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "agent1", props );
+//
+// KnowledgeBase kbase = kagent.getKnowledgeBase();
+//
+// assertEquals( 2,
+// kbase.getKnowledgePackages().size() );
+//
+// KnowledgeBase kbase_ = kagent.getKnowledgeBase();
+// assertSame( kbase,
+// kbase_ );
+//
+// //only change one
+// RuleBaseAssemblerTest.writePackage( p1,
+// p1f );
+// int i = 0;
+// while ( i < 20 && kagent.getKnowledgeBase() == kbase ) {
+// // this will sleep for a max of 10 seconds, it'll check every 500ms to see if a new kbase exists
+// // if it exists, it will break the loop.
+// Thread.sleep( 500 );
+// i++;
+// }
+//
+// kbase_ = kagent.getKnowledgeBase();
+// assertNotSame( kbase,
+// kbase_ );
+//
+// //check we will have 2
+// assertEquals( 2,
+// kbase.getKnowledgePackages().size() );
+//
+// }
- Package p1 = new Package( "p1" );
- File p1f = new File( dir,
- "p43_.pkg" );
- RuleBaseAssemblerTest.writePackage( p1,
- p1f );
-
- Package p2 = new Package( "p2" );
- File p2f = new File( dir,
- "p44_.pkg" );
- RuleBaseAssemblerTest.writePackage( p2,
- p2f );
-
- String path = dir.getPath() + "/" + "p43_.pkg " + dir.getPath() + "/p44_.pkg";
-
- Properties props = new Properties();
- props.setProperty( "file",
- path );
-
- props.setProperty( "newInstance",
- "true" );
-
- props.setProperty( "poll", "1" );
-
- KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "agent1", props );
-
- KnowledgeBase kbase = kagent.getKnowledgeBase();
-
- assertEquals( 2,
- kbase.getKnowledgePackages().size() );
-
- KnowledgeBase kbase_ = kagent.getKnowledgeBase();
- assertSame( kbase,
- kbase_ );
-
- //only change one
- RuleBaseAssemblerTest.writePackage( p1,
- p1f );
- int i = 0;
- while ( i < 20 && kagent.getKnowledgeBase() == kbase ) {
- // this will sleep for a max of 10 seconds, it'll check every 500ms to see if a new kbase exists
- // if it exists, it will break the loop.
- Thread.sleep( 500 );
- i++;
- }
-
- kbase_ = kagent.getKnowledgeBase();
- assertNotSame( kbase,
- kbase_ );
-
- //check we will have 2
- assertEquals( 2,
- kbase.getKnowledgePackages().size() );
-
- }
-
public void testPollingFilesRuleBaseRemoveNewInstanceFalse() throws Exception {
File dir = RuleBaseAssemblerTest.getTempDirectory();
More information about the jboss-svn-commits
mailing list