Nothing Special   »   [go: up one dir, main page]

Simple Pattern

The pattern is a state machine implementation that detects event occurrences from events arrived via one or more event streams over time.

This application demonstrates a simple pattern use case of detecting high-temperature event occurrence of a continuous event stream.

define stream TemperatureStream(roomNo int, temp double);

@sink(type = 'log')
define Stream HighTempAlertStream(roomNo int,
    initialTemp double, finalTemp double);

@info(name='temperature-increase-identifier')
from every( e1 = TemperatureStream ) ->
    e2 = TemperatureStream[ e1.roomNo == roomNo
        and (e1.temp + 5) <= temp ]
    within 10 min
select e1.roomNo, e1.temp as initialTemp, e2.temp as finalTemp
insert into HighTempAlertStream;
define stream TemperatureStream(roomNo int, temp double);

Defines TemperatureStream having information of room temperature such as roomNo and temp.

@sink(type = 'log')
define Stream HighTempAlertStream(roomNo int,
    initialTemp double, finalTemp double);

Defines HighTempAlertStream which contains the alerts for high temperature.

@info(name='temperature-increase-identifier')
from every( e1 = TemperatureStream ) ->
    e2 = TemperatureStream[ e1.roomNo == roomNo
        and (e1.temp + 5) <= temp ]
    within 10 min

Identify if the temperature of a room increases by 5 degrees within 10 min.

select e1.roomNo, e1.temp as initialTemp, e2.temp as finalTemp
insert into HighTempAlertStream;

This application sends an alert if the temperature of a room increases by 5 degrees within 10 min.

Input

Below events are sent to TemperatureStream within 10 minutes,

[2, 35]

[2, 37]

[2, 40]

Output

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

[2, 35.0, 40.0]

Top