Multi Access to Stateful Session
by gboro54
I have a stateful session which is having objects inserted and updated from
multiple threads. The thread managing the session is using the fireUntilHalt
method as below:
@Override
public void run() {
if (logger.isDebugEnabled()) {
logger.debug("Starting session...");
}
threadName = Thread.currentThread().getName();
session.fireUntilHalt();
}
The code being invoked to insert/modify objects is below:
public synchronized void insertOrUpdate(Object fact) {
Preconditions.checkNotNull(fact);
FactHandle factHandle = session.getFactHandle(fact);
if (factHandle == null) {
session.insert(fact);
} else {
session.update(factHandle, fact);
}
}
The problem I am running into is that I have a control fact which keeps an
internal counter(messages coming in are sequenced and need to be processed
in order) and a list of "deregister messages"(messages that are not going
to be inserted for various reasons). The problem I am having is that 75% of
the time it seems something goes wrong with the counter and messages stop
being processed and build up in the session. If i pass every message in and
don't try and deregister any everything works ok. The rules I have for
working with the message deregister is as follows(this is a an example there
are will be other rules added eventually):
rule "Dereg Message"
salience 10000
when
$controller:MessageControl($pos:currentPosition,excludedPositions[$pos]!=null)
then
modify( $controller ){
moveCurrentPositionForward(1)
}
end
rule "Remove Message"
salience -15000
when
$controller:MessageControl($pos:currentPosition,excludedPositions[$pos]==null)
$tsc:Message(rank==$pos)
then
cdiEvent.fire(new CDIEvent($tsc));
retract($tsc);
modify( $controller ){
moveCurrentPositionForward(1)
}
end
The controller class is:
private BigInteger currentPosition = new BigInteger("0");
private Map<BigInteger, BigInteger> excludedPositions = new
ConcurrentHashMap<BigInteger, BigInteger>();
public synchronized void addPositionToExclusionList(BigInteger position) {
excludedPositions.put(position, position);
}
public synchronized BigInteger getCurrentPosition() {
return currentPosition;
}
public synchronized void moveCurrentPositionForward(Integer value) {
currentPosition = currentPosition.add(new BigInteger(value.toString()));
}
public synchronized Map<BigInteger, BigInteger> getExcludedPositions() {
return excludedPositions;
}
public synchronized Collection<BigInteger> getExclusionList() {
return excludedPositions.values();
}
Any thoughts to why this may be occuring? I have been banging my head on
this problem for a couple days. We are using drools 5.3
--
View this message in context: http://drools.46999.n3.nabble.com/Multi-Access-to-Stateful-Session-tp3877...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years
Drools performance
by Hassan
Hi everyone,
In one of my tests, I inserted 1000000 objects into the working memory,
drools engine made a lot of time to execute the program and it throws
Exception : "java.lang.OutOfMemoryError !!
Please if someone could help me to improve drools performance and specially
reduce the drools execution time
thanks
-----
Youssef AZBAKH.
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-performance-tp3870569p3870569.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years
Rules Deployment Issue
by srinivas gullapalli
Hi,
We have a rule deployment directory where we can deploy the
rules.Currently we have written a new rule and deploying to the same to the
deployment directory.
what i observed is when i deploy the rule for the first time and passing
the corresponding data to fire the rule, the rule is not getting fired.If
copy the same file to some other
temporary directory and removing the same from current directory.Finally i
am copying the same file from the temporary directory(to which i copied
before removing the file) to our deployment directory then the rule is
getting fired as expected .
Could you please provide any pointers to resolve the issue.
we are uing 5.1.1 version of drools.
Regards,
Srinivas
14 years
Inconsistent rule firing on a boolean field.
by Creighton Kirkendall
I have two rules below; the first fails to fire for all values of photo
(photo is a boolean field). The second rule give the correct behavior when
photo is true and false. I am new to drools and could be wrong but this
feels like a bug. Can anyone give me a reason for this behavior.
*BAD RULE:*
# rule values at C137, header at C132
rule "Photochromatic_137"
when
RxOrderType(product[0].lens.material.photo == true,
product[0].lens.design.lensType=="SV")
then
addResult("e1",results);
System.out.println("Single Vision-Photo");
end
*GOOD RULE (notice the - true &&):*
# rule values at C137, header at C132
rule "Photochromatic_137"
when
RxOrderType(true && product[0].lens.material.photo == true,
product[0].lens.design.lensType=="SV")
then
addResult("e1",results);
System.out.println("Single Vision-Photo");
end
Creighton Kirkendall
14 years
parametrized rules
by Tim van Heugten
Hi all,
I'm new to Drools, and wonder how I can most cleanly write down rules for
the following.
(For the sake of example) Say I have an object that needs to be processed
season-dependent. I basically need a rule like:
rule
when
Date( month == X, day >= Y, day <= Z)
// Some date containing object
then
System.out.println("Season is "+R)
// Store season in associated object
end
And fill in X, Y, Z and R with:
X Y Z R
1 1 31 Winter
2 1 29 Winter
3 1 21 Winter
3 22 31 Spring
4 1 30 Spring
5 1 31 Spring
6 1 21 Spring
6 22 30 Summer
7 1 31 Summer
...
Should I expand all this rules by hand, and define 16 rules in my rule
file? Or can I parametrize the rules and have this done automagically?
Thanks a lot,
Tim van Heugten
14 years
drl problem
by arup
Hi,
i'm having some problems(more like i'm just getting confused) while creating
a rule for my project.
I have 2 classes say Phone() and PhoneTC() like below:
Phone()
{
String number;
}
PhoneTC()
{
String tc;
}
also PhoneTC() is inside the Phone() class. like:
Phone()--String number
PhoneTC()--------String tc
now i need to create a rule like this....
when phone numbers are same and the tc values are different for that number
then do something.
will this work??
when
ph1: Phone(number1 : number)
phtc1: PhoneTC(tc1 : tc)
Phone(number == number1) and PhoneTC(tc != tc1)
then
........
can u suggest better rule for the requirement??.... thanks in advance... :)
:) :)
--
View this message in context: http://drools.46999.n3.nabble.com/drl-problem-tp3877814p3877814.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years
ontologies
by Olfa h
hello,
how I can create ontologies with Drools ?
thx
14 years
Rule Compilation error when using custom classloader
by M. Kramer
Hello everybody,
I would appreciate some help with the compilation of a rule that involves
dynamically generated POJOs (minimal example at the end of the mail).
When I add the packages of the generated POJOs manually to the imported
packages of my Eclipse plug-in that executes the knowledge session
everything works fine.
When I use my custom classloader (that successfully loads all involved
classes, I checked this thoroughly) I get the following errors:
Unable to generate rule invoker. lts cannot be resolved to a type
Rule Compilation error lts cannot be resolved to a type
Do I need to change my rules just because the involved classes are now
loaded using my custom classloader?
Thanks for your help!
M. Kramer
This is the rule that only works if the package "lts" is listed under
"Import-Package" in the MANIFEST.MF:
import java.lang.String;
import java.util.ArrayList;
import java.util.HashMap;
import org.eclipse.emf.ecore.EObject;
global java.lang.String output;
global java.util.List list;
global java.util.List pclist;
rule "Aspect"
when
$s0Decl: lts.State(name == "a")
$s0: lts.State(this == $s0Decl)
then
java.util.List param = new ArrayList<HashMap<String,EObject>>();
java.util.List ids = new ArrayList<String>();
param.add($s0);
ids.add("0");
list.add(param);
pclist.add(ids);
end
This is the code that I am using to execute the rule:
void executeKnowledgeSession(String droolsRules, URLClassLoader
urlClassLoader, Iterable<EObject> iterable) {
KnowledgeBuilderConfiguration kBuilderConfiguration =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,
urlClassLoader);
KnowledgeBuilder knowledgeBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(kBuilderConfiguration);
Resource droolsRulesResource =
ResourceFactory.newByteArrayResource(droolsRules.getBytes());
knowledgeBuilder.add(droolsRulesResource, ResourceType.DRL);
if (knowledgeBuilder.hasErrors()) {
...
}
KnowledgeBaseConfiguration kBaseConfiguration =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null, urlClassLoader);
KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase(kBaseConfiguration);
knowledgeBase.getKnowledgePackages().clear();
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
StatelessKnowledgeSession knowledgeSession =
knowledgeBase.newStatelessKnowledgeSession();
knowledgeSession.setGlobal(...);
// execute the knowledge session
knowledgeSession.execute(iterable);
}
These are the exact errors that I get:
Unable to generate rule invoker. lts cannot be resolved to a type
lts cannot be resolved to a type
Rule Compilation error lts cannot be resolved to a type
Unable to generate rule invoker. : [Rule name='Aspect']
defaultpkg/Rule_Aspect_0DefaultConsequenceInvoker.java (22:883) : lts
cannot be resolved to a type
defaultpkg/Rule_Aspect_0DefaultConsequenceInvoker.java (22:901) : lts
cannot be resolved to a type
Rule Compilation error : [Rule name='Aspect']
defaultpkg/Rule_Aspect_0.java (6:322) : lts cannot be resolved to a type
--
View this message in context: http://drools.46999.n3.nabble.com/Rule-Compilation-error-when-using-custo...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years
drl execution problem
by arup
i have one drl like below:
rule "FirstNameDifference"
no-loop true
lock-on-active true
when
person1: Person( $firstName1: firstName )
person2: Person( firstName != $firstName1 )
then
dataDifferenceVO.getDataDiffArray().add("Person/FirstName");
end
i'm passing a list of objects in which i have 2 person type objects. my aim
is to check if the firstnames are same or different. if its different i need
to add one String to the DataDiffArray that is declared inside
DataDifferenceVO class.
but as i pass 2 person objects in the WM the rule is getting executed twice.
i.e, the string "Person/FirstName" is getting added twice in the array list.
why is this happening?... the rule should compare 2 firstnames and return
one String...is not that?... what step should i take to achive what i
want....
Thanks a lot i advance... :) :) :)
--
View this message in context: http://drools.46999.n3.nabble.com/drl-execution-problem-tp3866929p3866929...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years