[Drools 4.0.7]RuleAgent not working correctly inside service
by Jones, Alan R
Hi,
1) I use a package created/deployed in BRMS on a remote machine. The drl
source file has certain dependencies in it (the data model). These
dependencies are inside a jar file, used by BRMS to create/compile the
package.
2) Inside my web service class I have drools-core.jar, in a lib. I have
a method that uses URLClassloader to load the jar with the data model
from an external directory at each service invocation (data models may
get switched out every now and then).
3) I create a Properties object containing URL to the BRMS package, etc.
I use this to create a new RuleAgent:
RuleAgent agent = RuleAgent.newRuleAgent(MyProps);
But, I get NoClassDefError or Class loading errors when the rule agent
tries to load the package, it cannot see the classes I loaded from the
data model jar. In fact, it does not recognize the drools core jars
inside the /lib directory of my service either. However, if I put all
those jars into the WEB-INF/lib directory of the webapp that constitues
my web service implementation (axis2 in this case) and reboot tomcat,
everything works fine. But of course this is very hokey -- is not
acceptable.
How do I get my RuleAgent to see the data model classes I loaded? Why
does it not like the drools-core.jar inside my service? Is this going to
be a class loader nightmare?
Thanks,
Alan J
15 years, 9 months
Reusing Rules across different rule flows
by Roger Tanuatmadja
Hi,
I've looked at the documentation, and I've tried doing it in the IDE, and
basically I don't think it's possible.
Let's just say I have rule A and I want to reuse it as part of 2 different
rule flows. Is this possible? My guess is no.
Thanks,
Roger
15 years, 9 months
Snapshot doesn't include the updated rule?
by psentosa
Hi,
just trying to use BRMS for the 1st time by installing the insurance
example.
BRMS and the example are both deployed on JBoss 4.2.2.
After editing a rule (i.e. Driver is underage) by adding a self-defined
function and some new println statements, i built the package and took a
snapshot, and then try to run the example.
But apparently the edited rule wasn't taken into account bcs the result was
still the same as before the editing.
I checked the source package of the snapshot and found that the snapshot was
still the old one!
So...please correct me if I'm wrong..but as my understanding a snapshot
should include the latest modification, shouldn't it?
- is there any recommended order on how to make update on the rules, so that
it can be promptly used?
any idea, suggestions, critics are welcome
thanks
--
View this message in context: http://www.nabble.com/Snapshot-doesn%27t-include-the-updated-rule--tp1865...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 9 months
enum Type to access entry in HashMap
by thomas kukofka
Hi,
If have an input object Inputobject which contains an enum Paratmeter
which contains all allowed parameters of InputObject:
The entries for the parameters are stored in a map:
private HashMap<Parameter, String> stringParameters;
If I try:
io: InputObject ( stringParameters[InputObject.Parameter.ParameterName] ==
"something")
I got the error
=>Field/method 'InputObject' not found for class 'com.rules.InputObject'Rule
Compilation error
Kind Regards
Thomas
15 years, 9 months
Handle activationCancelled Event
by Claudio Rainoldi
Hi everyone,
i'm developing a java application using drools 4 for domotic control;
i ve implemented a listener on my working memory with the method
afterActivationFired(...)
and activationCancelled(...) .
At startup of my app i've write the following lines:
listener = *new* FiredRulesListener();
workingMemory.addEventListener(listener);
Each time a rule is fired the method afterActivationFired(...) is called and
it is ok; but when the rule stop to be true the method
activationCancelled isn't
never called.
I try to be more clear:
i 've the following rule:
when mylamp=="on"
then
System.out.println("light 1 on");
When i turn on the light 1 the method afterActivationFired(...) is called,
but when i turn off the light the method activationCancelled isn't called.
Can someboy help me??
Thanks in advance.
Cla
My listener code:
*
public* *static* *class* FiredRulesListener *extends*DefaultAgendaEventListener
{
List<Rule> firedRules = *new* ArrayList<Rule>();
*
public* List<Rule> getFiredRules()
{
*
return* *this*.firedRules;
}
@Override
*
public* *void* afterActivationFired(AfterActivationFiredEvent event,
WorkingMemory workingMemory)
{
Rule rule = event.getActivation().getRule();
*
if* (!*this*.firedRules.contains(rule))
*this*.firedRules.add(rule);
}
@Override
*
public* *void* activationCancelled (ActivationCancelledEvent event,
WorkingMemory workingMemory)
{
*System.out.println("i never see this message");*
Rule *rule*= event.getActivation().getRule();
*this*.firedRules.remove(rule);
}
15 years, 9 months
How to avoid circular rule activation for non circular problems?
by Ralph Ammon
I'd like to get some hints to improve the rules of my simple planning
system.
My simple planning system is derived from the HelloWorld Drools Project. The
job of my planning system is to calculate startTime and endTime as function
of duration and predecessors for each task. Each task has the fields
long duration;
Set<Task> predesessors;
long startTime;
long endTime;
For each task the rule (endTime = startTime + duration) should hold. If a
task has no predecessors, then its startTime should be 0. If a task has
predecessors, then is should start at the latest endTime of all
predecessors.
These are my DRL-rules:
rule "Calc EndTime"
no-loop true
when
$t : Task()
then
$t.setEndTime( $t.getStartTime() +
$t.getDuration() );
System.out.println( "Drools: Set " +
$t.getName() + ".EndTime to " + $t.getEndTime() );
update( $t );
end
rule "Calc StartTime without predecessors"
lock-on-active true
when
$t : Task(predecessorCount == 0)
then
$t.setStartTime( 0 );
System.out.println( "Drools: " +
$t.toString() + " can start immediately" );
update( $t );
end
rule "Calc StartTime with predecessors"
when
$t : Task(predecessorCount > 0, $predecessors :
predecessors )
# Checking EndTime > 0 for all predecessors means that
all EndTimes are
# initialy calculated. This is not what we realy want.
Actually we'd like
# to recalculate the successors EndTime, when ever it is
needed.
forall (
$succTask : Task( this == $t
)
$predTask : Task( this
memberOf $predecessors, endTime > 0 )
)
$endTime : Number()
from accumulate( $p : Task() from
$predecessors,
max($p.getEndTime()) )
then
$t.setStartTime( $endTime.longValue() );
System.out.println( "Drools: " +
$t.toString() + " has new StartTime" );
# !!!! If we did an update($t); here, we
would get an infinite recursion.
end
My TestClass creates three tasks: task0, task1 and task2. Each task has an
initial duration and (task0, task1) are predecessors of task2. It is
important that this example has no circular dependencies; otherwise the
rules, mentioned above, couldn't be applied.
After fireAllRuels() the endTime of task2 is calculated wrong, so obviously
the rule "Calc EndTime" should be activated. Is the rule-attribute (no-loop
= true) not the right solution to avoid circularity here?
Then the duration of task0 is updated outside of the rule engine. After a
second fireAllRuels() the endTime of task0 is recalculated, but task2 is not
recalculated at all. How can I tell the rule engine, that a task depends on
its predecessors?
I'd appreciate any input that could help me making this example work and if
it works very efficient on a big number of tasks it's brilliant. If anybody
is interested in my TestClass, to run this example with some logging, please
tell me.
Ralph Ammon
15 years, 9 months
Is "or" allowed in a rule? Can I link the rules?
by Yu Wang
I'm a beginner user of Jboss, please bear with my maybe dumb questions:
1. Seems to me that the conditions in a rule are always connected with "AND"
relation:
such as the following rule
if C1
C2
C3
then D1
it means "if C1 and C2 and C3, then D1"
Is "or" allowed? I mean , can I express: "if (C1 or C2 or C3) and C4, then
D1" in 1 rule?
Right now, I can only use 3 rules to express it:
if C1
C4
then D1
if C2
C4
then D1
if C3
C4
then D1
2. Can I form a link of rules? Can rule A's decision (the Then part) be rule
B's condition (The When part)?
for instance:
rule A: if C1, C2, C3 then D1
rule B: if D1, C4 then D2
When the complexity increases, the number of rules explodes.
I browsed the document and didn't find a clue. I'm using the 4.0.7.
Your help is highly appreciated.
15 years, 9 months
Drools 4 poor performance scaling?
by Ron Kneusel
I am testing Drools 4 for our application and while sequential mode is very fast I get very poor scaling when I increase the number of facts for stateful or stateless sessions. I want to make sure I'm not doing something foolish before deciding on whether or not to use Drools because from what I am reading online it should be fast with the number of facts I have.
The scenario: I have 1000 rules in a DRL file. They are all of the form:
rule rule0000
when
Data(type == 0, value> 0.185264);
Data(type == 3, value < 0.198202);
then
insert(new AlarmRaised(0));
warnings.setAlarm(0, true);
end
where the ranges checked on the values and the types are randomly generated. Then, I create a Stateful session and run in a loop timing how long it takes the engine to fire all rules as the number of inserted facts increases:
// Run
for(j=0; j < 100; j+=5) {
if (j==0) {
nfacts = 1;
} else {
nfacts = j;
}
System.out.println(nfacts + ":");
// Get a working memory
StatefulSession wm = ruleBase.newStatefulSession();
// Global - output
warnings = new Alarm();
wm.setGlobal("warnings", warnings);
// Add facts
st = (new Date()).getTime();
for(i=0; i < nfacts; i++) {
wm.insert(new Data(rand.nextInt(4), rand.nextDouble()-0.5));
}
en = (new Date()).getTime();
System.out.println(" facts = " + (en-st));
// Now run the rules
st = (new Date()).getTime();
wm.fireAllRules();
en = (new Date()).getTime();
System.out.println(" rules = " + (en-st));
// Clean up
wm.dispose();
System.out.println("\n");
}
This code is based on the HelloWorldExample.java code from the manual and the setup for the rule base is the same as in the manual. As the number of facts increases runtime increases dramatically:
facts -- runtime (ms)
10 -- 168
20 -- 166
30 -- 344
40 -- 587
50 -- 1215
60 -- 1931
70 -- 2262
80 -- 3000
90 -- 4754
with a maximum memory use of about 428 MB RAM. By contrast, if I use sequential stateless sessions, everything runs in about 1-5 ms.
Is there something in my set up that would cause this, or is this how one would expect Drools to scale? I read about people using thousands of facts so I suspect I'm setting something up incorrectly.
Any help appreciated!
Ron
_________________________________________________________________
The other season of giving begins 6/24/08. Check out the i’m Talkathon.
http://www.imtalkathon.com?source=TXT_EML_WLH_SeasonOfGiving
15 years, 9 months
java.util.NoSuchElementException in buildAsset
by Sergio Stateri Jr
Hi,
I have installed BRMS (Drools 5) and create a repository for BRMS. When
I create a simple rule, like:
when
$object: Object()
then
System.out.println("ok");
end
all works fine, but... When I create a complex rule, using my own complex
classes and click in the validate button, the following error is reported
:
Error
An error occurred executing the action.
java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)
at org.codehaus.janino.UnitCompiler.findClass(UnitCompiler.java) at org.codehaus.janino.Compiler$CompilerIClassLoader.findIClass(Compiler.java)
at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java) at org.codehaus.janino.UnitCompiler.reclassifyName(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.reclassifyName(UnitCompiler.java) at
org.codehaus.janino.UnitCompiler.reclassify(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$114(UnitCompiler.java) at org.codehaus.janino.UnitCompiler$15.visitAmbiguousName(UnitCompiler.java)
at org.codehaus.janino.Java$AmbiguousName.accept(Java.java) at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$104(UnitCompiler.java) at org.codehaus.janino.UnitCompiler$15.visitMethodInvocation(UnitCompiler.java)
at org.codehaus.janino.Java$MethodInvocation.accept(Java.java) at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.access$51(UnitCompiler.java) at org.codehaus.janino.UnitCompiler$9.visitMethodInvocation(UnitCompiler.java)
at org.codehaus.janino.Java$MethodInvocation.accept(Java.java) at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java) at
org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.access$25(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler$6.visitMethodInvocation(UnitCompiler.java)
at org.codehaus.janino.Java$MethodInvocation.accept(Java.java) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.access$8(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler$4.visitExpressionStatement(UnitCompiler.java)
at org.codehaus.janino.Java$ExpressionStatement.accept(Java.java) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.access$7(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler$4.visitBlock(UnitCompiler.java) at org.codehaus.janino.Java$Block.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java)
at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java)
at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java) at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java)
at org.codehaus.janino.Compiler.compile(Compiler.java) at org.drools.commons.jci.compilers.JaninoJavaCompiler.compile(JaninoJavaCompiler.java:174)
at org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJavaCompiler.java:51)
at org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.java:394)
at org.drools.compiler.DialectRegistry.compileAll(DialectRegistry.java:60)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:324)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:168)
at org.drools.brms.server.contenthandler.DRLFileContentHandler.compile(DRLFileContentHandler.java:32)
at org.drools.brms.server.builder.ContentPackageAssembler.buildAsset(ContentPackageAssembler.java:139)
at org.drools.brms.server.builder.ContentPackageAssembler.buildPackage(ContentPackageAssembler.java:127)
at org.drools.brms.server.builder.ContentPackageAssembler.(ContentPackageAssembler.java:84)
at org.drools.brms.server.builder.ContentPackageAssembler.(ContentPackageAssembler.java:92)
at org.drools.brms.server.ServiceImplementation.buildPackage(ServiceImplementation.java:897)
at org.drools.brms.server.ServiceImplementation.buildPackage(ServiceImplementation.java:887)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585) at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:40)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:155)
at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:91)
at org.drools.brms.server.ServiceImplementation_$$_javassist_3.buildPackage(ServiceImplementation_$$_javassist_3.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585) at org.jboss.seam.remoting.gwt.GWTToSeamAdapter.callWebRemoteMethod(GWTToSeamAdapter.java:85)
at org.jboss.seam.remoting.gwt.GWTRemoteServiceServlet.processCall(GWTRemoteServiceServlet.java:320)
at org.jboss.seam.remoting.gwt.GWTRemoteServiceServlet.doPost(GWTRemoteServiceServlet.java:188)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:46)
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.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
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:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:595)
I have created my models, categories and packages using the BRMS interface.
Then, I have no idea how to solve this problem, and the brms code doesn?t
show the line numbers before StringTokenizer class (I could see the error
cause in the brms source code, but the "UnitCompiler.java" is shown in the
line number position, why ?).
Thanks for any help.
Sergio Stateri Jr.
sergio.stateri(a)globo.com
15 years, 9 months