For reusable perspective, I have one Rule with Rule Flow group. I have use same rule flow group multiple times in flow. Now the situation is its should be fire same rule more then one time,but its only fire that rule single time.
I don't understand why its happens.
Can you give me an idea why its happening and whats the solution for same?
A Rule Task in a flow does not "execute" the rules in a rule-flow-group, it merely activates that group in the agenda so IF there are active rules, they will fire.
If between 2 executions of your Rule Task you modify the session in a way that new activations are created, consecutive executions of your task should fire new activations of those rules.
Hope it helps,
Related
I am using before update triggers to enforce some complex business rules.
One trigger has three separate checks, each running its own query.
Is this best implemented using:
a) a single before update trigger containing all three querys
b) three separate before update triggers each containing a single query
If all checks inside triggers are connected with business rules, then one trigger gives better (more redadable) structure of checks, better control over checks order, trigger can be terminated with error in any time without processing all checks, additionaly there is always place to reuse some information obtained during check in next one.
The same functionality can be achieved with multiple triggers, but execution order of those triggers may be not so obvious.
According to Documentation
If multiple triggers of the same kind are defined for the same event,
they will be fired in alphabetical order by name.
It' s worth mentioning, that placing complex business rules inside triggers is not recommended approach.
I have created a simple model in AnyLogic (see screenshot). Now I want to add a condition that selects one of the two resource sets in the service block. As an example the following scenario shall apply: If there are more than 5 parts in the queue, worker 3 and worker 4 should perform the service. If there are <= 5 parts in the queue, the service shall be performed by worker 1 and worker 2. This is only meant to be a simplified example. I am primarily interested in solving this problem using a condition. I have already tried different approaches, but without success. Does anyone have an idea how the Java code for this condition could look like?
First, you don't need the queue since the service block already has a queue... So For this particular example in your resource choice conditions you will do the following:
service.queueSize()>5 ? (worker3.containsUnit(unit) || worker4.containsUnit(unit))
:
(worker1.containsUnit(unit) || worker2.containsUnit(unit))
You can change service.queueSize() with queue.size() if you insist in using a queue. After that you need to be sure to recalculate the conditions when needed, for this particular example i think you only need to recalculate them on exit action of the service block:
self.recalculateResourceChoiceConditions();
One easy approach is to use Seize and Delay (and Release once done) blocks instead of Service. Before Seize, you can place your condition in a SelectOutputOut block. Like this:
I am using drools in my project and assume it has 100 rules. I have two process flow (typically it has start node->rule flow task->end node). One process flow's rule flow task is specified with rule flow-group which is assigned to 50 rules and another process flow's rule flow task is specified with flow flow groups which is assigned to rest of the 50 rules. The don't overlap.
Now I use kiesession and call start process of first process flow, I see that it loads all the 100 rules instead of only 50 and gives me compilation and runtime errors. So please help me in understanding why rules from different rule flow groups are getting executed in a process flow where those rules are no where related its rule flow-group ? I see all its when conditions are getting loaded.
The "unit of work" in Drools is the KieBase and not the rule-flow-group. All the rules in your KieBase will be present in your KieSessions and will be evaluated when required.
Hope it helps,
How to Fire all the rules in drools regardless of which group it belongs to,
I have two Rule-flow groups i.e., "rules1" "rules2", How to fire all the rules without mentioning rule-flow group name? I want to apply all the rules.
This is not possible. If a rule is in a group, the group has to receive the focus - otherwise the rules won't fire.
However, it isn't difficult at all to add a rule that will set the focus to another group.
Also, you can write a very simple loop setting the focus to group after group and to fire all rules.
If you don't need the grouping, remove the rule attribute.
I am very new to Drools, and started with the basics. Here is a setup;
Have a few rule files
Rules in different files belong to different Agenda groups
All the rules operate on the same fact
In my Unit Test, I obtain a particular "Agenda Group", set Focus (session.setFocus)
I insert the fact (Here is where I notice the rules within the other agenda group are getting evaluated even though the focus is not on them)
I fireAllRules()
Shouldn't the rules pertaining to the particular agenda group that is in focus be fired and not all rules from all the groups?
It is a fundamental law in many Rule Based Systems - especially those that follow Rete or similar algorithms - that the evaluation of conditions ("t
when", "left hand side") happens whenever there are changes in Working Memory: inserts, updates or deletes. In contrast, rule firing or the execution of consequences ("then", "right hand side") happens after fireAllRules or fireUntilHalt has been called.
The firing of rules - more precisely: of activations of rules - can be controlled in several ways. Here, it is indeed the focussed agenda group that limits what can be executed by the engine.
Keep this in mind: evaluation is not equal to execution.