rule "rule1" salience 1 when $message: Message(status == Message.HELLO) then System.out.println("Status is 'Hello', set 'Hello World!' to message"); $message.setMessage("Hello World!"); System.out.println("Message: " + $message.getMessage()); end
rule "rule1" salience 1 when $message: Message(status == Message.HELLO) then System.out.println("Status is 'Hello', set 'Hello World!' to message"); $message.setMessage("Hello World!"); System.out.println("Message: " + $message.getMessage()); System.out.println("Then set 'Goodbye' to status"); $message.setStatus(Message.GOODBYE); update($message); end
rule "rule2" salience 1 when $message: Message(status == Message.GOODBYE) then System.out.println("Status is 'Goodbye', set 'Goodbye World!' to message"); $message.setMessage("Goodbye World!"); System.out.println("Message: " + $message.getMessage()); end
再次运行,输出:
1 2 3 4 5
Status is 'Hello', set 'Hello World!' to message Message: Hello World! Then set 'Goodbye' to status Status is 'Goodbye', set 'Goodbye World!' to message Message: Goodbye World!
rule "rule1" salience 1 when $message: Message(status == Message.HELLO) then System.out.println("Status is 'Hello', set 'Hello World!' to message"); $message.setMessage("Hello World!"); System.out.println("Message: " + $message.getMessage()); System.out.println("Then set 'Goodbye' to status"); $message.setStatus(Message.GOODBYE); update($message); end
rule "rule2" salience 1 when $message: Message(status == Message.GOODBYE) then System.out.println("Status is 'Goodbye', set 'Goodbye World!' to message"); $message.setMessage("Goodbye World!"); System.out.println("Message: " + $message.getMessage()); System.out.println("Then set 'Hello' to status"); $message.setStatus(Message.HELLO); update($message); end<
输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Status is 'Hello', set 'Hello World!' to message Message: Hello World! Then set 'Goodbye' to status Status is 'Goodbye', set 'Goodbye World!' to message Message: Goodbye World! Then set 'Hello' to status Status is 'Hello', set 'Hello World!' to message Message: Hello World! Then set 'Goodbye' to status Status is 'Goodbye', set 'Goodbye World!' to message Message: Goodbye World! Then set 'Hello' to status Status is 'Hello', set 'Hello World!' to message Message: Hello World! ......
rule "rule1" salience 1 no-loop true when $message: Message(status == Message.HELLO) then System.out.println("Status is 'Hello', set 'Hello World!' to message"); $message.setMessage("Hello World!"); System.out.println("Message: " + $message.getMessage());
System.out.println("Then create a new Message and set 'Hello' to status"); Message message2 = new Message(); message2.setStatus(Message.HELLO); insert(message2); end
当把no-loop true一句注释掉时,输出结果为:
1 2 3 4 5 6 7 8
Status is 'Hello', set 'Hello World!' to message Message: Hello World! Then create a new Message and set 'Hello' to status Status is 'Hello', set 'Hello World!' to message Message: Hello World! Then create a new Message and set 'Hello' to status Status is 'Hello', set 'Hello World!' to message ......
造成了循环,将注释解开后,输出结果为:
1 2 3
Status is 'Hello', set 'Hello World!' to message Message: Hello World! Then create a new Message and set 'Hello' to status
rule "rule1" salience 1 no-loop true lock-on-active true when $message: Message(status == Message.HELLO) then System.out.println("Status is 'Hello', set 'Hello World!' to message"); $message.setMessage("Hello World!"); System.out.println("Message: " + $message.getMessage()); System.out.println("Then set 'Goodbye' to status"); $message.setStatus(Message.GOODBYE); update($message); end
rule "rule2" salience 1 when $message: Message(status == Message.GOODBYE) then System.out.println("Status is 'Goodbye', set 'Goodbye World!' to message"); $message.setMessage("Goodbye World!"); System.out.println("Message: " + $message.getMessage()); System.out.println("Then set 'Hello' to status"); $message.setStatus(Message.HELLO); update($message); end
当把lock-on-active true一句注释掉时,输出结果为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Status is 'Hello', set 'Hello World!' to message Message: Hello World! Then set 'Goodbye' to status Status is 'Goodbye', set 'Goodbye World!' to message Message: Goodbye World! Then set 'Hello' to status Status is 'Hello', set 'Hello World!' to message Message: Hello World! Then set 'Goodbye' to status Status is 'Goodbye', set 'Goodbye World!' to message Message: Goodbye World! Then set 'Hello' to status Status is 'Hello', set 'Hello World!' to message Message: Hello World! ......
Status is 'Hello', set 'Hello World!' to message Message: Hello World! Then set 'Goodbye' to status Status is 'Goodbye', set 'Goodbye World!' to message Message: Goodbye World! Then set 'Hello' to status