Skip to content

Instantly share code, notes, and snippets.

@evacchi
Last active January 24, 2020 09:35
Show Gist options
  • Save evacchi/1e99a57dca6bc64222dcf9f957f91045 to your computer and use it in GitHub Desktop.
Save evacchi/1e99a57dca6bc64222dcf9f957f91045 to your computer and use it in GitHub Desktop.
Drools: Declared Types (Blog)
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
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
}
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
package com.acme;
declare AlertingService extends RuleUnitData
events: DataStream<Event>
alerts: DataStream<Alert>
end
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