[jboss-jira] [JBoss JIRA] Commented: (JBRULES-1315) Rule that uses a 'collect' and 'from' clause together causes problem
Pavlin Zahariev (JIRA)
jira-events at lists.jboss.org
Wed Feb 6 11:46:04 EST 2008
[ http://jira.jboss.com/jira/browse/JBRULES-1315?page=comments#action_12398505 ]
Pavlin Zahariev commented on JBRULES-1315:
------------------------------------------
Hi,
the evil is the sharedCounter which is not used properly. It is increased when a node is found to be equal to an existing node, but on node TupleSource.remove is decreased when a tupleSink calls its tupleSource to detach it from its sink. IMHO there is no clear relation on how many times a node was shared and how many nodes it has in the sink.
The problem happens because sharedCounter is used to check if a node isInUse. This is wrong. Node is in use, if a tupleSink has a reference to its tupleSource - nothing to do with sharedCounter. I also couldn't find any other use of the sharedCounter.
Therefore override the imp[ementation of isInUse() in class TupleSource like this.
public boolean isInUse() {
if (null!=sink) {
Sink[] sinks = sink.getSinks();
return ((null!=sinks) && (0<sinks.length));
}
return false;
}
Now it works fine.
Probably more general solution could be offered from drools team.
Cheers,
Pavlin
> Rule that uses a 'collect' and 'from' clause together causes problem
> --------------------------------------------------------------------
>
> Key: JBRULES-1315
> URL: http://jira.jboss.com/jira/browse/JBRULES-1315
> Project: JBoss Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Components: Reteoo
> Affects Versions: 4.0.3
> Reporter: Igor Bolic
> Assigned To: Edson Tirelli
> Attachments: testRemovePackage.rar
>
>
> Test case:
> Write a Rule that uses a 'collect' and 'from' clause together, example:
> package com.sample.mypackage
> rule "Apply discount"
> when
> $order: Order();
> $items : ArrayList() from collect (OrderItem() from $order.items)
> then
> #apply discount
> end
> first i add the package to RuleBase object, everthing works fine. When i try to 'refresh' my rules, i.e. first remove the package and again
> add the same (modified) package to the RuleBase object, following error occurs:
> java.lang.IllegalArgumentException: Cannot remove a sink, when the list of sinks is null
> at org.drools.reteoo.ObjectSource.removeObjectSink(ObjectSource.java:116)
> at org.drools.reteoo.AlphaNode.remove(AlphaNode.java:181)
> at org.drools.reteoo.LeftInputAdapterNode.remove(LeftInputAdapterNode.java:204)
> at org.drools.reteoo.FromNode.remove(FromNode.java:153)
> at org.drools.reteoo.RightInputAdapterNode.remove(RightInputAdapterNode.java:167)
> at org.drools.reteoo.BetaNode.remove(BetaNode.java:186)
> at org.drools.reteoo.RuleTerminalNode.remove(RuleTerminalNode.java:461)
> at org.drools.reteoo.ReteooBuilder.removeRule(ReteooBuilder.java:224)
> at org.drools.reteoo.ReteooRuleBase.removeRule(ReteooRuleBase.java:272)
> at org.drools.common.AbstractRuleBase.removePackage(AbstractRuleBase.java:460)
> ...
> I've found a workaround for this error by writing my .drl code as following:
> package com.sample.mypackage
> rule "Explode Cart"
> salience 11
> dialect "java"
> when
> $order: Order()
> $item : OrderItem() from $order.items
> then
> insert( $item );
> end
> rule "Apply discount"
> no-loop true
> when
> $order : Order();
> $items : ArrayList() from collect (OrderItem())
> then
> #apply discount
> end
> Now, my rules are 'refreshed' without any error.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list