Unexpected Accumulate Collect behavior
by rymy8564
I'm using Spring AMQP to read messages from RabbitMQ. After a message is
read it's deserialized into one header (parent) object and multiple detail
(child) objects. Those facts are then inserted into a stateless rule
session. Finally, the updated facts are inserted into a database.
I have several rules that will aggregate the detail facts using either the
collect or accumulate functions. Here's an example.
rule "Header.TotalDuration"
when
h : BresHeader()
n : Number()
from accumulate( d : BresDetail(willSendToInvoice==true, uniqueConfID ==
h.uniqueConfID), sum(d.Duration) )
then
h.TotalDuration = new Integer(n.longValue());
System.out.println("[TotalDuration] rule ran");
end
If I run this once (reading in one message) in jUnit, the TotalDuration is
calculated correctly. If I run it in tomcat (continuously reading messages)
the values for TotalDuration are not correct and increase after each each
pass (message is grabbed, rules ran, facts persisted, repeat) and I can't
figure out why.
Can anyone shed light on this behavior?
--
View this message in context: http://drools.46999.n3.nabble.com/Unexpected-Accumulate-Collect-behavior-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months
configuring timings for event expiry
by rule_dev
Hi ,
I was wondering if it is possible to write a rule in such a way that you are
able to set the 'this after' for events using an attribute from a class.
rule "correlate orders"
when
$bo : BuyOrderEvent( $id : id )
$ae : AckEvent( id == $id, this after[0,10s] $bo )
then
// do something
end
in the above rule template I would like to set the "this after [0,10]" part
using a custom value from say a date attribute of the BuyOrderEvent class.
Thanks for your time.
--
View this message in context: http://drools.46999.n3.nabble.com/configuring-timings-for-event-expiry-tp...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months
Re: [rules-users] Using EntitySelector (EntityFilterClass)
by ge0ffrey
pppoole wrote
> I have a planning entity which has a "ResourceType" on it and I am
> attempting to schedule resources on the entity. The Resource is the
> Planning variable and the Resource instance has a "ResourceType" on it as
> well. I want to filter to make sure that a ResourceType matches between
> the PlanningEntity and the PlanningVariable prior to subjecting it to
> rules (since this is a hard constraint that can never be broken and want
> to save on performance). For example, if my PlanningEntity calls for a
> resource of type "janitor", then I shouldn't assign a Resource
> (PlanningVariable) of type "teacher" to the event. In order to filter
> these, I implemented a SelectionFilter class and validate that the
> entity's resource type matches the planning variable's resource type and
> return false if not. This is definitely returning the correct values (I
> debugged this to confirm), but yet my final solution is still getting the
> wrong resource types on it.
>
> My implementation for my filter:
>
> public boolean accept(ScoreDirector scoreDirector, PlanningEvent
> selection)
> {
> return selection.getRequiredResourceType().getType()
> .equals(selection.getResource().getResourceType().getType());
> }
>
> My configuration:
> <changeMoveSelector>
>
> <entitySelector>
>
> <entityFilterClass>
> com.lmco.mst.lss.autoscheduler.domain.move.RequiredTypeEntityFilter
> </entityFilterClass>
>
> </entitySelector>
> </changeMoveSelector>
> Please advise, I am kind of stuck.
>
> Thanks!
This thread continues here:
http://stackoverflow.com/questions/15394426/drools-planner-planner-not-pr...
--
View this message in context: http://drools.46999.n3.nabble.com/Using-EntitySelector-EntityFilterClass-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months
Strange exception
by goforcrazy
Hello,
I have been having my Drools project up and running but all of a sudden get
this new exception. Could anyone help me figure this out.
java.lang.IndexOutOfBoundsException: Index: 381, Size: 381
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at org.antlr.runtime.CommonTokenStream.LT(CommonTokenStream.java:103)
at org.drools.lang.ParserHelper.reportError(ParserHelper.java:391)
at org.drools.lang.DRLParser.compilationUnit(DRLParser.java:196)
at org.drools.lang.DRLParser.compilationUnit(DRLParser.java:157)
at org.drools.compiler.DrlParser.compile(DrlParser.java:240)
at org.drools.compiler.DrlParser.parse(DrlParser.java:157)
at org.drools.compiler.DrlParser.parse(DrlParser.java:139)
at
org.drools.compiler.PackageBuilder.drlToPackageDescr(PackageBuilder.java:478)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:467)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:673)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:45)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:34)
at cs441.eews.ServerApp.readKnowledgeBase(ServerApp.java:88)
at cs441.eews.ServerApp.main(ServerApp.java:36)
java.lang.RuntimeException: org.drools.compiler.DroolsParserException:
Unexpected exception raised while parsing. This is a bug. Please contact the
Development team :
Index: 381, Size: 381
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:705)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:45)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:34)
at cs441.eews.ServerApp.readKnowledgeBase(ServerApp.java:88)
at cs441.eews.ServerApp.main(ServerApp.java:36)
Caused by: org.drools.compiler.DroolsParserException: Unexpected exception
raised while parsing. This is a bug. Please contact the Development team :
Index: 381, Size: 381
at org.drools.compiler.DrlParser.compile(DrlParser.java:258)
at org.drools.compiler.DrlParser.parse(DrlParser.java:157)
at org.drools.compiler.DrlParser.parse(DrlParser.java:139)
at
org.drools.compiler.PackageBuilder.drlToPackageDescr(PackageBuilder.java:478)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:467)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:673)
... 4 more
Thanks,
Sam
--
View this message in context: http://drools.46999.n3.nabble.com/Strange-exception-tp4022814.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months
Implementing Refraction with Drools
by magaram
I believe we can inject in Refraction capabilities into Drools Rule Engine
using a simple Agenda Filter. I have tested this with test cases against
JRules and Drools and get similar results. Without the Refraction Agenda
Filter it loops infinitely as expected.
Please try it out and tell me what you think. I believe refraction is a much
needed feature of a forward chaining rule engine for commercial purposes.
Any feedback is deeply appreciated.
Here is what the code looks like
---------Agenda Filter---------------------------
package test;
import java.util.ArrayList;
import java.util.List;
import org.drools.runtime.rule.Activation;
import org.drools.runtime.rule.AgendaFilter;
/**
* This custom agenda filter injects refraction behavior into the rule engine
* @author Mukundan Agaram
*
*/
public class RefractionAgendaFilter implements AgendaFilter {
private List encounteredActivations = new ArrayList();
@Override
public boolean accept(Activation act)
{
//Check for a Refraction
if (encounteredActivations.contains(act))
{
//Remove from encountered activations for future firing
encounteredActivations.remove(act);
//return false so the rule is not selected as part of the refraction
return false;
}
//Otherwise add the rule to check for potential refractions in the future
encounteredActivations.add(act);
//select the rule to be part of the agenda
return true;
}
}
-----------------DRL------------------------
//created on: Jan 15, 2013
package test
dialect "mvel"
rule testFooBar1
salience 100
when
$foo : Foo()
$bar : Bar(y > 0)
then
$foo.setX(($foo.getX() + $bar.getY()));
System.out.println("Fired "+drools.getRule().getName())
update($foo);
end
rule testFooBar2
salience 150
when
$foo : Foo(x >= 6)
then
System.out.println("Fired "+drools.getRule().getName())
end
rule testFooBar3
salience 50
when
$foo : Foo(x >= 7)
then
System.out.println("Fired "+drools.getRule().getName())
end
----------------Runtime execution code--------------------------
package test;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
public class TestFooBarMain {
private static void test()
{
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "TestFooBar.drl",
TestFooBarMain.class ),
ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
System.out.println( kbuilder.getErrors().toString() );
}
else
{
System.out.println("DRL parsing - success!");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
Foo foo1 = new Foo();
foo1.setX(6);
Bar bar1 = new Bar();
bar1.setY(3);
ksession.insert(foo1);
ksession.insert(bar1);
ksession.fireAllRules(new RefractionAgendaFilter());
}
/**
* @param args
*/
public static void main(String[] args) {
test();
}
}
----------------Facts-------------------------
package test;
public class Foo {
private int x;
private int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
package test;
public class Bar {
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
private int x;
private int y;
}
Thanks,
Mukundan Agaram
--
View this message in context: http://drools.46999.n3.nabble.com/Implementing-Refraction-with-Drools-tp4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months
Unable to parse ChangeSet in Linux Machine
by anniejoseph
Hi
I'm using change-set.xml, which pionts to a drl file.It *worked fine in
Windows* machine. But while running change-set.xml in *Linux machine I got
the following exception*.
java.lang.RuntimeException: *Unable to parse ChangeSet*
at
org.drools.agent.impl.KnowledgeAgentImpl.getChangeSet(KnowledgeAgentImpl.java:448)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:180)
at
xxx.xxxxxxx.xxxxx.xxxxxxxxxxxxx.xxxxxxxx.xxxxxxxx.<init>(xxxxxxx.java:79)
at
xxx.xxxxxxx.xxxxx.xxxxxxxxxxxxx.xxxxxxxx.xxxxxxxx.<clinit>(xxxxxxx.java:58)
at
org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:1229)
at
org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:134)
at
org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:205)
at
org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:122)
at
org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:43)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.NetworkClient.openServer(NetworkClient.java:118)
at sun.net.ftp.FtpClient.openServer(FtpClient.java:488)
at sun.net.ftp.FtpClient.openServer(FtpClient.java:475)
at
sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:270)
at
sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:352)
at org.drools.io.impl.UrlResource.grabStream(UrlResource.java:210)
at org.drools.io.impl.UrlResource.getInputStream(UrlResource.java:146)
at org.drools.io.impl.UrlResource.getReader(UrlResource.java:214)
at
org.drools.agent.impl.KnowledgeAgentImpl.getChangeSet(KnowledgeAgentImpl.java:446)
... 13 more
My code is:
kbase= KnowledgeBaseFactory.newKnowledgeBase();
ksession= kbase.newStatefulKnowledgeSession();
aconf = KnowledgeAgentFactory .newKnowledgeAgentConfiguration();
aconf.setProperty("drools.agent.newInstance", "false");
kagent = KnowledgeAgentFactory.newKnowledgeAgent( "Agent", aconf);
kagent.applyChangeSet( ResourceFactory.newFileResource(filePath));
kbase = kagent.getKnowledgeBase();
ksession= kbase.newStatefulKnowledgeSession();
sconf
=ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
sconf.setProperty( "drools.resource.scanner.interval",
AgentContainerContext.getRuleReloadInterval() );
ResourceFactory.getResourceChangeScannerService().configure( sconf );
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
Can any one help me to solve my problem?
Thanks & Regards
Annie
--
View this message in context: http://drools.46999.n3.nabble.com/Unable-to-parse-ChangeSet-in-Linux-Mach...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months