Last active
January 24, 2020 09:35
-
-
Save evacchi/1e99a57dca6bc64222dcf9f957f91045 to your computer and use it in GitHub Desktop.
Drools: Declared Types (Blog)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.acme; | |
unit AlertingService; | |
rule IncomingEvent when | |
// matches when a temperature higher than 30 °C is registered (OOPath syntax) | |
$e : /events [ type == "temperature", value >= 30 ] // Temperature is an Event subclass | |
then | |
System.out.println("incoming event: "+ $e.getMessage()); | |
alerts.append( new Alert( "warning", $e ) ); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.acme; | |
public class AlertingService implements RuleUnitData { | |
private final DataStream<Event> events = DataSource.createStream(); | |
private final DataStream<Alert> alerts = DataSource.createStream(); | |
// getters and setters | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.acme; | |
declare Event | |
type: String | |
value: int | |
end | |
declare Alert | |
severity: String | |
message: String | |
end | |
declare AlertingService extends RuleUnitData | |
events: DataStream<Event> | |
alerts: DataStream<Alert> | |
end | |
unit AlertingService; | |
rule IncomingEvent when | |
// matches when a temperature higher than 30 °C is registered (OOPath syntax) | |
$e : /events [ type == "temperature", value >= 30 ] // Temperature is an Event subclass | |
then | |
System.out.println("incoming event: "+ $e.getMessage()); | |
alerts.append( new Alert( "warning", $e ) ); | |
end | |
query Warnings | |
alerts: /alerts [ severity == "warning" ] | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.acme; | |
declare AlertingService extends RuleUnitData | |
events: DataStream<Event> | |
alerts: DataStream<Alert> | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.acme; | |
declare Event | |
type: String | |
value: int | |
end | |
declare Alert | |
severity: String | |
message: String | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment