Thanks, I'll try to reproduce it later. Just a couple of side notes..
Given that the rules fire correctly the first time, I would exclude that the
wrong URL is used. The ChangeScanner has a polling interval of **60**
seconds, so
changes may not be immediate. You can configure that interval, though.
In the logs, then, you should see something like :
"ResourceChangeScanner attempt to scan x resources"
(it's a DEBUG level message, you may want to configure log4j accordingly)
x obviously should be greater than 0.
You should then see a message saying that the ResourceChangeScanner
modified/removed/added some resources. If not, it's not picking up the
change..
I'd try forcing a PKG rebuild manually after changing the rules in guvnor.
The changeset.xsd error is just a warning, it won't affect execution.
On 05/02/2013 01:52 AM, riri wrote:
Here is the code I am using to create the knowledge base, knowledge
agent and
to retrieve the resources:
public static KnowledgeBase createKnowledgeBase(List<DroolsResource>
resources,
EventProcessingOption eventProcessingOption)
{
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
for (DroolsResource resource : resources)
{
logger.info("Resource: " + resource.getType() + ", path type="
+ resource.getPathType() + ", path=" + resource.getPath());
switch (resource.getPathType())
{
case CLASSPATH:
builder.add(ResourceFactory.newClassPathResource(resource.getPath()),
resource.getType());
break;
case FILE:
builder.add(ResourceFactory.newFileResource(resource.getPath()),
resource.getType());
break;
case URL:
UrlResource urlResource = (UrlResource) ResourceFactory
.newUrlResource(resource.getPath());
if (resource.getUsername() != null)
{
logger.info("Setting authentication for: " +
resource.getUsername());
urlResource.setBasicAuthentication("enabled");
urlResource.setUsername(resource.getUsername());
urlResource.setPassword(resource.getPassword());
}
builder.add(urlResource, resource.getType());
break;
default:
throw new IllegalArgumentException(
"Unable to build this resource path type.");
}
}
if (builder.hasErrors()) {
throw new RuntimeException(builder.getErrors().toString());
}
KnowledgeBaseConfiguration conf =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
// setting the STREAM option
conf.setOption(eventProcessingOption);
// modify the default identity compare mode to equality
conf.setOption(AssertBehaviorOption.EQUALITY);
KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase(conf);
knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
return knowledgeBase;
}
public static KnowledgeAgent createKnowledgeAgent(String
knowledgeAgentName, KnowledgeBase knowledgeBase)
{
KnowledgeAgentConfiguration aconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
aconf.setProperty("drools.agent.newInstance", "false");
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent(knowledgeAgentName, knowledgeBase,
aconf);
ResourceFactory.getResourceChangeScannerService().start();
ResourceFactory.getResourceChangeNotifierService().start();
return kagent;
}
public DroolsResource getGuvnorResource(User user)
{
String packageName = user.getUsername();
String guvnorBinaryResourceUrl =
"http://127.0.0.1:8080/guvnor/rest/packages/" + packageName +
"/binary";
return new DroolsResource(guvnorBinaryResourceUrl, ResourcePathType.URL,
ResourceType.PKG, credentials.getUserPrincipal().getName(),
credentials.getPassword());
}
Where the DroolsResource is a custom class to hold information about a
resource:
public class DroolsResource
{
private String path;
private ResourcePathType pathType;
private ResourceType type;
private String username = null;
private String password = null;
//getters, setters and constructors
}
To initialize the environement I just call the method to create the
knowledge base once I have the DroolsResource and then the method to create
the knowledge agent. Afterwards I create a statefull knowledge session using
the getKnowledgeBase() of the agent. Would the problem be the Guvnor url
that I am using? I used the rest version since it sais that it builds the
package automatically. Or the fact that the url is not in a change-set.xml
file?
When I run the session the first time (via the fireUntilHalt() in a separate
thread), rules get executed correctly and I call the halt() method to stop
it. If I then go and change a rule in the package and restart the session
then no changes are taken into account. Is the way I am executing the
sessions a problem? I do not want to recreate a new session every time since
I would have to reinsert all the facts, so I retrieve the session from the
knowledge base. I dispose of the session when the application is shut down.
I am new at this so I might be overlooking an important aspect.
Many thanks for all your help.
--
View this message in context:
http://drools.46999.n3.nabble.com/Re-rules-users-KnowledgeAgent-to-update...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users