Logical Sequence

The sequence can repetitively match event sequences and use logical event ordering (using and, or, and not).

Refer the Siddhi query guide for more information.

define stream TempSensorStream(deviceID long,
    isActive bool);

define stream HumidSensorStream(deviceID long,
    isActive bool);

define stream RegulatorStream(deviceID long, isOn bool);

@sink(type='log')
define stream StateNotificationStream (deviceID long,
    tempSensorActive bool, humidSensorActive bool);

from every e1=RegulatorStream[isOn == true],
    e2=TempSensorStream and e3=HumidSensorStream
select e1.deviceID, e2.isActive as tempSensorActive,
    e3.isActive as humidSensorActive
insert into StateNotificationStream;
define stream TempSensorStream(deviceID long,
    isActive bool);

Defines TempSensorStream having information of temperature sensor device.

define stream HumidSensorStream(deviceID long,
    isActive bool);

Defines HumidSensorStream having information of humidity sensor device.

define stream RegulatorStream(deviceID long, isOn bool);

Defines RegulatorStream which contains the events from regulator with attributes deviceID and isOn.

@sink(type='log')
define stream StateNotificationStream (deviceID long,
    tempSensorActive bool, humidSensorActive bool);

Defines StateNotificationStream which tells the state of temperature and humidity sensors.

from every e1=RegulatorStream[isOn == true],
    e2=TempSensorStream and e3=HumidSensorStream
select e1.deviceID, e2.isActive as tempSensorActive,
    e3.isActive as humidSensorActive
insert into StateNotificationStream;

Identifies a regulator activation event immediately followed by both temperature sensor and humidity sensor activation events in either order.

This application can be used identify a regulator activation event immediately followed by both temperature sensor and humidity sensor activation events in either order.

Input

  • First, below event is sent to RegulatorStream,

    [2134, true]

  • Then, below event is sent to HumidSensorStream,

    [124, true]

  • Then, below event is sent to TempSensorStream,

    [242, false]

Output

After processing the above input events, the event arriving at StateNotificationStream will be as follows:

[2134, false, true]

Top