cannot retrieve timerId from timerInstance - Bug?
by tom238@gmx.at
Hi there!
I'm using Drools 5.1.SNAPSHOT.
I want to disable some timer nodes in my ruleflow, so that they will not trigger anymore. therefore I tried the following code:
Collection<TimerInstance> tcoll = drools.getWorkingMemory().getTimerManager().getTimers();
for (TimerInstance ti : tcoll)
{
drools.getWorkingMemory().getTimerManager().cancelTimer(ti.getTimerId());
}
OK, so far so good. The code above doesn't work, because ti.getTimerId() always returns 0. Anyone an idea why this value is 0? As I've seen in the sources this field is set to an value > 0. this value is then incremented when you add another timerinstance.
Thanks in advance! hope anyone can help.
tom
--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
15 years
couuld not load fact to rule engine
by Hemanth kumar
hi,
Im working on a sample test project.
In that im dynamically creating a class ( fact) and compiling it.
here is my test project
--------------------------------------------------------------------------------------
mainJavaclass
public void runRule()
{
try {
System.out.println("\nRunning rule\n");
// go !
URL[] urls = new URL[]{ new URL("file://"+path) };
URLClassLoader ucl = new URLClassLoader(urls);
Class<?> clazz = ucl.loadClass("test.Message");
Object classObj = clazz.newInstance();
Method method = clazz.getDeclaredMethod("setMessage", new
Class[]{String.class});
//System.out.println("facts loaded\n");
method.invoke(classObj, new Object[]{"Hello"});
log.info("==== Calling Rule Runner ======");
Collection facts = new ArrayList();
facts.add(classObj);
// Load and fire our rules files against the data
new RuleRunner().runStatelessRules(RULES_FILES, null, facts, null, null,
logger);
}
catch (Throwable t) {
t.printStackTrace();
}
}
----------------------------------------------------------------------
Fact
package test;
public class Message{
private String message;
public String getMessage(){
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
}
------------------------------------------------------------------------
sample rule
package test
import test.Message;
rule "Your First Rule"
dialect "mvel"
when
m:Message(message != "Good Bye" )
then
System.out.println("First Rule fired "+m.message );
modify(m){ message = "Good Bye"};
end
-----------------------------------------------------------------
console file http://www.nabble.com/file/p26072723/console.PNG console.PNG
what happens is when i was running the project inside eclipse IDE it works
fine but when i hosted in tomcat and calling from outside ide the rule is
not getting fired.
I think the dyanamically loaded class is not recognised by the rule engine.
suggest me any ideas
Hemanth
--
View this message in context: http://www.nabble.com/couuld-not-load-fact-to-rule-engine-tp26072723p2607...
Sent from the drools - user mailing list archive at Nabble.com.
15 years
Is there any way to hook-up Drools 4.0 RuleBase (session) to a Drools 5.0 KnowledgeBase (session) ??
by Chetan Mahadev
Hi ,
We have been using drools 4.0 in our application. All the rules are loaded
using RuleBase and PackageBuilder.
The application is pretty old, and has got lot of work into it.
Now we want to use Drools 5.0 CEP (Fusion) along with the old rules (based
on drools 4.0).
But the problem , is, how can we hook-up the old "RuleBase" based sessions
with the "KnowledgeBase" sessions of Drools 5.0??
The use case is:
1.Fact enters the system ( asserted using Rulebase), is enriched by rules
(Based on Drools 4.0)
2.The same fact will be treated as EVENT (for CEP), for further correlation
of Events (facts) using KnowledgeBase as proposed i Drools 5.0.
I am facing difficulty in hooking up the two sessions. Is there an way??
Following is the test i did. ( http://drools.pastebin.com/m7d6c613b)
Can anybody help??
IN MY JAVA CODE
1. //load up the rulebase
2. RuleBase ruleBase = readRule(); // Read and load rules frm
a packagebuilder()
3. StatefulSession rBaseSession =
ruleBase.newStatefulSession();
4. Message message = new Message();
5. message.setMessage( "Hello World" );
6. message.setStatus( Message.HELLO );
7. rBaseSession.insert( message );
8.
9. @@//Load KnoweledgeBase
10. KnowledgeBase kbase = loadRuleBase(); // I
set options for EventProcessing in loadRuleBase()
11. KnowledgeSessionConfiguration conf =
12.
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
13. ((SessionConfiguration) conf).setClockType(
ClockType.REALTIME_CLOCK );
14. StatefulKnowledgeSession kbaseSession
= kbase.newStatefulKnowledgeSession(conf,null);
15.
16. rBaseSession.fireAllRules();
17.
IN MY RULE FILE
1. rule "Hello World"
2. when
3. $m : Message( status == Message.HELLO, message :
message )
4. then
5. System.out.println( message );
6. Message message2 = new Message();
7. message2.setMessage( "Hello World" );
8. message2.setStatus( Message.HELLO );
9.
10. WorkingMemoryEntryPoint eventsignaturestream =
drools.getEntryPoint("EVENT SIGNATURE STREAM") ; // I Get a NULLPOINTER
EXCEPTION here
11. eventsignaturestream.insert(message2);
12.
13. end
15 years, 1 month
DSL, DSLR and Changesets...
by Pegram, Macon
All,
Are DSL and DSLR files supported by the KnowledgeAgent / Changeset code.
Here's the details of my test case:
I have a Changeset file I'm trying to load which looks like the
following:
<?xml version="1.0" encoding="UTF-8"?>
<change-set xmlns='http://drools.org/drools-5.0/change-set'
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance' >
<add>
<resource source="classpath:com/test/general/" type="DSL" />
<resource source="classpath:com/test/general/" type="DSLR" />
</add>
</change-set>
There's a single DSL and a single DSLR file in this folder. I'm
loading the change set as follows:
KnowledgeAgent ka = KnowledgeAgentFactory.newKnowledgeAgent(agentName);
ka.applyChangeSet(ResourceFactory.newClassPathResource(agentName +
"-changeset.xml", getClass()));
When I run this code, the logger suggests the DSL and DSLR are being
loaded and compiled:
[2009:10:299 16:10:52:info] KnowledgAgent created, with configuration:
monitorChangeSetEvents=true scanResources=true scanDirectories=true
++ Constructing and applying changeSet: dsl-test
[2009:10:299 16:10:52:info] KnowledegAgent has started listening for
ChangeSet notifications
(null: 3, 68): cvc-elt.1: Cannot find the declaration of element
'change-set'.
[2009:10:299 16:10:317:info] KnowledgAgent applying ChangeSet
[2009:10:299 16:10:317:debug] KnowledgeAgent subscribing to
directory=[ClassPathResource path='com/test/general/']
[2009:10:299 16:10:317:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@b9b618 to
resource=[ClassPathResource path='com/test/general/']
[2009:10:299 16:10:317:debug] ResourceChangeScanner subcribing
notifier=org.drools.io.impl.ResourceChangeNotifierImpl@61ec49 to
resource=[ClassPathResource path='com/test/general/']
[2009:10:299 16:10:317:debug] KnowledgeAgent subscribing to directory
content resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test.dsl']
[2009:10:299 16:10:317:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@b9b618 to
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test.dsl']
[2009:10:299 16:10:317:debug] ResourceChangeScanner subcribing
notifier=org.drools.io.impl.ResourceChangeNotifierImpl@61ec49 to
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test.dsl']
[2009:10:299 16:10:317:debug] KnowledgeAgent subscribing to directory
content resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test-dsl.dslr']
[2009:10:299 16:10:317:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@b9b618 to
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test-dsl.dslr']
[2009:10:299 16:10:317:debug] ResourceChangeScanner subcribing
notifier=org.drools.io.impl.ResourceChangeNotifierImpl@61ec49 to
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test-dsl.dslr']
[2009:10:299 16:10:317:debug] KnowledgeAgent subscribing to
directory=[ClassPathResource path='com/hmc/test/general/']
[2009:10:299 16:10:317:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@b9b618 to
resource=[ClassPathResource path='com/hmc/test/general/']
[2009:10:299 16:10:317:debug] KnowledgeAgent ChangeSet requires
KnowledgeBuilder
[2009:10:299 16:10:317:debug] KnowledgeAgent rebuilding KnowledgeBase
using ChangeSet
[2009:10:299 16:10:317:debug] KnowledgeAgent building
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test.dsl']
[2009:10:299 16:10:333:debug] KnowledgeAgent building
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test-dsl.dslr']
[2009:10:299 16:10:333:info] KnowledgeAgent new KnowledgeBase now built
and in use
However after load is completed I try to run the following code:
System.out.println("KB Info");
Collection<KnowledgePackage> pkgs =
ka.getKnowledgeBase().getKnowledgePackages();
for (KnowledgePackage kp : pkgs) {
for (Rule rule : kp.getRules()) {
System.out.println("Rule: " + rule.getName() + ", " +
ule.getPackageName());
for (String attribs : rule.listMetaAttributes())
System.out.println("---- " + attribs);
}
}
}
I get NO output (except of course "KB Info").
If I initialize the knowledgebase like this:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory
.newClassPathResource("com/test/general/test.dsl"),
ResourceType.DSL);
kbuilder.add(ResourceFactory
.newClassPathResource("com/test/general/test-dsl.dslr"),
ResourceType.DSLR);
if (kbuilder.hasErrors()) {
throw new Exception(kbuilder.getErrors().toString());
}
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
}
... and run the same output code I get a list of the rules that were
loaded.
Any clues why the different behavior?
Macon
15 years, 1 month
Issues with groovy fact objects not matching
by Ilya Sterin
I have an application that dynamically compiles a groovy object with
properties and uses it as a bean class. The object is a statically
defined object, though...
package com.buycentives.types
import com.buycentives.incengine.*
class TestIncentive extends IncentiveData<MonetaryIncentive> {
String name
Integer age
}
The rules compile just fine, as I load the groovy class using a
GroovyClassLoader and inject the groovy class loader like this...
PackageBuilderConfiguration config = new PackageBuilderConfiguration();
config.setClassLoader(loader);
JavaDialectConfiguration dialectConf = (JavaDialectConfiguration)
config.getDialectConfiguration("java");
dialectConf.setCompiler(JavaDialectConfiguration.JANINO);
KnowledgeBuilder kBldr = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
/// Here I add some rules to the builder...
KnowledgeBase kb = KnowledgeBaseFactory.newKnowledgeBase(new
RuleBaseConfiguration(loader));
kb.addKnowledgePackages(kBldr.getKnowledgePackages());
So the rule actually resolves the TestIncentive type just fine, but it
never fires the side effect, as the pattern never seems to match.
TestIncentive incentive = new TestIncentive();
incentive.setAge(25);
// Below never matches...
$input: TestIncentive( age >= 20, age < 30 )
I verify that the injected object actually has an age of 25...
The crazy thing is, that this rule...
$input: Object()
matches the TestIncentive fact in the knowledge base and when I print
out the object in the side effect, it's the same as the one injected,
so it should match the pattern above just fine.
The same rules work just fine when I use a plain Java object or if I
declare a fact type in the drl file.
Any ideas?
Ilya Sterin
15 years, 1 month
[droolsflow] - JPAKnowledgeService - Another Event based NullPointerException
by Bill Tarr
After re-loading a session, and trying to send it an Event, I get the following NullPointerException:
java.lang.NullPointerException
at org.drools.impl.StatefulKnowledgeSessionImpl$ProcessEventListenerWrapper.beforeRuleFlowNodeTriggered(StatefulKnowledgeSessionImpl.java:674)
at org.drools.event.RuleFlowEventSupport.fireBeforeRuleFlowNodeTriggered(RuleFlowEventSupport.java:147)
at org.drools.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:110)
at org.drools.workflow.instance.node.EventNodeInstance.signalEvent(EventNodeInstance.java:50)
at org.drools.workflow.instance.impl.WorkflowProcessInstanceImpl.signalEvent(WorkflowProcessInstanceImpl.java:272)
at com.csatp.svc.rulesmgr.claim.ClaimsDemoJpaTest.validateDocumentWorkflow2(ClaimsDemoJpaTest.java:209)
My code is pretty straightforward:
StatefulKnowledgeSession session = JPAKnowledgeService.loadStatefulKnowledgeSession( 1, knowledgeBase, null, env );
ProcessInstance process = session.getProcessInstance(2);
process.signalEvent("ReceiveDocsEvent", null);
that same code (and Flow) works on a session created from knowledgeBase.newStatefulKnowledgeSession();
This is difficult for me to debug, but here's what I have:
In org.drools.event.RuleFlowEventSupport.fireBeforeRuleFlowNodeTriggered(), the code is getting listeners:
final Iterator<RuleFlowEventListener> iter = getEventListenersIterator();
then iterating over them. In the session created from a regular knowledgeBase, "iter" has the following values
iter = {java.util.concurrent.CopyOnWriteArrayList$COWIterator @ 3411}
snapshot = {java.lang.Object[2] @ 3416}
[0] = {org.drools.audit.WorkingMemoryFileLogger @ 3417}
events = {java.util.ArrayList @ 3419} size = 77
fileName = {java.lang.String @ 3420}"log/claimsdemo"
maxEventsInMemory = 1000
nbOfFile = 0
split = true
initialized = false
filters = {java.util.ArrayList @ 3421} size = 0
[1] = {org.drools.impl.StatefulKnowledgeSessionImpl$ProcessEventListenerWrapper @ 3418}
listener = {com.csatp.svc.rulesmgr.claim.TrackingProcessEventListener @ 3396}
While the session created using JPAKnowledgeService has the following values for "iter"
iter = {java.util.concurrent.CopyOnWriteArrayList$COWIterator @ 3803}
snapshot = {java.lang.Object[1] @ 3805}
[0] = {org.drools.impl.StatefulKnowledgeSessionImpl$ProcessEventListenerWrapper @ 3806}
listener = null
I can see that the EventListeners should be setup in AbstractEventSupport and it's implementing classes,
and they are clearly missing, but I'm not sure where this is going wrong.
I'll gladly fix this, but just don't know where to start, if you have any ideas that can help, I'd greatly appreciate it!
Bill
15 years, 1 month
Re: [rules-users] [droolsflow] JPAKnowledgeService - how do you reload a Session with Processes?
by Bill Tarr
Thanks Kris,
That seems like the solution I was looking for...
I'll try persisting my session ID in my Claims domain object, and walking the node instances first.
If that doesn't work, I'll try create a custom log object to track processes.
Either way, this thread has been a huge help.
Bill
----- Original Message ----
From: Kris Verlaenen <kris.verlaenen(a)cs.kuleuven.be>
To: Bill Tarr <javatestcase(a)yahoo.com>
Sent: Sat, October 24, 2009 7:47:30 PM
Subject: Re: [rules-users] [droolsflow] JPAKnowledgeService - how do you reload a Session with Processes?
Quoting Bill Tarr <javatestcase(a)yahoo.com>:
> However, I don't see any methods in either StatefulKnowledgeSession
> or ProcessInstance that would enable me to gather up SubProcess node
> instances.
>
> Could you point me in the right direction on how I could do this?
>
Yes, cast the process instance to a WorkflowProcessInstance, that way
you can use getNodeInstances() to get all active nodes. You'll then
probably have to use instanceof SubProcessNodeInstance to only filter
out sub-process nodes, and then use getProcessInstanceId() to retrieve
the id of the sub process instance.
Kris
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
15 years, 1 month
Rule is not firing
by satyasri.ch
Hi ,
I am doing the sample drools project.
Below are the sample rule and Fact class.
when Running from eclipse ide both rules are working fine.
Where as running the rule outside eclipse ide only second rule fired .
Suggest me any ideas
----------------------------------------------------------
package test
import test.Message;
rule "Your First Rule"
dialect "mvel"
when
m:Message( )
eval(m.getMessage() == "Hello")
then
System.out.println("First Rule fired ");
end
rule "Your Second Rule"
dialect "mvel"
when
eval(true)
then
System.out.println("Second Rule fired ");
end
------------------------
package test;
public class Message{
private String message;
public String getMessage(){
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
}
Thanks,
Satyasri.
--
View this message in context: http://www.nabble.com/Rule-is-not-firing-tp26056180p26056180.html
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 1 month