The ResourceChangeScanner will consider a resource modified if last
modification > last read.
If your resource is a URL resource pointing to a file, the
implementation (version 5.6, at least)
will delegate to File.lastModified().
Make sure that whenever you (re)deploy your PKGs, the lastModified()
timestamp is updated
On 03/13/2014 12:47 PM, Peach Wyss wrote:
Hy all
We're having the following situation in our application:
ChangeSet:
<change-set
xmlns='http://drools.org/drools-5.0/change-set'
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
xs:schemaLocation='http://drools.org/drools-5.0/change-set
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/...
<add>
<resource source='file:rules/rules.pkg' type='PKG' />
</add>
</change-set>
Code:
...
// Build initial KnowledgeBase
KnowledgeBuilderConfiguration kbuilderConfig =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,
classloaders);
knowledgeBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(kbuilderConfig);
knowledgeBuilder.add(resource, resourceType); //Resource: URL-Resource
(Patch to ChangeSet), ResourceType: ChangeSet
Collection<KnowledgePackage> knowledgePackages =
knowledgeBuilder.getKnowledgePackages();
knowledgeBase.addKnowledgePackages(knowledgePackages);
// Create and configure Knowledge Agent
KnowledgeAgentConfiguration knowledgeAgentConfig =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
knowledgeAgentConfig.setProperty("drools.agent.useKBaseClassLoaderForCompiling",
"true");
knowledgeAgentConfig.setProperty("drools.agent.newInstance",
"false");
knowledgeAgent = KnowledgeAgentFactory.newKnowledgeAgent("MyAgent",
knowledgeBase, knowledgeAgentConfig);
knowledgeAgent.addEventListener(new KnowledgeAgentEventListener()
{...} // Just for debugging purposes
knowledgeAgent.monitorResourceChangeEvents(true);
knowledgeAgent.applyChangeSet(resource);
// Configure Notification and Scanner
ResourceChangeScannerConfiguration resourceChangeScannerConfig =
ResourceFactory
.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
resourceChangeScannerConfig.setProperty("drools.resource.scanner.interval",
"10");
ResourceFactory.getResourceChangeScannerService().configure(resourceChangeScannerConfig);
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
// Get KnowledgeBase from Agent
knowledgeBase = knowledgeAgent.getKnowledgeBase();
...
When i replace the rules.pkg with a new package (exported from guvnor
with a newer "Date Modified"), the Knowledge-Base is newly generated.
When I replace the pkg with the Package from the previous Version
(older "Date modified"), nothing happens (despite the pkg has changed).
Question:
Does the agent only updates the Knowledge-Base, when the replaced
pkg-File has a newer "Date Modified"?
In our scenario, the expected behaviour would be that the Agent
updates the Knowledge-Base everytime the pkg-file changes, so that we
can switch between newer and older versions of the pkg-file. Any idea
how to achieve this?
Thanks for your help.
Kind regards,
Peter
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users