Drools and threads
by Abhay B. Chaware
Hi
I have few questions about Drools.
Are rules compiled, partially compiled or interpreted ?
When I call fireAllRules(), does it ( or can it ) create a new thread that runs parallely or the operation is sequential and the caller program HAS TO wait till all rules execution is done ?
Also, How is the application data integrity guarantied? E.g. what happens when some of the facts are changed in middle of rules being executed .. ? what should happen ?
-abhay
13 years, 6 months
Is it possible to affect load order of rules?
by Martin, Matthias
Hello,
in our project we've to know, which rules have already been checked, regardless whether or not the rule gets activated and hence put on the agenda. Is there any possibility to affect the order, in which the drools engine reads and checks the LHS of rules? I suppose the assignment of a salience value has no effect on the load order and is rather a mechanism for conflict resolving, when a rule is about to be fired.
Background for this demand explained in an nutshell:
We use salience for conflict resolving. The conflicting rule with the highest salience value should be fired, but the others with minor salience values mustn't! In our scenario it can occur, that two (or more) rules might conflict at runtime. Therefore we want to perceive, which rule for which fact has already been checked, actually if it gets never activated on the agenda.
Example:
rule "morespecific"
salience 100
when myObj(variant = Variants.SPECIFIC_1 && fee < 10)
then....
end
rule "general"
salience 30
when myObj(fee < 100)
then....
end
If I set the value for variant to Variants.SPECIFIC_1 and the fee value to 30, for example, the first rule will never make it to the agenda but the second one does and is actually getting fired because it doesn't care about the variants value and 30 is less 100.
We want to perceive the already performed check for "morespecific" for a specific object und halt the execution of "general".
Any suggestions are welcome!
Regards,
Matthias Martin
13 years, 6 months
How can I access the updated JAR file in DRL file ???
by Vijeth Raj
Hi ,
Recently i was working on a drools project where i came across certain
issues and i need some help.
In my project i access jar at runtime by making use of the
URLClassLoader.Here is the code :
Object object=*null*;
Class myclass=*null*;
URL jarPath=*null*;
*try*{
jarPath=*new* File("lib/Billing.jar").toURI().toURL();
URLClassLoader loader = *new* URLClassLoader(*new* URL[] { jarPath },*
ClassLoader.*getClassLoader());
myclass = loader.loadClass("dynamicclasses.Billing");
object = myclass.newInstance();
}
*catch* (Exception e) {e.printStackTrace}
After getting the class instance I will set the values and pass the object
to my drools class
new DroolsClass().fireRules(object);
The drools class contain the following code :
public class DroolsClass {
*public* *void* fireRules(Object object){
*try* {
KnowledgeBase kbase = *readKnowledgeBase*();
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.*newFileLogger*(ksession, "test");
ksession.insert(object);
ksession.fireAllRules();
logger.close();
} *catch* (Throwable t) {
t.printStackTrace();
}
}
*private* *static* KnowledgeBase readKnowledgeBase() *throws* Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.*
newKnowledgeBuilder*();
kbuilder.add(ResourceFactory.*newFileResource*(
"./rulefiles/testing.drl"), ResourceType.*DRL*);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
// *------ some code*
KnowledgeBase kbase = KnowledgeBaseFactory.*newKnowledgeBase*();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
*return* kbase;
}
Next I have a drl file testing.drl which is present in the file directoty
and which accesses the same class dynamicclasses.Billing which is present in
Billing.jar
Here is the drl file content :
*import* dynamicclasses.Billing;
*rule* "rule 3"
*salience* 10
*dialect* "mvel"
*no-loop* *true*
*when*
m : Billing(bplan=="plan1")
*then*
System.out.println("You have opted for plan1");
*end*
* *
The problem I encounter is when the jar i.e Billing.jar get updated at
runtime the drl file i.e testing.drl
The following things i am trying to do.
1) I will create jar at runtime and update it if required.
2) I will create a drl file at runtime which will import the class present
in the jar i.e. dynamicclasses.Billing
I am able to access the updated jar contents in my java class ussing
URLClassLoader .But once i pass the object to my drools class i get the
following exception
Unable to resolve ObjectType 'Billing' : [Rule name='rule 3']
Error importing : 'dynamicclasses.Billing'
*java.lang.IllegalArgumentException*: Could not parse knowledge.
If i restart my application i get no exception since the jar is already
present but the object doesn't seem to pass to the drl and i get no result.
I made the following adjustment to the code :
URLClassLoader loader = new URLClassLoader(new URL[] { jarPath
},this.getClass().getClassLoader());
Here I get the same exception initially. But after I restart my application
it works fine and the rule get fired and I will get the result.
But again if I update the jar it will access only the previous content.
So it’s clear that the DRL file is not able to access the jar initially or
even after updating.
Is there any way so that I can make it work?
Thanks.
--
Thanks & Regards,
Vijeth Raj K
Email : vijethrajk(a)gmail.com
13 years, 6 months
Complicated Grant Permissions Logic
by ginni
Hi,
I am new to Drools and would just like to understand how to do what I am
trying to do. This syntax does not work, and I am not sure how to make it
work. I want permission granted if:
User is Librarian
OR user is Submitter OR user is Requester AND requestSubmitted is false
AND
requestCancelable is true
This syntax requires the user to be both librarian AND submitter or
requester.
when
$perm: PermissionCheck(target == "libraryRequest", action ==
"cancelRequest", granted == false)
RequestState($requestCancelable: requestCancelable, $requestSubmitted:
requestSubmitted)
Role(name == "APP_LIBRARY REQUESTS_LIBRARY STAFF")
eval($requestCancelable == true ||
($submitter.getBadgeNumber().equals($userBadge) ||
$requester.getBadgeNumber().equals($userBadge) && !requestSubmitted))
)
Any help would be greatly appreciated!!
Thanks,
Ginni
--
View this message in context: http://drools.46999.n3.nabble.com/Complicated-Grant-Permissions-Logic-tp2...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 6 months
drools-spring drools-grid-impl dependency
by Tommy Odom
Hi,
I was attempting to try an upgrade from drools 5.1.1 today to 5.2.0.M2 but I ran into a problem with using the drools-spring artifact. Since drools-spring needs access to the GridNode it has a dependency on drools-grid-impl which in turn has dependencies on hibernate & JPA 1.0 and includes a persistence.xml file. I was able to work around the hibernate and JPA 1.0 dependencies using maven exclusion rules but it appears that the included persistence.xml is causing problems with my own configuration locating its persistence unit.
Would it be possible to extract the grid classes that drools-spring is dependent on out into a drools-grid artifact that instead of depending on the full impl? Either that or does anyone have any suggestions for making sure my persistence.xml in my WAR takes precedence over the one in the JAR?
Thanks!
13 years, 6 months
Facing Problem in BRL
by Sumeet Karawal
Hi,
I am using Drools-Expert. I am having a class "Person" with data members as
age and discount.
I am trying to create a .brl. I have these statements in drools.package
package com.rules;
import com.model.PersonDetails;
and in the example.brl I am providing the details of when and then
conditions
but on execution I am getting the following error :
java.lang.RuntimeException: [4] Unable to expand: PersonDetails( age <
"20" )[6] Unable to expand: PersonDetails fact0 = new PersonDetails
();[7] Unable to expand: fact0.setDiscount( 10 );[8] Unable to
expand: insert(fact0 );
It would be helpful is somebody guide me on how execute it.
Also, I am creating the knowledgebase as:
private static KnowledgeBase createKnowledgeBase() {
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
builder.add (ResourceFactory.newClassPathResource(
"com/rules/example.brl"),ResourceType.BRL);
if (builder.hasErrors()) {
throw new RuntimeException (builder.getErrors().toString ());
}
KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages ());
return knowledgeBase;}
Thanks & Regards,
Sumeet Karawal
CEG - Open Source Technology Group
Tata Consultancy Services
Ph:- +912267782556
Cell:- +919833236440
Mailto: sumeet.karawal(a)tcs.com
Website: http://www.tcs.com
____________________________________________
Experience certainty. IT Services
Business Solutions
Outsourcing
____________________________________________
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
13 years, 6 months
How to run one example of drools in eclipse?
by clement.pernot
hi,
I have download: "Drools Examples" on http://www.jboss.org/drools/downloads
I use eclipse in order to build.
I have follow this:
https://github.com/droolsjbpm/droolsjbpm-build-bootstrap/blob/master/READ...
in order to configure eclipse.
I don't know what i must do.
After one build i got this:
Apache Maven 3.0.2 (r1056850; 2011-01-09 01:58:10+0100)
Java version: 1.6.0_24, vendor: Sun Microsystems Inc.
Java home: /home/newel/eclipse/jre
Default locale: fr_FR, platform encoding: UTF-8
OS name: "linux", version: "2.6.35-28-generic", arch: "i386", family: "unix"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from EMBEDDED/conf/settings.xml
[DEBUG] Reading user settings from /home/newel/.m2/settings.xml
[DEBUG] Using local repository at /home/newel/.m2/repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for
/home/newel/.m2/repository
[INFO] Scanning for projects...
[DEBUG] Verifying availability of
/home/newel/.m2/repository/org/drools/drools/5.1.1/drools-5.1.1.pom from
[central (http://repo1.maven.org/maven2, releases=true, snapshots=false,
managed=false)]
[DEBUG] Using connector AsyncRepositoryConnector with priority 100 for
http://repo1.maven.org/maven2
[DEBUG] Reading resolution tracking file
/home/newel/.m2/repository/org/drools/drools/5.1.1/drools-5.1.1.pom.lastUpdated
[DEBUG] Writing resolution tracking file
/home/newel/.m2/repository/org/drools/drools/5.1.1/drools-5.1.1.pom.lastUpdated
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were
encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not find artifact
org.drools:drools:pom:5.1.1 in central (http://repo1.maven.org/maven2) and
'parent.relativePath' points at wrong local POM @ line 5, column 11
at
org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:325)
at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:632)
at
org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:581)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:233)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at
org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at
org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at
org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
[ERROR]
[ERROR] The project org.drools:drools-examples:5.1.1
(/home/newel/workspace/drools-5.1.1-examples/drools-examples/pom.xml) has 1
error
[ERROR] Non-resolvable parent POM: Could not find artifact
org.drools:drools:pom:5.1.1 in central (http://repo1.maven.org/maven2) and
'parent.relativePath' points at wrong local POM @ line 5, column 11 -> [Help
2]
org.apache.maven.model.resolution.UnresolvableModelException: Could not find
artifact org.drools:drools:pom:5.1.1 in central
(http://repo1.maven.org/maven2)
at
org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:183)
at
org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:819)
at
org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:670)
at
org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:308)
at
org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:232)
at
org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:354)
at
org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:305)
at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:632)
at
org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:581)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:233)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at
org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at
org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at
org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.sonatype.aether.resolution.ArtifactResolutionException: Could
not find artifact org.drools:drools:pom:5.1.1 in central
(http://repo1.maven.org/maven2)
at
org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:526)
at
org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:214)
at
org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:179)
... 21 more
Caused by: org.sonatype.aether.transfer.ArtifactNotFoundException: Could not
find artifact org.drools:drools:pom:5.1.1 in central
(http://repo1.maven.org/maven2)
at
org.sonatype.aether.connector.async.AsyncRepositoryConnector$3.wrap(AsyncRepositoryConnector.java:1409)
at
org.sonatype.aether.connector.async.AsyncRepositoryConnector$3.wrap(AsyncRepositoryConnector.java:1404)
at
org.sonatype.aether.connector.async.AsyncRepositoryConnector$GetTask.flush(AsyncRepositoryConnector.java:895)
at
org.sonatype.aether.connector.async.AsyncRepositoryConnector$GetTask.flush(AsyncRepositoryConnector.java:889)
at
org.sonatype.aether.connector.async.AsyncRepositoryConnector.get(AsyncRepositoryConnector.java:276)
at
org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:438)
... 23 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please
read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2]
http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-run-one-example-of-drools-in-ecl...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 6 months