OK, this is a little more to the point.<br><br>What you should review critically is the use of paywayManager (in "Pay complete") and emTicket (in the other rules). Apparently, these objects are not WM items - are they globals? Globals must not be used in conditions the way they are apparently used here.<br>
<br>It's impossible to tell from these snippets why the last rule never fires - there's that ElectromechanicalEvent...<br><br>-W<br><br><br><br><div class="gmail_quote">2011/7/7 Aitor González Serrano <span dir="ltr"><<a href="mailto:jmolly@gmail.com">jmolly@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Ok.<br>That's my code:<br><br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
/************************************** Payment Complete **************************************/<br>
rule "Pay complete"<br> salience 10<br> no-loop true<br>when<br> event : PaywayEvent(id == PaywayEventType.OPERATION_IN)<br> paymentData : PaymentData(credit >= saleImport) <br> transaction : CurrentTransaction (state == TransactionState.CHARGE_PRODUCT) <br>
eval (!paywayManager.isStopped())<br>then<br> retract(event);<br> <br> updateDebt(languageManager, hmiManager,paymentData.getDebt());<br> <a href="http://log.info" target="_blank">log.info</a>("Machine.drl","Charge complete. Stopping devices!. Debt is "+paymentData.getDebt());<br>
for(Enumeration<String> e = paywayManager.getPaywayNames(); e.hasMoreElements(); ){<br> String payway = e.nextElement();<br> if(paywayManager.getPayway(payway).isLoaded()<br> && !paywayManager.getPayway(payway).getPaywayApi().isStopped()) {<br>
PaywayEvent paywayEvent = new PaywayEvent(PaywayEventType.STOP_PAYMENT_DEVICES);<br> paywayEvent.setDevice(payway); <br> insert(paywayEvent);<br> }<br> } <br>end<br><br>
<br>
This is the stop rule of the device<br><br>/******************************************STOP PAYMENT DEVICES ****************************/<br>rule "Stop EmTicket Device"<br> salience 10<br> no-loop true<br>
when<br>
event : PaywayEvent(id == PaywayEventType.STOP_PAYMENT_DEVICES && device == "discountticket")<br> transaction : CurrentTransaction (state == TransactionState.CHARGE_PRODUCT) <br> eval (!emTicket.isStopped())<br>
then<br> retract(event);<br> if (emTicket.stop()){<br> electromechanical.disableTakeTicket();<br> electromechanical.blinkingLedOff();<br> emTicket.setState(EmTicketState.OUT_OF_SERVICE);<br> }<br>
else{<br> <a href="http://log.info" target="_blank">log.info</a>("EmTicket","EmTicket cannot be stoped!");<br> }<br> <br> insert (new PaywayEvent(PaywayEventType.OPERATION_IN));<br>
end<br></blockquote>
<br><br>So, there are bidirectional calls between STOP_PAYMENT_DEVICES and OPERATION_IN (because emTicket can't be stopped, so an event should be fired soon)<br><br>While this 2 rules are firing the other, the hardware sends an DISCOUNT_TICKET_ACCEPTED, that updates the debt, and the state of EmTicket, so the in next STOP_PAYMENT_DEVICES emTicket will be stopped.<br>
<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">rule "Discount Ticket discarded when accepted"<br> salience 1000<br> no-loop true<br>
when<br> event : ElectromechanicalEvent (eventType == ElectromechanicalEventType.CONSUM_EVENT<br> && description == "articleDiscarded")<br> transaction : CurrentTransaction(state == TransactionState.CHARGE_PRODUCT)<br>
eval (emTicket.getState() == EmTicketState.ARTICLE_TAKEN)<br> paymentData : PaymentData()<br>then <br> lot of code here..<br>end<br></blockquote><br><br>The problem I'm facing is that rule "Discount Ticket discarded when accepted" is never fired (and has a lot more of salience than the other two)! The other two rules are in a constant bucle. The event of the discarded is sent via enginer.insertEvent() && fireAllRules. Maybe insert command in drl files has more priority than facts invoked from java classes?<br>
Thanks in advance!<div><div></div><div class="h5"><br><br><br><br><br><br><br><br><br><br><br><div class="gmail_quote">2011/7/7 Wolfgang Laun <span dir="ltr"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Sorry, but I become more confused with every re-read. I think the original code is required.<br><br>I think that this is nothing but a FSM. Generally, this sort of problem should be doable without resorting to salience (except for one or two low priority ones acting as the "safety net").<br>
<font color="#888888">
<br>-W</font><div><div></div><div><br><br><br><br><div class="gmail_quote">On 7 July 2011 16:35, jmolly <span dir="ltr"><<a href="mailto:jmolly@gmail.com" target="_blank">jmolly@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello.<br>
I'm facing some problems in drools with salience. (maybe I don't understand<br>
how it works)<br>
<br>
We have a rule that check if an import has been satisfied by the client. But<br>
we have a lot of pay methods so, when the import has been satisfied, we have<br>
to stop all the payment devices. If a payment device is in use, we can't<br>
stop it, so we send stop commands until device can stop.<br>
The problem is that if a device is making a pay process, and consumes an<br>
event, that event is never fired.<br>
<br>
Maybe I can explain better with code:<br>
<br>
<br>
rule "Pay device stop"<br>
Salience 10<br>
Try to stop the device and sends an OPERATION_IN event if can't stop<br>
(because there is a ticket inside)<br>
<br>
Machine rule<br>
rule "Operation in received witch devices not stopped"<br>
salience 10<br>
Sent stop events to all devices<br>
<br>
Machine rule<br>
rule "Operation in received with devices stopped"<br>
salience 10<br>
All ok. Finish operation<br>
<br>
<br>
rule "Ticket data read"<br>
salience 1000<br>
updates the debt for the user and sends an OPERATION_IN<br>
<br>
The pay hardware, when is reading a ticket, sent a TICKET_DATA_READ<br>
this rule has salience 100 and should be fired inmediatly but Drools is<br>
entering all time in a bucle from Operation in received and Pay stop device.<br>
<br>
<br>
Can someone give a clue about what are we doing wrong?<br>
<br>
<br>
Sorry for the english. I can post the original code if needed.<br>
Thanks in advance<br>
<font color="#888888"><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Problem-with-salience-tp3148382p3148382.html" target="_blank">http://drools.46999.n3.nabble.com/Problem-with-salience-tp3148382p3148382.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>
</div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>
</div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>