//类似名称空间的作用,目前不用考虑
package rules;
dialect "mvel"
//此处引入对应实例
import com.drools.test.entity.*
rule "Is of valid age"
when
$a:Applicant(age < 18);
then
$a.setValid(false);
end
rule "When there is a fire turn on the sprinkle"
salience 1
when
Fire($room : room)
$sprinkler:Sprinkler($room == room, on == false);
then
modify($sprinkler){setOn(true)}
System.out.println("room 【" + $room.getName() + "】 is firing!!!");
System.out.println("Turn on the sprinkler from room 【" + $room.getName() + "】.");
end
rule "When the fire is gone trun off the srinkle"
when
$room:Room();
$sprinkler:Sprinkler($room == room, on == true);
not Fire($room == room);
then
modify($sprinkler){setOn(false)}
System.out.println("Room 【" + $room.getName() + "】 fire is gone.");
System.out.println("Turn off the sprinkler from room 【" + $room.getName() + "】.");
end
rule "Raise the alarm when have one or more fires"
//先报警,在开喷头
salience 2
when
exists Fire();
then
insert(new Alarm())
System.out.println("Raise the alarm.");
end
rule "Cancel the alarm when all the fires have gone"
when
not Fire();
$alarm:Alarm()
then
delete($alarm);
System.out.println("Cancel the alarm.");
end
rule "Status output when things are ok"
when
not Alarm();
not Sprinkler(on == true);
then
System.out.println("Everything is ok.");
end