0 Replies Latest reply on Sep 9, 2015 12:39 PM by ritesh.ganatra

    make rule fire every 30 seconds when condition doesnt get met

    ritesh.ganatra

      I am trying to do something like this:

      train Fact needs to be updated if GPS events arrive, to update its GPS Location. Now, if there are no GPS events for 40 seconds in a row, the confidence level of train drops by 5 (initial 100)

      Code:

      rule "ConfidenceLevel_sliding" dialect "mvel" 

      when

      $GPSEvent : GPSEvent($eventTrainID:trainID, $eventGPSLocation:GPSLocation) over window:time(40s)

      $train : Train(trainID==$eventTrainID,$confidenceLevel:confidenceLevel  )

      not(GPSEvent(this != $GPSEvent,trainID==$eventTrainID))

      then

      $train.confidenceLevel=$confidenceLevel-5

      System.out.println( "updated train information for trainID:" +$train.trainID +"\nnew Confidence Level:"+$train.confidenceLevel ); 

      end

      now, the above is working fine when i send 2 GPSEvents within required time (40 Secs), and the rule fires if i fire second GPS event after 40 seconds

      Code:

      kSession.insert(train1);

      kSession.insert(GPSEvent1);

      clock.advanceTime(10, TimeUnit.SECONDS);

      kSession.insert(GPSEvent2);

      But then it doesnt continue firing every 40 seconds. I want the rule to decrease the confidence level every 40 seconds of not receiving a GPS Event for that train.

      Examples (what we want to achieve):

      1) I insert a train with confidence level 100, and never insert a GPS Event for the train, then every 40 seconds the confidence level should go down by 5

      2) I insert a train with confidence level 100, insert a GPS Event within 40 seconds, then the confidence level remains 100.

       

      Please help here.

      Thanks