NullPointerException for Integer null
by techy
Hello,
For following rule, NullPointerException is thrown for null id in 4.x. is
this expected? Please clarify.
Foo{
Integer id;
}
Rule "null check"
foo : Foo(id==null)
then
end
stack trace:
java.lang.NullPointerException
at
org.drools.base.extractors.BaseObjectClassFieldExtractor.getIntValue(BaseObjectClassFieldExtractor.java:95)
at
org.drools.base.ClassFieldExtractor.getIntValue(ClassFieldExtractor.java:197)
at
org.drools.base.evaluators.IntegerFactory$IntegerLessEvaluator.evaluate(IntegerFactory.java:241)
at
org.drools.rule.VariableRestriction.isAllowed(VariableRestriction.java:73)
at org.drools.rule.VariableConstraint.isAllowed(VariableConstraint.java:67)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:137)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:318)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:162)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:911)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:883)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:684)
at
org.drools.reteoo.ReteooStatelessSession.execute(ReteooStatelessSession.java:160)
--
View this message in context: http://www.nabble.com/NullPointerException-for-Integer-null-tp23286041p23...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months
need some advice in defining rules
by Brody bach
Hi all,
I'm having difficulty in defining a rule for the following problem:
We need to check if within a week there are more than 5 objects of type
Reminder inserted into Memory.
(one day corresponds to one object)
The number of the inserted objects depends on the usage of the application.
That means there could be nothing, 1, 2, or any number of the objects.
Before, within a session, I inserted a list containg data from within one
week (7 days).
Than I can check using the rule:
when:
$list : list(size > 5)
Reminder() from $list
no String(trim == "limit reached");
then
System.out.println("This rule fires");
insert new String("limit reached");
Now I need to insert a list containing data from a whole month, but I still
need to check whether within one week there are more than 5 reminders exist.
so, the constraint list> 5 can't be used anymore for a single list. I tried
to break the whole list in several smaller list, where each list represents
one week.
Now the problem is, if the rule fires for a certain week, than it won't work
for the following weeks anymore.
My idea is then to insert an integer containing specific number to the
current list, i.e. the calendar week (i.e insert new Integer(52)) and then
to prove this in LHS; but the problem is now how to prove the week number in
LHS? as I remeber, a function can only be called within an eval statement
and in this case actually I should only prove the existence of an Integer
Hope my explanation is quite understandable and looking forward for any
hints
Regards
--
View this message in context: http://www.nabble.com/need-some-advice-in-defining-rules-tp23259683p23259...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months
problem escaping quote in eval
by samlotti
Hello,
I'm trying to construct a rule in drool V4 that contains and eval and a
literal string that may contain quotes. I've tried escaping the quote but
get the error below. The \" works outside an eval.
rule "evalList2"
when
Var( eval( "tt".equals("t\"t")))
then
System.out.println( "evalList2" );
end
Error:
java.lang.NullPointerException:
at
org.drools.rule.PredicateConstraint.createContextEntry(PredicateConstraint.java:201)
at org.drools.reteoo.AlphaNode.createMemory(AlphaNode.java:230)
...
It looks like a change was made to V3 to fix this but doesnt appear to work
in V4, does anyone know how to construct this type of rule?
Thanks
Sam
--
View this message in context: http://www.nabble.com/problem-escaping-quote-in-eval-tp19186015p19186015....
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months
Drools 4.0.7 - Rules not fired
by Benoit VILLAUMIE
Hello,
I am using Drools engine 4.0.7 and Eclipse 3.3 drools plugin.
I have a very basic/dumb problem but I do not understand where my error is :
I have 2 rules
---------------------------------
package poc
import poc.FlashFact;
*rule "HP one"*
when
FlashFact( homepage == "one");
then
System.out.println("*** HP one");
end
*rule "HP commons"*
when
FlashFact();
then
System.out.println("*** HP commons ");
end
----------------------------------
I insert a FlashFact which homepage is set with "one" value.
In my understanding, both rules "HP one" and "HP commons" should be
fired. Instead, only "HP commons" is launched. I have compared with the
Drools State example (which works fine), but I do not notice nothing.
Thanks for your help.
The code of the FlashFact class
---------------------------------
package poc;
public class FlashFact {
public FlashFact() {
this(null);
}
public FlashFact(String homepage) {
this.setHomepage(homepage);
}
private String homepage;
/**
* @return the homepage
*/
public final String getHomepage() {
return this.homepage;
}
/**
* @param homepage the homepage to set
*/
public final void setHomepage(String homepage) {
this.homepage = homepage;
}
}
---------------------------------
The code of the launcher
---------------------------------
package poc;
import java.io.InputStreamReader;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.audit.WorkingMemoryFileLogger;
import org.drools.compiler.PackageBuilder;
public class FlashUndeployedRulesMain {
public static void main(String[] args) throws Exception {
StatefulSession session = null;
WorkingMemoryFileLogger logger = null;
try {
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(new InputStreamReader(
FlashUndeployedRulesMain.class.getClassLoader()
.getResourceAsStream(RULE)));
final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(builder.getPackage());
session = ruleBase.newStatefulSession();
logger = new WorkingMemoryFileLogger(
session);
logger.setFileName("log/flash");
// inserting facts
FlashFact HPFrance = new FlashFact("one");
session.insert(HPFrance);
session.fireAllRules();
} finally {
if(session != null) {session.dispose();}
if(logger != null) {logger.writeToDisk();}
}
}
private static final String RULE = "poc/Flash.drl";
---------------------------------
15 years, 7 months
using matches in a collection
by ygaurav
Hi All
i am new to drools and I am hoping that some body can help me out here.
I data in string array and I would like to check if one of the entry starts
with the string I have. How can check it ?
Code is shown below
@java
class ABC {
String[] array = new String[]{"abcdef","ghijkl","mnopqrst"}
}
@drools
rule "check something"
when
$abc : ( ABC.array contains a single entry which start with "abc" )
Is there a way I can do it ? If it is not possible what is way I can achive
it
Thanks
--
View this message in context: http://www.nabble.com/using-matches-in-a-collection-tp18115893p18115893.html
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months
KnowledgeBase threadsafe?
by Dan Seaver
I'm using various KnowledgeBase objects in a J2EE environment, using JBoss
4.2 as the application server. Currently, I keep a list of KnowledgeBase
objects in a stateless session bean. The thought being that to keep the
application scalable, we don't want contention around rule sessions.
However, I just heard that KnowledgeBase is thread safe. This would mean
that I could instantiate a KnowledgeBase once and have multiple
StatelessKnowledgeSessions using it concurrently.
Can anyone verify that KnowledgeBase is thread safe for me?
Would this technique potentially cause contention on a busy system?
Dan
--
View this message in context: http://www.nabble.com/KnowledgeBase-threadsafe--tp23324327p23324327.html
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months
FW: RuleFlow and Internal Model
by Bhamidi, Krishna
I was inserting the wrong object in to the session.
________________________________
From: Bhamidi, Krishna
Sent: Thursday, April 30, 2009 3:21 PM
To: 'Rules Users List'
Subject: RuleFlow and Internal Model
Hi,
We are attempting to use a rule flow in Guvnor 5.0.0 CR1. When we use the internal data model, we get an error that essentially reads "
java.lang.IllegalArgumentException: OR split could not find at least one valid outgoing connection for split"
When we use an external data model (model in java) instead of the internal data model, the ruleflow runs perfectly. Any similar experiences? What is the way out? Would appreciate input.
Krishna
15 years, 7 months
Use of KnowledgeAgent in JEE Container
by Dave Macpherson
I was wondering if it's safe to use the KnowledgeAgent inside of a JEE
container. I'm assuming that the KnowledgeAgent implementation spawns a
thread to poll for changed resources (to reinitialize a KnowledgeBase, for
instance, when updated DRL files are detected). Normally, use of unmanaged
threads is considered a no-no inside of a JEE container. Has anyone
encountered any problems with this?
Dave
15 years, 7 months
Using immutable Globals in the new Command API
by Dan Seaver
In the M5 release, I could use a Boolean global as an Out type parameter and
changes I made to the global would be maintained in the results. In CR1, I
use the CommandFactory to add the global with out set to true, and I get
back the initial value of the Boolean, not the updated value.
Here's a code snippet:
List<Command< ? >> commands = new ArrayList<Command< ? >>();
commands.add(CommandFactory.newInsertElements(sessionFacts));
commands.add(CommandFactory.newSetGlobal("result", null, true));
Command< ? > execution = CommandFactory.newBatchExecution(commands);
BatchExecutionResults results = session.execute(execution);
Here's the rule that fires:
rule 'Initialize'
dialect 'mvel'
when
then
drools.getWorkingMemory().setGlobal("result", new Boolean(false));
logger.debug("Initialized result to false");
end
In M5, result would have a value of false.
In CR1, result has a vaule of null.
Am I doing something wrong with the new command structure?
Is this behavior expected, or is it supposed to work like it did in M5?
Thanks for any assistance.
Dan
--
View this message in context: http://www.nabble.com/Using-immutable-Globals-in-the-new-Command-API-tp23...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months