We will declare 2 rules:

  1. First handling the Fire event
  2. Second handling the CeaseFire event

when there is a fire then turn on the sprinkler and alarm:

package com.fire;

rule "when there is a fire turn on the sprinkler and alarm"
when
    Fire($room: room) from entry-point "fire-sensors"
then
    insertLogical(new Alarm());
    insertLogical(new ActivateSprinkler($room));
end

Important:

  1. Since Fire is an input, it must come from entry point. The entry point name can be anything. When we will define the corresponding input, we will connect it using that name (it will appear in the combo box).
  2. We use insertLogical to insert facts:
    • later we will connect Alarm and ActivateSprinkler types with corresponding outputs. Every time a new instance will be inserted, the system will send a message to the output
    • we use insertLogical to remove Alarm and ActivateSprinkler instances automatically when Fire object is deleted from memory. See logical insertion of facts.

when there is a fire and fire brigade reports it’s stopped then put the system back to normal state:

package com.fire;

rule "cease fire in a room"
when
    $fire: Fire($room : room) from entry-point "fire-sensors"
    CeaseFire(room == $room, this after $fire) from entry-point "fire-fighters"
then
    retract($fire)
end

Important:

  1. we use temporal operator after to designate that CeaseFire event must occur after Fire event
  2. when we retract Fire instance, deletion of Alarm and ActivateSprinkler instances is automatic because of insertLogical

When complete, you should have something like this:

BinaryFile


Next: Specifying Inputs