Why isn't my rule firing??
by dunnlow
First, my intent:
1) insert a pojo into a stateful session
2) based upon that pojo's attributes, create and insert a new fact
(different type)
3) retract the initial pojo, but keep the newly created fact in memory for
some period of time
After some helpful insight from the forum, I thought I could knock this out.
However, I'm stuck and I've boiled down to what I imagine is a
misunderstanding that I have. I have the code and rules below.
With each fact that I insert, I expected
1) to see the number of facts grow (the list of facts printed line 16 does
grow with each call). This works
2) to see the NotificationEvent added only once to working memory (the
facts printed shows only one NotificationEvent and then a new MyBean for
each one I insert). So, I think this works also.
3) BUT, each time I call fireAllRules(), I expect the "foundNE" rule to be
triggered and to see "Found A notification event" printed. However, this is
only printed once - after my first insert. Also, I see that 0 rules get
fired (line 13) after the first MyBean insert.
SO, if I see a NotificationEvent in the list of facts in line 17, why isn't
my foundNE rule printing out the message each time I insert a new MyBean and
call fireallrules??
FYI, my future plan is to have a rule with low salience that retracts the
MyBeans just inserted and have my foundNE rule retract any
NotificationEvents that are at least 10 mins old. (so that the
NotificationEvents will grow but not MyBeans) .
Here is my test code (please excuse typos - there are none in my code):
Thanks very much for any insight.
-J
===test.java ===============
1 KnowledgeBase kbase = readKnowledgeBaseFromFile();
2 StatefulKnowledegeSession ksession = kbase.newStatefulKnowledgeSession():
3 KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession,"testlog");
4 for (int x=0;x<10;x++){
5 myBean mb = new MyBean();
6 mb.setName("me");
7 mb.setHeadline("my_head");
8 mb.setTag("tagline");
9
10 List<Command> cmds = new ArrayList<Command>();
11 FactHandle fh = (FactHandle) ksession.insert(seb);
12 int rf = ksession.fireAllRules();
13 System.out.println(rf+"rules fired");
14
15 Collection<FactHandle> c = ksession.getFactHandles();
16 for (FactHandle f:c) {
17 System.out.println(" now: "+f.toString());
18 }
19
20 Thread.sleep(5000);
21 }
=== test.drl ================
import com.me.MyBean
import java.util.Calendar
declare NotificationEvent
name: String
headline: String
tagline: String
dts: Long
end
rule "foundNE"
dialect "mvel"
when
$ne : NotificationEvent()
then
System.out.println("Found a Notification Event");
end
rule "NotTemplate_1"
dialect "mvel"
when
$myb : MyBean(name matches "me", headline matches "my_head")
not ($ne : NotificationEvent(name matches $myb.name,
headline=$myb.headline)
then
NotificationEvent fact0 = new NotificationEvent();
fact0.setName($myb.name);
fact0.setHeadline($myb.headline);
insert(fact0);
System.out.println("Adding a notification event");
end
--
View this message in context: http://drools.46999.n3.nabble.com/Why-isn-t-my-rule-firing-tp3670261p3670...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 3 months
unable to load jar file
by kavita
Hi,
I am trying to upload a POJO jar file into drools guvnor. But it is throwing
me an error saying "unable to load file".
This is the file that am trying to upload
http://drools.46999.n3.nabble.com/file/n3669841/QcResult.jar QcResult.jar
I am running drools guvnor 5.3 on tomcat server. When i looked into the logs
of tomcat, the following is the stacktrace..
SEVERE: Servlet.service() for servlet AssetFileServlet threw exception
java.lang.ClassNotFoundException: groovy.lang.GroovyObject
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at
org.drools.rule.MapBackedClassLoader.loadClass(MapBackedClassLoader.java:109)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at
org.drools.rule.MapBackedClassLoader.fastFindClass(MapBackedClassLoader.java:86)
at
org.drools.rule.MapBackedClassLoader.loadClass(MapBackedClassLoader.java:104)
at java.lang.ClassLoader.loadClass(Unknown Source)
at
org.drools.guvnor.server.contenthandler.ModelContentHandler.isClassVisible(ModelContentHandler.java:183)
at
org.drools.guvnor.server.contenthandler.ModelContentHandler.getImportsFromJar(ModelContentHandler.java:148)
at
org.drools.guvnor.server.contenthandler.ModelContentHandler.onAttachmentAdded(ModelContentHandler.java:66)
at
org.drools.guvnor.server.files.FileManagerUtils.attachFileToAsset(FileManagerUtils.java:115)
at
org.drools.guvnor.server.files.FileManagerUtils.attachFile(FileManagerUtils.java:87)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
at
org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at
org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:163)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at
org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
at
org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
at
org.drools.guvnor.server.files.FileManagerUtils_$$_javassist_seam_10.attachFile(FileManagerUtils_$$_javassist_seam_10.java)
at
org.drools.guvnor.server.files.AssetFileServlet.processAttachFileToAsset(AssetFileServlet.java:97)
at
org.drools.guvnor.server.files.AssetFileServlet.doPost(AssetFileServlet.java:49)
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.jboss.seam.web.ContextFilter$1.process(ContextFilter.java:42)
at
org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:65)
at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:37)
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.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Please help.
Thanks,
Kavitha.
--
View this message in context: http://drools.46999.n3.nabble.com/unable-to-load-jar-file-tp3669841p36698...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 3 months
Get fact type returning null
by kavita
Hi,
I am a beginner to drools and am trying to integrate drools rules to java .
Am doing this using changeset.
Here's my piece of code:
package edu.arizona;
import org.drools.KnowledgeBase;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentFactory;
import org.drools.definition.type.FactType;
import org.drools.io.Resource;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
public class TestRest {
public static void main(String[] args) throws
InstantiationException,IllegalAccessException {
StatefulKnowledgeSession ksession = null;
KnowledgeBase kbase = readKnowledgeBase();
FactType factType = kbase.getFactType("edu.arizona", "result");
System.out.println (factType);
Object obj = factType.newInstance();
factType.set(obj,"rawConcentration",150);
ksession = kbase.newStatefulKnowledgeSession();
ksession.insert(obj);
ksession.fireAllRules();
System.out.println(factType.get(obj,"rescode"));
}
private static KnowledgeBase readKnowledgeBase() {
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("LabAgent");
Resource changeset = ResourceFactory.newClassPathResource(
"edu.arizona/lab-changeset.xml");
kagent.applyChangeSet(changeset);
KnowledgeBase kbase = kagent.getKnowledgeBase();
kagent.dispose();
return kbase;
}
}
When i run the application the System.out.println (factType) is printing as
null. and getting
Exception in thread "main" java.lang.NullPointerException
at edu.arizona.TestRest.main(TestRest.java:20)
What am i missing? Please help.
Thanks,
Kavitha.
--
View this message in context: http://drools.46999.n3.nabble.com/Get-fact-type-returning-null-tp3667266p...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 3 months
cannot import function
by xdyl
HI,all:
i want import an function in another drools file. but when i use "import
function " in drools 5.3.0.Final
compile give me a error message:
Rule Compilation error : [Rule name='start']
room/Rule_start.java (2:279) : Only a type can be imported.
util.convertString2Set resolves to a package
room/Rule_start.java (9:629) : The method convertString2Set(String) is
undefined for the type Rule_start
and i search in google not find any help .
--
View this message in context: http://drools.46999.n3.nabble.com/cannot-import-function-tp3668460p366846...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 3 months
APIs to create rules
by bobbi_80
public static class CpuTracker{
private String machinename;
private String averageCPU;
}
Consider the following rule :
rule first_rule
@ID(“1”)
when
averageCPU > 80
then
syso("do something");
end
I have the following requirements to let the user change the rules.
1) Create an app that will accept user input for rule Name, LHS , RHS of
rule.
2) Add/remove rules from the knowledge base at runtime.
3) Display all compiled rules .
For task(1) I am unable to figure out the exact APIs to programmatically
create rules . Have gone through number of posts in user forums and docs but
got nothing conclusive.
For Task(3) I could get rule name and any other meta data information but
not LHS,RHS info. Does that mean that rules will have to be persisted and
there are no APIs to fetch LHS/RHS at run time?
What are my options here?
Many Thanks,
Dumb programmer!
--
View this message in context: http://drools.46999.n3.nabble.com/APIs-to-create-rules-tp3662689p3662689....
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 3 months
drools5.2 integrate with JMS
by DroolersEye
Hi, I would like to integrate JMS with drools 5.2. I have a confusion over
selecting right approach.
I noticed from the mailing list drools pipeline is depricated so I assume
that not recomended now. So ignored it than look for another option but not
using spring? when i check the user forum I not getting any right direction
insted more confusion selecting rigt tool. Can some one help me to provide
me some info about integration JMS with drools without using spring?i am
using drools5.2
thanks lot,
-----
with kind regards,
--
View this message in context: http://drools.46999.n3.nabble.com/drools5-2-integrate-with-JMS-tp3546100p...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 3 months