Drools scalability
by S Feseha
Can one session be shared amongst multiple threads? In the book Drools JBoss Rules 5.0 Developer's Guide it says that sessions cannot be shared as they contain state which i understand but in chapter 12 they say that "Drools supports parallel execution mode. One session can be executed by multiple threads." using Knowledge partitioning what exactly does this mean?
Thanks in advance
15 years, 6 months
Steps for uploading model jar and decision table in guvnor
by Swapnil Sawant
Hi,
PFA the model jar and decision table that I have created .
myTest.jar contains my model class 'AmountPojo' and currently I have written only one PF rule using this 'AmountPojo' class
I have done following things successfully on guvnor GUI :
- uploading of model jar in a package(named Test)
- uploading decision table xls in same package
- 'save and validate configuration' and 'building package'after above steps
- Creating test scenario for testing that my rule is working fine
Now, I wish to utilize this package in my application through changeset.xml. For this, I wrote something like :
<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 drools-change-set-5.0.xsd' >
<add>
<resource source='https://ofbiz.apache.org:8443/drools-guvnor/org.drools.guvnor.Guvnor/pack...' type='DRL' />
</add>
</change-set>
Also, in my code I have created knowledge agent like dis :
kagent = KnowledgeAgentFactory.newKnowledgeAgent( "MyRuleAgent" );
String changesetUrl = "file:"+currentWorkingDirectory+"/framework/drools/config/changeset.xml";
kagent.applyChangeSet( ResourceFactory.newUrlResource( changesetUrl ) );
Using this 'kagent' I have created knowledge base like dis :
if(kbase==null){
kbase = kagent.getKnowledgeBase();
}
When kagent.applychaneset line executes, it throws following error :
[Error: Failed to compile: 4 compilation error(s):
- (1,9) unqualified type in strict mode for: amtEntity
- (1,9) unqualified type in strict mode for: amtEntity
- (1,15) unqualified type in strict mode for: basic
- (1,40) unable to resolve method using strict-mode: java.lang.Object.setHra(java.lang.Object)]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:78)
at org.drools.base.mvel.MVELCompilationUnit.compile(MVELCompilationUnit.java:365)
at org.drools.base.mvel.MVELCompilationUnit.getCompiledExpression(MVELCompilationUnit.java:288)
at org.drools.base.mvel.MVELConsequence.compile(MVELConsequence.java:49)
at org.drools.rule.builder.dialect.mvel.MVELConsequenceBuilder.build(MVELConsequenceBuilder.java:107)
at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:86)
at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:1168)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:654)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:291)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:489)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:25)
at org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:387)
at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:121)
at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:110)
at org.ofbiz.drools.event.drool.RuleIntegrate.createKnowledgeBase(RuleIntegrate.java:46)
at org.ofbiz.drools.event.drool.RuleIntegrate.createWorkingMemory(RuleIntegrate.java:29)
at org.ofbiz.payroll.DroolsRule.callRuleJava(DroolsRule.java:42)
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.ofbiz.service.engine.StandardJavaEngine.serviceInvoker(StandardJavaEngine.java:100)
at org.ofbiz.service.engine.StandardJavaEngine.runSync(StandardJavaEngine.java:57)
at org.ofbiz.service.ModelServiceReader$GenericInvokerImpl.runSync(ModelServiceReader.java:761)
at _$gen.file_58$.D_58$.Swapnil_95$Data.ofbiz_95$trunk_95$06_95$22.applications.payroll.servicedef.services_46$xml_3
at org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:399)
at org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:226)
at org.ofbiz.service.GenericDispatcher.runSync(GenericDispatcher.java:165)
at org.ofbiz.webapp.event.ServiceEventHandler.invoke(ServiceEventHandler.java:336)
at org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:633)
at org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:379)
at org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:224)
at org.ofbiz.webapp.control.ControlServlet.doPost(ControlServlet.java:87)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:271)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
[2010:08:233 16:08:734:debug] KnowledgeAgent building resource=[UrlResource path='https://ofbiz.apache.org:8443/drools-guvno
[2010:08:233 16:08:359:debug] KnowledgeAgent has KnowledgeBuilder errors object=Unable to resolve ObjectType 'AmountPojo' :
Unable to resolve ObjectType 'AmountPojo' : [Rule name='HRA rule']
Unable to build expression for 'consequence': Failed to compile: 4 compilation error(s):
- (1,9) unqualified type in strict mode for: amtEntity
- (1,9) unqualified type in strict mode for: amtEntity
- (1,15) unqualified type in strict mode for: basic
- (1,40) unable to resolve method using strict-mode: java.lang.Object.setHra(java.lang.Object) ' amtEntity.setHra( am
' : [Rule name='HRA rule']
Error importing : 'com.sample.AmountPojo'Error importing : 'com.sample.PFRules'Error importing : 'com.sample.SpreadsheetComp
Test/Rule_PF_Rules_11_0.java (2:22) : Only a type can be imported. com.sample.SpreadsheetCompiler resolves to a pack
Test/Rule_PF_Rules_11_0.java (2:60) : Only a type can be imported. com.sample.AmountPojo resolves to a package
Test/Rule_PF_Rules_11_0.java (2:89) : Only a type can be imported. com.sample.PFRules resolves to a package
Test/Rule_PF_Rules_11_0.java (7:371) : a cannot be resolved
Test/Rule_PF_Rules_11_0.java (7:379) : a cannot be resolved
Test/Rule_PF_Rules_11_0.java (8:460) : a cannot be resolved
It seems that it is not able to recognize 'AmountPojo' class.thereby considering it as 'Object' type and applying setHra() on it.
Any idea why this is occuring ? How to communicate about 'AmountPojo' Type in code ?
Also,
After this, I wanted to know the steps for 'inserting fact type object for AmountPojo' in the session created.
For this I read in docs that use following lines of code :
// Retrieve the generated fact type
FactType cheeseFact = ruleBase.getFactType( "org.drools.generatedbeans.Cheese" );
// Create a new Fact instance
Object cheese = cheeseFact.newInstance();
cheeseFact.set( cheese,
"type",
"stilton" );
But, I didnt find any method like KnowledgeBase.getFactType(String fullyQualifiedfactTypePath) . There is only one KnowledgeBase.getFactType(String pckname,String factTypeName) method in it
Please let me the know the right way of achieving this .
Thanks,
Swapnil Sawant
This Email may contain confidential or privileged information for the intended recipient (s) If you are not the intended recipient, please do not use or disseminate the information, notify the sender and delete it from your system.
______________________________________________________________________
15 years, 6 months
Migration from drools 5.0 to 5.1
by Swapnil Sawant
Hi,
Using drools 5.0 APIs, I have written a kind of framework component code using which I am able to achieve following functionalities successfully :
- Running rules using changeset.xml
- Executing workflow
Example of framework component code can be :
- Creating knowledge agent
- Applying changeset to it
- Building knowledge base out of that agent
- Creating stateful knowledge session
- Inserting fact types into this session , fire rules and get result
Now that 5.1 stable version has been released, I want to know if I just replace the 5.0 jars with 5.1 jars in my framework code, would I be able to achieve same results as they were when I was using 5.0 API ?
Or there is/are some change/s in the APIs ?
Thanks & Regards,
Swapnil Sawant
________________________________
This Email may contain confidential or privileged information for the intended recipient (s) If you are not the intended recipient, please do not use or disseminate the information, notify the sender and delete it from your system.
______________________________________________________________________
15 years, 6 months
Left and Right Unlinking - Community Project Proposal
by Mark Proctor
In an effort to help encourage those thinking of learning more about
the internals of rule engines. I have made a document on implementating
left and right unlinking. I describe the initial paper in terms relevant
to Drools users, and then how that can be implemented in Drools and a
series of enhancements over the original paper. The task is actually
surprisingly simple and you only need to learn a very small part of the
Drools implementation to do it, as such it's a great getting started
task. For really large stateful systems of hundreds or even thousands of
rules and hundreds of thousands of facts it should save significant
amounts of memory.
http://blog.athico.com/2010/08/left-and-right-unlinking-community.html
Any takers?
Mark
Introduction
The following paper describes Left and Right unlinking enhancements for
Rete based networks:
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.6246
<http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.6246>
A rete based rule engine consists of two parts of the network, the alpha
nodes and the beta nodes. When an object is first inserted into the
engine it is discriminated against by the object type Node, this is a
one input and one output node. From there it may be further
discriminated against by alpha nodes that constrain on literal values
before reaching the right input of a join node in the beta part of the
network. Join nodes have two inputs, left and right. The right input
receives propagations consisting of a single object from the alpha part
of the network. The left input receives propagations consisting of 1 or
more objects, from the parent beta node. We refer to these propagating
objects as LeftTuple and RightTuple, other engines also use the terms
tokens or partial matches. When a tuple propagation reaches a left or
right input it's stored in that inputs memory and it attempts to join
with all possible tuples on the opposite side. If there are no tuples on
the opposite side then no join can happen and the tuple just waits in
the node's memory until a propagation from the opposite side attempts to
join with it. If a given. It would be better if the engine could avoid
populating that node's memory until both sides have tuples. Left and
right unlinking are solutions to this problem.
The paper proposes that a node can either be left unlinked or right
unlinked, but not both, as then the rule would be completely
disconnected from the network. Unlinking an input means that it will not
receive any propagations and that the node's memory for that input is
not populated, saving memory space. When the opposite side, which is
still linked, receives a propagation the unlinked side is linked back in
and receives all the none propagated tuples. As both sides cannot be
unlinked, the paper describes a simple heuristic for choosing which side
to unlink. Which ever side becomes empty first, then unlink the other.
It says that on start up just arbitrarily chose to unlink one side as
default. The initial hit from choosing the wrong side will be
negligible, as the heuristic corrects this after the first set of
propagations.
If the left input becomes empty the right input is unlink, thus clearing
the right input's memory too. The moment the left input receives a
propagation it re-attaches the right input fully populating it's memory.
The node can then attempt joins as normal. Vice-versa if the right input
becomes empty it unlinks the left input. The moment the right input
receives a propagation it re-attaches the left input fully populating
it's memory so that the node can attempt to join as normal.
Implementing Left and Right Unlinking for shared Knowledge Bases
The description of unlinking in the paper won't work for Drools or for
other rule engines that share the knowledge base between multiple
sessions. In Drools the session data is decoupled from the main
knowledge base and multiple sessions can share the same knowledge base.
The paper above describes systems where the session data is tightly
coupled to the knowledge base and the knowledge base has only a single
session. In shared systems a node input that is empty for one session
might not be empty for another. Instead of physically unlinking the
nodes, as described in the paper, an integer value can be used on the
session's node memory that indicates if the node is unlinked for left,
right or both inputs. When the propagating node attempts to propagate
instead of just creating a left or right tuple and pushing it into the
node. It'll first retrieve the node's memory and only create the tuple
and propagate if it's linked.
This is great as it also avoids creating tuple objects that would just
be discarded afterwards as there would be nothing to join with, making
things lighter on the GC. However it means the engine looks up the node
memory twice, once before propagating to the node and also inside of the
node as it attempt to do joins. Instead the node memory should be looked
up once, prior to propagating and then passed as an argument, avoiding
the double lookup.
Traditional Rete has memory per alpha node, for each literal constraint,
in the network. Drools does not have alpha memory, instead facts are
pulled from the object type node. This means that facts may needlessly
evaluate in the alpha part of the network, only to be refused addition
to the node memory afterwards. Rete supports something called "node
sharing", where multiple rules with similar constructs use the same
nodes in the network. For this reason shared nodes cannot easily be
unlinked. As a compromise when the alpha node is no longer shared, the
network can do a node memory lookup, prior to doing the evaluation and
check if that section of the network is unlinked and avoid attempting
the evaluation if it is. This allows for left and right unlinking to be
used in a engine such as Drools.
Using Left and Right Unlinking at the Same Time
The original paper describes an implantation in which a node cannot have
both the left and right inputs unlinked for the same node. Building on
the extension above to allow unlinking to work with a shared knowledge
base the initial linking status value can be set to both left and right
being unlinked. However in this initial state, where both sides are
unlinked, the leaf node's right input isn't just waiting for a left
propagation so the right can re-link itself (which it can't as the left
is unlinked too). It's also waiting to receive it's first propagation,
when it does it will link the left input back in. This will then tell
it's parent node's right input to also do the same, i.e. wait for it's
first right input propagation and link in the left when it happens. If
it already has a right propagation it'll just link in the left anyway.
This will trickle up until the root is finally linked in and
propagations can happen as normally, and the rule's nodes return to the
above heuristics for when to link and unlink the nodes.
Avoid Unnecessary Eager Propagations
A rule always eagerly propagates all joins, regardless of whether the
child node can undertake joins too, for instance of there is no
propagates for the leaf node then no rules can fire, and the eager
propagations are wasted work. Unlinking can be extended to try to
prevent some level of eager propagations. Should the leaf node become
right unlinked and that right input also become empty it will unlink the
left too (so both sides are unlinked) and go back to waiting for the
first right propagation, at which point it'll re-link the left. If the
parent node also has it's right input unlinked at the point that it's
child node unlinks the left it will do this too. It will repeat this up
the chain until it reaches a node that has both left and right linked
in. This stops any further eager matching from occurring that we know
can't result in an activation until the leaf node has at least one right
input.
Heuristics to Avoid Churn from Excessive and Unnecessary Unlinking
The only case where left and right linking would be a bad idea is in
situations that would cause a "churn". Churn is when a node with have a
large amount of right input memory is continually caused to be linked in
and linked out, forcing those nodes to be repeatedly populated which
causes a slow down. However heuristics can be used here too, to avoid
unnecessary unlinking. The first time an input becomes empty unlink the
opposite and store a time stamp (integer counter for fact handles from
the WM). Then have a minimum delta number, say 100. The next time it
attempts to unlink, calculate the delta of the current time stamp
(integer counter on fact handle) and the time stamp of the node which
last unlinked (which was recorded at the point of unlinking) if it's
less than 100 then do nothing and don't unlink until it's 100 or more.
If it's 100 or more then unlink and as well as storing the unlink time
stamp, then take the delta of 100 or more and apply a multiple (2, 3, 4
etc depending on how steep you want it to rise, 3 is a good starting
number) and store it. Such as if the delta is 100 then store 300. The
next time the node links and attempts to unlink it must be a delta of
300 or more, the time after that 900 the time after that 2700.
15 years, 6 months
Multi-user architecture of Drools Web Service.
by tom ska
Hi,
what I have is SOAP Web Service with two methods: fn_AddFacts, and
fn_Conclude. I defined special XML implementation to send various fact's
types via SOAP. Model is defined in DRL/Guvnor - and rules too.
So now, I can add some facts (web service creates them using Drools
"reflection" API) to knowledge base. And then use fn_Conclude method, to
fire "fireAllRules" method and get response with results. But.....
What if now I have 100 users, and I don't want their's facts to interfere
each other? I want, to use Drools to conclude for different users. I want to
use this same rules, but on different knowledge bases (each user has own
knowledge base of his facts).
Please help me, how to solve this problem... I am new in JAVA EE, and I
don't understand some elementary issues well. (But I am trying to understand
them :D )
regards,
tom.
15 years, 6 months
error while inserting values in excel
by Kripa Nathwani
Hi,
Below is the decision table on which I am working. It is calculating PF and HRA by taking basic value and checking that basic is not equal to null.
The problem is when I start inserting values in the column it is giving me following error messages:
no viable alternative at input ')' in rule "Pricing bracket_12" in pattern AmountPojo
mismatched input '!=' expecting ')' in rule "Pricing bracket_12" in pattern AmountPojo
Unknown error while parsing. This is a bug. Please contact the Development team
I know it is related to syntax but I am not able to solve it.
[cid:image004.png@01CB404C.DD13B6E0]
Best Regards,
Kripa
________________________________
This Email may contain confidential or privileged information for the intended recipient (s) If you are not the intended recipient, please do not use or disseminate the information, notify the sender and delete it from your system.
______________________________________________________________________
15 years, 6 months
Time unit step-size inside rule files.
by Thorsten
Hello out there,
is it possible to change or extend the existing time unit step-size like
[h,s,ms] used inside the rules? They all seems to have a fixed (logical)
relationship (e.g. 1 s = 1000ms). Unfortunately we have a different time
representation in our application. We can rebuild the time model using
the smallest units as pseudo time reference but this makes the rules
hard to write / read as every user has to know how much
“smallest-time-units” represents a real world second.
Thank you very much
Thorsten
15 years, 6 months
Skills required for using Drools Guvnor
by Swapnil Sawant
Hi,
I had a very basic question. I wanted to know the pre-requisite skills which are required in order to start working on drools guvnor GUI.
When I say work , I mean creating rules/modifying them etc.
Technical knowledge(e.g. java technology) is must in this case?
Thanks & Regards,
Swapnil Sawant
S
________________________________
This Email may contain confidential or privileged information for the intended recipient (s) If you are not the intended recipient, please do not use or disseminate the information, notify the sender and delete it from your system.
______________________________________________________________________
15 years, 6 months
Drools beginners guide
by Singh, Palvinder X.
I am new to Drools and just executed with my first sample program. I
have been trying to find out some beginners guide to help me in start
up, but unable to find any over the net. I would appreciate if anyone
can share some material to go thru.
Just to set up some background, I am not new to IT but yes new to
Business rule engine.
Thanks,
Palvinder Singh
15 years, 6 months