Drools & JBPM Persistence
by Alberto R. Galdo
Hi,
I'm opening this thread in the aim of generating a debate about the
approach to session persistence in Drools and JBPM for BPMN processes which
by definition are able to generate asynchronous human tasks.
IMHO the current approach needs to be refactored in favor of joining the
management of the different Drools and JBPM entities in an unique manager.
The current implementation offers two managers one in Drools, one in
JBPM. Each of this managers are wrappers of a shared JPA EntityManager
context and manage their own entities.
When the integration of JBPM into Drools was done ( leaving behind
drools flow ), the approach seemed to be to make the entities in JBPM (
workitems, processinstance and so on ) look like the entities in Drools. As
a result, the implementation of those entities in JBPM now implement the
interfaces of the same entities in Drools. That looked like a good
approach, but the experience, at least mine, seems to reveal it as not that
good.
In my opinion, the first problem with that approach is that Drools, the
reteoo algorithm, runs in a single-threaded environment. Drools persistence
was designed having this in mind, so for the code in Drools, there's no
doubt that when in a persistent enviroment, the transaction, if any, will
be bound to the same thread as the one in which the reteoo algorithm is
executed. That leads to situations where whenever a class in JBPM calls
drools in a JBPM's thread ( the mina handler thread, a NIO one for instance
), Drools thinks that is being executed in it's own thread ( where things
are expected, as the JTA transaction bound for example ) and clearly, in
some situations it is not the case. Then Drools expects to find certain
resources and certain environment which are not always there. Leading to
failure.
As Drools now is a dependency for JBPM through the Knowledge-API, I
think that the management of the persistence for Drools and JBPM should be
merged in one that makes no assumptions and manages the needs for
persistence in a coherent way for both products.
What do you think?
"There can be only one" ->
http://en.wikipedia.org/wiki/Highlander_%28film%29
Alberto R. Galdo
argaldo(a)gmail.com
12 years, 5 months
Does a StatefulKnowledgeSession still change when it is being serialized?
by chrisLi
Hi All,
The business requirement needs me to serialize a statefule session into
a file. However, the session
object may be huge, which may take 500M memory space. So it will take
several seconds to serialize it.
During the serialization process, the session may still in use, such as
asserting an object, executing
fireAllRules command, which will cause the session to change.
Is there any way to pause or halt the session? Otherwise, Is there any
good practice to serialize a big
session object which may still be in change?
Thank you very much. Any response will be appreciated.
--
View this message in context: http://drools.46999.n3.nabble.com/Does-a-StatefulKnowledgeSession-still-c...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
Accumulator being executed depending on the number of events
by ekzl@yahoo.com
Hi,
I'm experimenting with Drools and have troubles understanding the way
accumulators work. Before i go and look at the source code i was wondering
if the way the accumulators work is designed as described below or of it has
something to do with my rules configuration.
I'm using drools distibution 5.4.0. So this is my test case:
I have 3 similar events and 1 rule containing an accumulator. So when firing
the alerts obviously as the events are similar the same rule is fired. So
accorrding to me when the rule is fired drools creates a new accumulator and
passed data for all events but at the same time the first accumulator still
exists and receives only the datza for the second event. The 3rd event will
trigger accumulate for context1 and context2 and then create a new
accumulator with all the 3 events. This results in actually having 3
accumulators with exactly the same data.
I have created a dummy accumulator to test this:
Here is the DRL
rule "update profile"
salience 1000 // Make sure this rule is always executed by giving it a
very high salience
no-loop true
when
$event: TestEvent()
$profile: Profile( key == $event.key)
$total : Number() from accumulate( TestEvent( $p : value, key ==
$event.key), test( $p ) )
then
System.out.println("Total:" + $total);
end
Here is the output
Event 1
Context created:137
Init called for context:137
accumulate called for context:137 object:80
Total called for context:137
Total:80
Event 2
Context created:858
Init called for context:858
accumulate called for context:858 object:80
Total called for context:858
accumulate called for context:137 object:41
accumulate called for context:858 object:41
Total called for context:858
Total called for context:137
Total:121
Total:121
Event 3
Context created:724
Init called for context:724
accumulate called for context:724 object:80
accumulate called for context:724 object:41
Total called for context:724
accumulate called for context:137 object:53
accumulate called for context:858 object:53
accumulate called for context:724 object:53
Total called for context:724
Total called for context:858
Total called for context:137
Total:174
Total:174
Total:174
How can i remove the accumulator after the rule is finished?
Regards,
e
--
View this message in context: http://drools.46999.n3.nabble.com/Accumulator-being-executed-depending-on...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
Setting unused globals on a session
by gqmulligan
I save many different knowledge packages for different accounts to a
database. Most accounts use a particular service to pull data from the
database but not all of them. Because of this I wanted to set this service
as a global on the session.
However, because not all accounts use the service I get an exception when I
try to set it on the session for an account that does not use the service
anywhere in its rules. Does an exception really need to be thrown in this
case?
Also, do I have any options to work around this exception without having
some sort of "master" rule that is automatically put into all accounts and
declares all globals? The service is being pulled from a bean so I would
like to stay away from having to find it by name and keep to injecting any
global services if possible.
Thanks.
--
View this message in context: http://drools.46999.n3.nabble.com/Setting-unused-globals-on-a-session-tp4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
how to handle the overwrinting values in drools planner
by Ricardo
Hi,
First Thanks for helping me with your valuable time,
I have 2 boxes, lets say each size of 5x5 and I have 3 items two size 4x4
and one item size is 3x3. planner initially planner assigning as follows...
item1 --> box1
item2 --> box2
item3 --> box1
When I use 2 item, result as follows...
item1 --> box1
item2 --> box2
item3 --> box1
When I increase one more box....
item1 --> box1
item2 --> box2
item3 --> box3
in the above 3 scenarios...first one (2 boxes and 3 items), is the
overwriting the item1 with iem3 into box1.
I am beginner for drools-planner.....any tips or help will be most
appreciated....
-----
with kind regards,
--
View this message in context: http://drools.46999.n3.nabble.com/how-to-handle-the-overwrinting-values-i...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
planning entity value range type
by Ricardo
Hi,
*/"A planning entity should not use other planning entities to determinate
its value range. That would only try to make it solve the planning problem
itself and interfere with the optimization algorithms."/*
reference to the above from the drools-planner user guide, I can use the
other planning entity property but not to use other planning entity to
determine its value range. Am I correct?
thanks,
-----
with kind regards,
--
View this message in context: http://drools.46999.n3.nabble.com/planning-entity-value-range-type-tp4018...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
traits - don more than 3 pojos, got IllegalArgumentException
by Michal Bali
Hi all,
I came across this issue when trying out 'traits' with POJOs (not declared
types). An IllegalArgumentException is being thrown when I apply the third
'don'. Here is how to reproduce:
as the POJO I am using the Message class that comes with the project
created by the Eclipse plugin.
now the rule file:
declare Message
@Traitable
end
declare NiceMessage
@format(trait)
end
rule load
when
then
Message message = new Message();
message.setMessage("Hello World");
insert(message);
don(message, NiceMessage.class);
Message unreadMessage = new Message();
unreadMessage.setMessage("unread");
insert(unreadMessage);
don(unreadMessage, NiceMessage.class);
Message oldMessage = new Message();
oldMessage.setMessage("old");
insert(oldMessage);
System.out.println("don " + oldMessage);
don(oldMessage, NiceMessage.class); //*<--- exception happens here*
System.out.println("wont reach this point");
end
When I run this and rule 'load' fires the third 'don' will throw the
following exception:
Exception executing consequence for rule "load" in com.mycompany.app:
java.lang.IllegalArgumentException: argument type mismatch
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1101)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:709)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:673)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:221)
at com.mycompany.app.DroolsTest.main(DroolsTest.java:44)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at
org.drools.factmodel.traits.TraitFactory.getProxy(TraitFactory.java:92)
at
org.drools.base.DefaultKnowledgeHelper.don(DefaultKnowledgeHelper.java:502)
at
org.drools.base.DefaultKnowledgeHelper.don(DefaultKnowledgeHelper.java:522)
at
com.mycompany.app.Rule_load_86ecf966a4c14d8486844cfae2e1e0d8.defaultConsequence(Rule_load_86ecf966a4c14d8486844cfae2e1e0d8.java:21)
at
com.mycompany.app.Rule_load_86ecf966a4c14d8486844cfae2e1e0d8DefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
at
com.mycompany.app.Rule_load_86ecf966a4c14d8486844cfae2e1e0d8DefaultConsequenceInvoker.evaluate(Unknown
Source)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)
... 6 more
Am I doing something wrong or is this a bug. I am running with 5.4.0.Beta2.
BTW traits are a great piece of functionality. Thank you!
Best regards,
Michal
12 years, 5 months
planner score calculation error...
by Ricardo
Hi when i use the following drl file for score calculation ....It assign a
bigger table into the smaller room. help will be appreciated....
console output is as follows..
*Solved Organizer with 2 rooms and 3 tables:
Table 1 -> Room 1
Table 2 -> Room 2
Table 3 -> Room 2*
test data:
Room room1 = new Room(10, 10);
room1.setId((long) 1);
Room room2 = new Room(10, 10);
room2.setId((long) 2);
----
Table table1 = new Table(10, 10);
table1.setId((long) 1);
Table table2 = new Table(9, 9);
table2.setId((long) 2);
Table table3 = new Table(9, 9);
table3.setId((long) 3);
drl file for score calculation...
//created on: Jun 18, 2012
package org.drools.planner.organizer;
dialect "java"
//list any import classes here.
import
org.drools.planner.core.score.buildin.hardandsoft.HardAndSoftScoreHolder;
import org.drools.planner.core.score.constraint.IntConstraintOccurrence;
import org.drools.planner.core.score.constraint.ConstraintType;
import org.drools.planner.organizer.domain.Room;
import org.drools.planner.organizer.domain.Table;
//declare any global variables here
global HardAndSoftScoreHolder scoreHolder;
//
############################################################################
// Hard constraints
//
############################################################################
rule "requiredLengthTotal"
when
$room : Room($length : length)
$requiredSpaceTotal : Number(intValue > $length) from accumulate(
Table(
room == $room,
$tablelength : length),
sum($tablelength)
)
then
insertLogical(new IntConstraintOccurrence("requiredLengthTotal",
ConstraintType.NEGATIVE_HARD,
$requiredSpaceTotal.intValue() - $length,
$room));
end
rule "requiredWidthTotal"
when
$room : Room($width : width)
$requiredSpaceTotal : Number(intValue > $width) from accumulate(
Table(
room == $room,
$tablewidth : width),
sum($tablewidth)
)
then
insertLogical(new IntConstraintOccurrence("requiredWidthTotal",
ConstraintType.NEGATIVE_HARD,
$requiredSpaceTotal.intValue() - $width,
$room));
end
//
############################################################################
// Soft constraints
//
############################################################################
rule "roomLengthCapacity"
when
$room : Room($length : length)
$table : Table(room == $room, length > $length, $tablelength :
length)
then
insertLogical(new IntConstraintOccurrence("roomLengthCapacity",
ConstraintType.NEGATIVE_SOFT,
($tablelength - $length),
$room, $table));
end
rule "roomWidthCapacity"
when
$room : Room($width : width)
$table : Table(room == $room, width > $width, $tablewidth : width)
then
insertLogical(new IntConstraintOccurrence("roomWidthCapacity",
ConstraintType.NEGATIVE_SOFT,
($tablewidth - $width),
$room, $table));
end
//
############################################################################
// Calculate score
//
############################################################################
// Accumulate hard constraints
rule "hardConstraintsBroken"
salience -1 // Do the other rules first (optional, for performance)
when
$hardTotal : Number() from accumulate(
IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_HARD, $weight : weight),
sum($weight)
)
then
scoreHolder.setHardConstraintsBroken($hardTotal.intValue());
end
// Accumulate soft constraints
rule "softConstraintsBroken"
salience -1 // Do the other rules first (optional, for performance)
when
$softTotal : Number() from accumulate(
IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_SOFT, $weight : weight),
sum($weight)
)
then
scoreHolder.setSoftConstraintsBroken($softTotal.intValue());
end
-----
with kind regards,
--
View this message in context: http://drools.46999.n3.nabble.com/planner-score-calculation-error-tp40181...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
Does Guvnor Support Traits?
by BenjaminWolfe
I'm pretty new to developer forums. If my question is best asked in a
different venue, feel free to point me there. And if it's vague (see the
full version below), please ask clarifying questions. Thank you!
I was just reading in the 5.4 docs about traits, donning the isA keyword...
pretty exciting stuff. It allows me a lot of flexibility as a rule-writer.
But my company's upcoming implementation of Drools is going to feature
Guvnor pretty prominently. (We're in the process of rolling it out.) Does
Guvnor support traits?
I should mention that I'm an analyst, and our developers are new to Drools
and Guvnor as well. Traits are coming up in one of our early projects, as
we consider whether to squish two similar things into the same fact type (so
that we can easily use the same rules on both) or separate them out into
two.
--
View this message in context: http://drools.46999.n3.nabble.com/Does-Guvnor-Support-Traits-tp4018176.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
drools planner ConstraintOccurrence
by Ricardo
Hi,
I am learning drools planner, please explain to me about the
ConstraintOccurrence (Int, Double,Long and Umweighted) object used in the
then part of the drools planner drl file. My doubt is when to use this each
type of this class and how it makes changes in the score calculations.
note: Already search the mailing list, src code and read the user guide but
no details available
best regards,
-----
with kind regards,
--
View this message in context: http://drools.46999.n3.nabble.com/drools-planner-ConstraintOccurrence-tp4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months