why modify

Upload: carlcols

Post on 22-Feb-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/24/2019 Why Modify

    1/5

    Copyright 2011 Red Hat, Inc. All Rights Reserved.4

    Why Modify?

    To Illustrate the purpose of modify lets look a small example

    In this example I have a simple model

    A single fact in my model called Car

    My Car fact has two fields: make (a Text field) and speed (an int)

  • 7/24/2019 Why Modify

    2/5

    Copyright 2011 Red Hat, Inc. All Rights Reserved.5

    Why Modify?

    I now add one rule to my system called accelerate car

    Notice that I have the no-loop attribute turned off

    If I were to run a test scenario where I place one Car object intoworking memory, what would you expect to happen?

  • 7/24/2019 Why Modify

    3/5

    Copyright 2011 Red Hat, Inc. All Rights Reserved.6

    Why Modify?

    Since the no-loop attribute is off, you might expect this to result in aninfinite loop. However, as you can see below, the rule is only activatedone time.

    Why? The rule engine is never informed that anything has changed in

    working memory.

  • 7/24/2019 Why Modify

    4/5

    Copyright 2011 Red Hat, Inc. All Rights Reserved.7

    Why Modify?

    If I change the rule by adding update or modify, then I also need to setthe no-loop attribute to true. Why?

    Every update or modify command will inform the rule engine to do a re-evaluation of the fact since something has changed on fact.

    So in this case, no-loop must be set to prevent an infinite loop.

  • 7/24/2019 Why Modify

    5/5

    Copyright 2011 Red Hat, Inc. All Rights Reserved.8

    Why Modify?

    To be clear, no-loop is not the only way to prevent an infinite loop. Iwould suggest that the use of no-loop should be a last resort.

    The following rule is one example of how to stop the infinite loop withoutusing the no-loop attribute.