kcontext.getKnowledgeRuntime() returns StatefulKnowledgeSessionImpl even when session is started as a CommandBasedStatefulKnowledgeSession
by Darin Wilcox
Hi,
In my project, I have created a StatefulKnowledgeSession that is
persistent. The StateulfKnowledgeSession implementation is the
CommandBasedStatefulKnowledgeSession. From this
CommandBasedStatefulKnowledgeSession, I started a workflow that contains a
SignalEvent waiting for something to signal into that process.
I then started a second process that contains only an action node with the
following code:
kcontext.getKnowledgeRuntime().signalEvent("TestSignal2", "from
SignalHello"); // Should broadcast to all other processes currently
running in this session.
The signal is never received by the first process because the
kcontext.getKnowledgeRuntime() that is trying to signal the event uses an
instance of StatefulKnowledgeSessionImpl not
CommandBasedStatefulKnowledgeSession. Can anyone explain why the
kcontext.getKnowledgeRuntime() returns a different instance of the
StatefulKnowledgeSession than the one it was started with? Is this a bug?
Thanks,
- Darin
13 years, 10 months
Drools fusion how to I catch an Exception
by RichardAmbridge
If I have a rule that has an error in it, the error isn't being caught by the
compiler and the error doesn't happen as the Object is inserted into the
session, it only happens after a time period completes, then Drools silently
fails.
How can I catch these silent failures.
See below for test case.
Notice in the After5 rule there is a mistake in the then part.
m.status=$m.status;
$m doesn't exist.
If i change this to $m.status=m.status, the compiler detects the error, but
this way of m.status=$m.status is not found.
When the rule fires it just dies.
I need to be able to catch the Exception somehow and report it..
Any help really appreciated..
Thanks
Ric
----------
sample.drl:-
----------
package com.sample
import com.sample.DroolsTest.Message;
declare Message
@role ( event )
end
rule "Hello"
dialect "mvel"
when
m : Message( status == Message.HELLO, myMessage : message )
then
System.out.println( "Hello added" );
end
rule "After5"
dialect "mvel"
when
m : Message( status == Message.HELLO, myMessage : message )
not( Message( status == Message.GOODBYE , this after [0s,5s] m ))
then
System.out.println( "After5 then start" );
m.status=$m.status;
System.out.println( "After5 then stop" );
retract(m);
end
----------
DroolsTest.java:
----------
package com.sample;
import org.drools.KnowledgeBase;
/**
* This is a sample class to launch a rule.
*/
public class DroolsTest {
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase
.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
.newFileLogger(ksession, "test");
// go !
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
System.out.println("Inserting message");
ksession.insert(message);
System.out.println("Fire all rules");
ksession.fireAllRules();
System.out.println("Sleep 10");
Thread.sleep(10000);
System.out.println("End sleep");
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBaseConfiguration conf = KnowledgeBaseFactory
.newKnowledgeBaseConfiguration();
conf.setOption(EventProcessingOption.STREAM); // STREAM mode as we are
// dealing with Events
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(conf);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
public static class Message {
public static final int HELLO = 0;
public static final int GOODBYE = 1;
private String message;
private int status;
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public int getStatus() {
return this.status;
}
public void setStatus(int status) {
this.status = status;
}
}
}
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-fusion-how-to-I-catch-an-Excepti...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
Fwd: how to import function in drl file on guvnor
by Michael Anstis
Forwarded to mailing list.
You would have to consider use of free-format DRL in this scenario.
---------- Forwarded message ----------
From: <avneesh.sisodia(a)intelegencia.com>
Date: 4 September 2012 12:33
Subject: how to import function in drl file on guvnor
To: michael.anstis(a)gmail.com
Hello mantis,
I am very new in drools and guvnor users. I have a problem during making
rules. I want to use my predefined functions in rule execution.
Suppose I have a rule "companyDivision" and i want to import it into my
rule file like this:
package com.exp.test
import com.abc.bean.CompanyBean
import function
com.abc.util.Validation.companyDivision;
rule "CompanyInfo"
dialect "mvel"
when
CompanyBean( businessType == "ABC" , insuranceProgram ==
"XYZ" )
then
CompanyBean fact0 = new CompanyBean();
fact0.setBusinessType( "ABC" );
fact0.setInsuranceProgram( "XYZ" );
companyDivision(fact0 );
end
How I can do this.
I am doing following steps to c\generate rules::
1. creating com.exp.test package
2. uploading jar(model) file which included all pojo files of application
3. creating "CompanyInfo" rule
rule file generated by guvnor is like this:::
package com.exp.test
import com.abc.bean.CompanyBean
rule "CompanyInfo"
dialect "mvel"
when
CompanyBean( businessType == "ABC" , insuranceProgram ==
"XYZ" )
then
CompanyBean fact0 = new CompanyBean();
fact0.setBusinessType( "ABC" );
fact0.setInsuranceProgram( "XYZ" );
insert(fact0 );
end
I have only two options there 1. insert and 2. insert logically.
but on place of insert and insert logically I want to use "companyDivision"
function.
Please guys tell me how it is possible.
Thanks
13 years, 10 months
Fwd: need help to use drools guvnor.
by Michael Anstis
Forwarded to mailing list.
You could consider using the RSS feed (
http://blog.athico.com/2011/03/atompub-interface-for-guvnor.html) and an
adaptation of this:
https://community.jboss.org/wiki/PublishDroolsArtifactsFromAProductionEnv...
---------- Forwarded message ----------
From: <avneesh.sisodia(a)intelegencia.com>
Date: 4 September 2012 12:32
Subject: need help to use drools guvnor.
To: michael.anstis
Hey manstis,
I need your valuable help. I have a project which is based on Insurance
domain. I have to use drools-guvnor in it to execute some rules.Now I had
deploy guvnor 5.3 on JBoss AS 7.0.Final. And I am able to use static rules
from .drl file by using stateless session. I need to do it dynamic. I mean
when I changed any condition in rule file on guvnor it should be reflect on
application. So I want that you suggest me any link where I can get useful
information. how I can use rules directly from guvnor on java.
Thanks..
13 years, 10 months
IntelliFest Drools & jBPM Workshop Agenda (San Diego Oct 2012)
by Mark Proctor
http://www.dzone.com/links/r/intellifest_drools_amp_jbpm_workshop_agenda_...
---
At IntelliFest this year there are two Drools workshops. There is the "General Drools&jBPM Workshop", which is a series of high level talks explaining the various features of Drools&jBPM. The second is the workshop "Rule Design Patterns in Production Systems", by Dr Wolfgang Laun, which is aimed at rule authoring techniques. The agenda for both is below, you can see the more detailed and up to date agenda here.
Only 7 weeks to go, and there are limited spaces, so register soon here.
General Drools&jBPM Workshop
8.00 AM: Breakfast Social – pre-laptop setup, and QA time with solution Architects.
-Key will be provided to setup your laptop, so you can view and run the examples used during the talks.
9.00 BRMS Product Overview (Prakash Aradhya 15min)
How we turn the Drools and jBPM communtiy parts into a world class product. Supporting and harvesting all the innovation done in the open community, Red Hat delivers reliable, dependable and integrated solutions for enterprise customers.
9.15 Introduction to Drools Expert (Mark Proctor 45min)
Drools Expert covers the business rule engine. A gentle, example driven, dive into the Drools technical rule language and engine features.
10.10 Introduction to Drools Fusion (Edson Tirelli 45min)
Learn how Drools does CEP differently. Our unified approach extends Drools Expert with a series of language and sub-engine extensions to provide temporal reasoning and event correlation.
11.05 Introduction to jBPM and BPMN2 (Kris Verlaenen 45min)
jBPM is a BPM engine designed for flexible processes, implementing and extending the BPMN2 spec. Built form the ground up to be part of a unified strategy for business automation and decision management. jBPM fully integrates with Drools Expert and Fusion.
11.45 Decision Modelling with Graphical Editors (Edson Tirelli 30min)
Drools Expert provides sophisticated web based tooling, around decision tables, guided editors and templates. Our decision modelling approach draws from the very best research found at Dr Jan Vanthienien school of Decision Modelling.
12.30 Working Lunch – Experience Drools and jBPM – Hands on labs (Optional) (1hour)
13.30 Human Tasks up Close and Personal (Kris Verlaenen 40min)
Human tasks are a central component of BPM. This example driven talk will build an example live, demonstrating what jBPM’s Human Task technology can do for you.
14.20 Building Games with Drools – Pong, Snake and Wumpus (Mark Proctor 40min)
Time for some hard play, learn how to build classic computer games with Drools. These also provide interesting exercises in BA requirements gathering.
15.10 Drools Planner a Quick Overview (Geoffrey De Smet 40min)
Whether it’s employee rostering, task scheduling, vehicle routing, bin packing or another planning problem: all organizations try to optimize their limited resources under constraints. Drools Planner optimizes business resources for normal Java programmers.
15.50 Drools Chance for Imperfect Reasoning (Davide Sottara 40min)
Sometimes data quality is not perfect, so facts may not be known with precision and certainty. Likewise, crisp constraints such as hard thresholds might not be able to capture the complexity of a business policy. Drools Chance allows to apply gradual and/or probabilistic constraints to uncertain or vague data.
16.40 UberFire – Drools&jBPM Workbench framework (Mark Proctor 30min)
UberFire is a new project that forms the foundation of our 6.0 web tooling. It’s standalone framework that provides a sophisticated workbench framework for the web; where everything is a plugin. Come learn about the Uberfire, and how you can use the workbench to build your own web applications.
17.10 Drools&jBPM 6.0 and Beyond (Optional : open as long as people remain)
An open presentation and discussion about the design ideas, principles and goals that are driving the development of Drools & jBPM version 6.0. This will be an optional and informal session where attendees will have the opportunity to learn about what is coming, contribute ideas and provide feedback that will be taken in consideration by the development team.
17.10 Hands on Lab
Run at the same time as "Drools&jBPM and Beyond" and Beyond. Solution Architects are on hand to help you with your coding problems, and running examples.
Rule Design Patterns in Production Systems
Rule Design Patterns
What is a “Rule Design Pattern”?
Basic Rule Formats
Fact Classification
Handling Failure to Match
Extending Rules
Reasoning with Interfaces
Active Facts
Marker Facts
Fact Proxies
Application Design Patterns
Short-Term Sessions
Permanent Sessions
13 years, 10 months
Add calendars to knowledge session from Spring?
by dunnlow
I am using the Drools 5.4 integration server in a stateless session. I have
it running fine with the example. Now, I want to use custom Quartz
calendars in my rules. The only way I could come up with to do this in
Spring (a la integration server) was to create a bean that takes a ksession
constructer then creates the calendars and adds them to that ksession.
I see that the bean is created with a knowledge session and all seems ok,
but none of my calendar-based rules ever fire regardless of how the
calendars are configured. (I test the calendars in my bean (with a call to
isTimeIncluded()) and they seem to be in working order.
Also weird is that bean's constructor gets called twice and with two
different knowledge sessions. Once when I start the application, and then
again when I send to the rules service.
1) What is the right was to add custom calendars to a knowledge session (via
Spring)?
2) Any idea why my bean is getting called twice with different knowledge
sessions?
Thanks for any insight. -J
---in knowledge-service.xml
<drools:ksession id="ksession1" type="stateful" kbase="kbase1"
note="node1"/>
<bean id="myCalendar" class="org.test.MyQuartzCalendarLoader">
<constructor-arg ref="ksession1"/>
</bean>
--- MyQuartzCalendarLoader.java
public class MyQuartzCalendarLoader {
private static StatefulKnowledgeSession thisSession=null;
public MyQuartzCalendarLoader (StatefulKnowledgeSession thisKs) {
//gets called twice?
thisSession=thisKs;
print thisSession.tostring() -- looks ok
WeeklyCalendar calendar = new WeeklyCalendar();
org.drools.time.Calendar onlyWeekDays =
QuartzHelper.quartzCalendarAdapter(calendar);
calendar.setDayExcluded(Calendar.WEDNESDAY,false) -- I toggle
just to test
print onlyWeekDays.isTimeIncluded(now.getTime()); --- also
works as expected
Calendars cals =
thisSession.getCalendars().set("ONLYWEEKDAYS",onlyWeekDays);
}
}
--- test.drl
rule "weekdays" dialect "mvel" <-- This rule never fires unless i
remove calendars.
calendars "ONLYWEEKDAYS"
when
$m:Message()
then
$m.text = "FIRED"
end
--
View this message in context: http://drools.46999.n3.nabble.com/Add-calendars-to-knowledge-session-from...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
Reg. Iterating over a list
by Phani Saripalli
Hi.
I tried to identify relevant ways for some container specific operations
like exists, forall (or foreach). Basically I have started using for
software product line research, and specifically model checking over product
line models. The initial results so fat ( considering the time I started)
have been wonderful, alas I am tuck at this point.
For example, consider :
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
declare Project
a : int
b : int = 5
list : List = new java.util.ArrayList(java.util.Arrays.asList(1 , 2 , 3
, 4 , 5))
end
Now that the element of Project - list is configured, I would like to
perform some operations on it like:
a) for each - for the list (Project - P; P.list), is each element is greater
than 2? (or in essence - evaluating each element using a boolean
expression).
b) Similarly, a function like exists . for the list, is there any element
for which this expression is satisfied -
t > 2 && t < 5, where t is the iterator for the list.
As the elements of the lists are mere numbers (in this case ints), I am not
really aware/clear how I can use the Drools operations collect, for all etc.
Previously I worked with Jess rule engine, and it has in built lambda
functions which nicely provides list iterators and thus evaluating each
element of the list against a boolean expression.
I am at a very important point in my work, and any hint or solution will be
highly appreciated.
Many thanks :)
Phani
--
View this message in context: http://drools.46999.n3.nabble.com/Reg-Iterating-over-a-list-tp4019512.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months