Hi, I have managed to install Drools-core and Drools-compiler in my Equinox
osgi environment, I can compile rules and execute them just fine, I was just
wandering how to configure a KnowledgeAgent using
KnowledgeBuilderFactoryService and KnowledgeBaseFactoryService. I managed to
configure one but i am not able to reload rules when they change at runtime.
I have started ResourceChangeScannerService and
ResourceChangeNotifierService, changeset related to the rules file gets read
but no change gets implemented. An idea?
Here is the code:
ResourceFactory.getResourceChangeScannerService().start();
ResourceFactory.getResourceChangeNotifierService().start();
ServiceReference serviceRef = bc
.getServiceReference(ServiceRegistry.class.getName());
ServiceRegistry registry = (ServiceRegistry) bc.getService(serviceRef);
KnowledgeBuilderFactoryService knowledgeBuilderFactoryService = registry
.get(KnowledgeBuilderFactoryService.class);
KnowledgeBaseFactoryService knowledgeBaseFactoryService = registry
.get(KnowledgeBaseFactoryService.class);
ResourceFactoryService resourceFactoryService = registry
.get(ResourceFactoryService.class);
KnowledgeBuilderConfiguration kbConf = knowledgeBuilderFactoryService
.newKnowledgeBuilderConfiguration(null, getClass()
.getClassLoader());
KnowledgeBuilder kbuilder = knowledgeBuilderFactoryService
.newKnowledgeBuilder(kbConf);
ResourceFactoryService resource = resourceFactoryService;
kbuilder.add(resource.newFileSystemResource(filePath),
ResourceType.CHANGE_SET);
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors());
throw new RuntimeException(kbuilder.getErrors().toString());
}
KnowledgeBaseConfiguration kbaseConf = knowledgeBaseFactoryService
.newKnowledgeBaseConfiguration(null, getClass()
.getClassLoader());
KnowledgeBase kbase = knowledgeBaseFactoryService
.newKnowledgeBase(kbaseConf);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
KnowledgeAgentConfiguration aconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
aconf.setProperty("drools.agent.scanDirectories", "true");
aconf.setProperty("drools.agent.scanResources", "true");
aconf.setProperty("drools.agent.newInstance", "false");
kagent = KnowledgeAgentFactory.newKnowledgeAgent( "CoreDroolsAgent",kbase,
aconf);
kagent.applyChangeSet(resource.newFileSystemResource(filePath));
Thanks in advance!
Cheers
--
View this message in context:
http://drools-java-rules-engine.46999.n3.nabble.com/KnowledgeAgent-and-OS...
Sent from the Drools - User mailing list archive at
Nabble.com.