Re-alerting the Rule Engine to changes in these objects requires them to be facts.

I don't see where they are changed; if so, it must be done using modify/update.

-W

2011/7/7 Aitor González Serrano <jmolly@gmail.com>
You are right. Both paywayManager and emTicket are globals. Maybe I'm not understanding the use of globals? It would solve the problem converting that globals into objects in the working memory?

Thanks


2011/7/7 Wolfgang Laun <wolfgang.laun@gmail.com>
OK, this is a little more to the point.

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.

It's impossible to tell from these snippets why the last rule never fires - there's that  ElectromechanicalEvent...

-W




2011/7/7 Aitor González Serrano <jmolly@gmail.com>
Ok.
That's my code:

/************************************** Payment Complete **************************************/
rule "Pay complete"
    salience 10
    no-loop true
when
    event : PaywayEvent(id == PaywayEventType.OPERATION_IN)
    paymentData : PaymentData(credit >= saleImport)   
    transaction : CurrentTransaction (state == TransactionState.CHARGE_PRODUCT)   
    eval (!paywayManager.isStopped())
then
    retract(event);
   
    updateDebt(languageManager, hmiManager,paymentData.getDebt());
    log.info("Machine.drl","Charge complete. Stopping devices!. Debt is "+paymentData.getDebt());
    for(Enumeration<String> e = paywayManager.getPaywayNames(); e.hasMoreElements(); ){
        String payway = e.nextElement();
        if(paywayManager.getPayway(payway).isLoaded()
            && !paywayManager.getPayway(payway).getPaywayApi().isStopped()) {
            PaywayEvent paywayEvent = new PaywayEvent(PaywayEventType.STOP_PAYMENT_DEVICES);
            paywayEvent.setDevice(payway);
            insert(paywayEvent);
        }
    }       
end


This is the stop rule of the device

/******************************************STOP PAYMENT DEVICES ****************************/
rule "Stop EmTicket Device"
    salience 10
    no-loop true
when
    event : PaywayEvent(id == PaywayEventType.STOP_PAYMENT_DEVICES && device == "discountticket")
    transaction : CurrentTransaction (state == TransactionState.CHARGE_PRODUCT)   
    eval (!emTicket.isStopped())
then
    retract(event);
    if (emTicket.stop()){
        electromechanical.disableTakeTicket();
        electromechanical.blinkingLedOff();
        emTicket.setState(EmTicketState.OUT_OF_SERVICE);
    }
    else{
        log.info("EmTicket","EmTicket cannot be stoped!");
    }
   
    insert (new PaywayEvent(PaywayEventType.OPERATION_IN));
end


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)

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.

rule "Discount Ticket discarded when accepted"
    salience 1000
    no-loop true
when
    event : ElectromechanicalEvent (eventType == ElectromechanicalEventType.CONSUM_EVENT
    && description == "articleDiscarded")
    transaction : CurrentTransaction(state == TransactionState.CHARGE_PRODUCT)
    eval (emTicket.getState() == EmTicketState.ARTICLE_TAKEN)
    paymentData : PaymentData()
then   
  lot of code here..
end


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?
 Thanks in advance!











2011/7/7 Wolfgang Laun <wolfgang.laun@gmail.com>
Sorry, but I become more confused with every re-read. I think the original code is required.

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").

-W




On 7 July 2011 16:35, jmolly <jmolly@gmail.com> wrote:
Hello.
I'm facing some problems in drools with salience. (maybe I don't understand
how it works)

We have a rule that check if an import has been satisfied by the client. But
we have a lot of pay methods so, when the import has been satisfied, we have
to stop all the payment devices. If a payment device is in use, we can't
stop it, so we send stop commands until device can stop.
The problem is that if a device is making a pay process, and consumes an
event, that event is never fired.

Maybe I can explain better with code:


rule "Pay device stop"
Salience 10
Try to stop the device and sends an OPERATION_IN event if can't stop
(because there is a ticket inside)

Machine rule
rule "Operation in received witch devices not stopped"
salience 10
  Sent stop events to all devices

Machine rule
rule "Operation in received with devices stopped"
salience 10
   All ok. Finish operation


rule "Ticket data read"
salience 1000
 updates the debt for the user and sends an OPERATION_IN

The pay hardware, when is reading a ticket, sent a TICKET_DATA_READ
this rule has salience 100 and should be fired inmediatly but Drools is
entering all time in a bucle from Operation in received and Pay stop device.


Can someone give a clue about what are we doing wrong?


Sorry for the english. I can post the original code if needed.
Thanks in advance










--
View this message in context: http://drools.46999.n3.nabble.com/Problem-with-salience-tp3148382p3148382.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users