How to write a rule that fires when it matches against specific facts in working memory.
by groovenarula
Hello,
I have a fact called 'Option' :
public class Option {
private String code;
private Item item;
public String getCode() {
return code;
}
public void setCode(String optionCode) {
this.code = optionCode;
}
At any point in time, the working memory can have several Option instances
with different code values. My rules need to fire specifically when the
working memory contains a specific set of options. e.g. Rule 1 should fire
if and only if the working memory contains 2 option instances one with code
"P1" and the other with "P2" (order should not matter).
I tried to use 'forall' as follows :
rule "Matched Options"
when
forall (
Option ( code == "P1" || code == "P2" )
)
then
//insert( new IsPriced( i ) );
System.out.println ( "Priced using G/S ");
end
However, the rule above never fires. Maybe I should be taking a different
approach. I'm still learning through how to create rules. So any
help/suggestions on how to tackle the above will be appreciated.
Thanks
Gurvinder
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-t...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 10 months
Drools Server 5.1.1 - Something wrong with the XStream Marshaller
by OlliSee
Its impossible to add an "out-identifier" (which is pretty bad). The JSON
Marshaller works fine, though.
Can I get a clean implementation somewhere?
Exception:
Exception in thread "main" java.lang.NullPointerException
at
com.thoughtworks.xstream.io.xml.PrettyPrintWriter.writeText(PrettyPrintWriter.java:203)
at
com.thoughtworks.xstream.io.xml.PrettyPrintWriter.writeAttributeValue(PrettyPrintWriter.java:195)
at
com.thoughtworks.xstream.io.xml.PrettyPrintWriter.addAttribute(PrettyPrintWriter.java:190)
at
com.thoughtworks.xstream.io.WriterWrapper.addAttribute(WriterWrapper.java:41)
at
org.drools.runtime.help.impl.XStreamXML$InsertConverter.marshal(XStreamXML.java:119)
at
com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
at
com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
at
com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63)
at
com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeItem(AbstractCollectionConverter.java:64)
at
com.thoughtworks.xstream.converters.collections.CollectionConverter.marshal(CollectionConverter.java:55)
at
com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
at
com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
at
com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63)
at
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:115)
at
com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:129)
at
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:100)
at
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:58)
at
com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
at
com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)
at
com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63)
at
com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:98)
at
com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:38)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:837)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:826)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:801)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:789)
at olli.Main.main(Main.java:58)
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Server-5-1-1-S...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 10 months
"from" facts - working memory
by jwillans2
Hello,
My understanding was that facts evaluated using the "from" statement were
not really facts and therefore were not stored in WM, therefore in:
$event1Provider : Event1Provider()
Event1(..) from $event1Provider.evaluate()
the value of $event1Provider.evaluate() will get gc'ed (providing no other
object has a handle to it). However I read in the forum topic "Why Using
"from" Always Return A New Fact?" a post by Edson Tirelli which seemed to
indicate that fact handles are created for values returned from the "from"
statement, are these stored in WM? Do these values explicitly need to be
retracted to avoid them accumulating in WM? Or is it the case that previous
values are automatically retracted on recalls to ".evaluate" if they are
!equals?
Thanks,
James
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/from-facts-working-me...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 10 months
Isn't it possible to mock a global with e.g. Mockito or EasyMock
by dhermanns
Hi everybody,
i'm trying to mock a global using Mockito but Drools is always complaining:
Caused by: java.lang.ClassCastException:
de.lvm.verteilung.monitoring.VerteilungServicesMonitoringMBean$$EnhancerByMockitoWithCGLIB$$df2ff492
incompatible with
de.lvm.vorverteilung.monitoring.VorverteilungServicesMonitoringMBean
at
ServiceProzesse.Verteilung.Vertreterregeln.Rule_Vertretung_nach_Endnummer_0DefaultConsequenceInvoker.evaluate(Rule_Vertretung_nach_Endnummer_0DefaultConsequenceInvoker.java:22)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:917)
... 31 more
It seems that it has problems with the created subclass from Mockito. I get
the same
ClassCastException when trying this with EasyMock.
Here is my Unit-Test:
KnowledgeBase knowledgeBase = createKnowledgeBase();
StatelessKnowledgeSession ksession =
knowledgeBase.newStatelessKnowledgeSession();
VerteilungServicesMonitoringMBean monitoring =
mock(VerteilungServicesMonitoringMBean.class);
Arbeitsanstoss arbeitsanstoss = new ArbeitsanstossImpl();
arbeitsanstoss.setBenutzerId("m500516");
VerteilSperreController verteilSperreService =
mock(VerteilSperreController.class);
when(verteilSperreService.istVerteilSperreAktiv("m500516",
Ausgangskanal.LAS_BRIEFKASTEN)).thenReturn(true);
ksession.setGlobal("monitoring", monitoring);
ksession.setGlobal("verteilSperreService", verteilSperreService);
ksession.execute(arbeitsanstoss);
And my drl:
package ServiceProzesse.Verteilung.Vertreterregeln
import de.lvm.vorverteilung.services.types.SystemseitigerAnstoss;
import de.lvm.vorverteilung.services.types.Arbeitsanstoss;
import de.lvm.vorverteilung.monitoring.VorverteilungServicesMonitoringMBean;
import de.lvm.verteilung.sperre.VerteilSperreController;
import de.lvm.verteilung.sperre.Ausgangskanal;
global VorverteilungServicesMonitoringMBean monitoring;
global VerteilSperreController verteilSperreService;
rule "Vertretung nach Endnummer"
when
$a : Arbeitsanstoss()
eval( verteilSperreService.istVerteilSperreAktiv($a.getBenutzerId(),
Ausgangskanal.LAS_BRIEFKASTEN) )
then
monitoring.log("Vertretung nach Endnummer");
System.out.println("hello2");
end
Any ideas?
Thanks in advance,
Dirk
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Isn-t-it-possible-to-...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 10 months
On demand events
by James Willans
Hello,
I'm a new user of Drools and have experimented with the basics. I am
interested in processing events and have had success when defining rules
of the type:
rule "example"
when
Event1(..) from entry-point Event1Store
Event2(..) from entry-point Event2Store
then
System.out.println("Fired!");
end
Where events of type Event1 and Event2 are continually injected into
entry-points within the working memory.
The events I have in mind are formed from data that sit in data stores
that are expensive to access and I would like to explore strategies for
minimising access to these. In the above example, I assume that if
Drools does not match the pattern Event1(..) then it will not try and
match the pattern Event2(..), in which case it would not be necessary to
construct facts/events which may match the Event2(..) pattern.
I understand that the 'from' statement can be used to evaluate facts
that are not in working memory, on this basis I have defined proxy
objects that are inserted into working memory which are then evaluated
for the actual data from the database on demand:
1 rule "example"
2 when
3 $event1Provider : Event1Provider()
4 Event1(..) from $event1Provider.evaluate()
5 $event2Provider : Event2Provider()
6 Event2(..) from $event2Provider.evaluate()
7 then
8 System.out.println("Fired!");
9 end
On the basis that if line 4 fails to match, then line 5 and 6 will not
get evaluated therefore avoiding accessing the database describing the
Event2 fact/event. I think that this works - but only once, since it
looks like the system is treating these as facts, that don't expire,
rather than events. Is it the case that the 'from' statement cannot be
used for events in this way? If not, what approach should be taken to
addressing the problem I am trying to solve?
Any direction would be much appreciated.
James
13 years, 10 months
fact problem
by saurabh maheshwari
Hi,
When i am taking a precompiled class in my rule engine is able to
process any no of objects in very quick session.
but when i am taking the facttype(class created from drl) inspite of
precompiled class then it is taking much time as no of objects increased in
the memory
i have 6 rules in my drl
1- in case of factType it is taking 1 sec for each 50 when 30000 objects
in memory(increases as no of objects increased in memory )
2- but in case of precompiled class it is taking 1 sec for each 1000
.without much effect of the no of objects (i have taken 1024mb heap size)
I am not able to find the cause of this problem .
Please inform if you have any idea about this.
Regards
Saurabh
13 years, 10 months
drools-guvnor\modules
by Michael Anstis
Hi,
We're in the process of rationalising Guvnors code-base including the
removal of GWTEXT and came across use of GWTEXT's Grid in
drools-guvnor\modules\properties.
Anybody care to claim ownership? Otherwise we're probably delete it (if not
all drools-guvnor\modules) s we don't want to refactor stuff no longer
needed.
X-posted in case knowledge of the module has moved to the user list only.
With kind regards,
Mike
13 years, 10 months
Decision Trees
by Petr Chelčický
I have quite a big decision tree (eligibility check) that I'd like to implement in Drools. To convert it to rules, I'd have to find every path from start leading to a leaf and check all the constraints. I feel like it'd be very messy. Is there a faster way? How about Drools Flow and decision trees? I tried to explain my use case here: http://stackoverflow.com/questions/4887456/decision-trees-and-rule-engine... where they recommend using Drools Expert. Is this the way to take?
John
13 years, 10 months