Testing uniqueness
The events:
event OrderKey{...}
event NewOrder {
OrderKey key; //You can use anything for key as long as it is unique
...
}
event ValidNewOrder {
NewOrder order;
}
The monitors:
monitor OrderFilter {
dictionary < OrderKey, NewOrder > orders;
action onload() {
on all NewOrder() as order validateOrder(order);
}
action validateOrder(NewOrder order){
if orders.hasKey(order.key) {
print "Duplicate order!"
print "Original: " + orders[order.key].ToString();
print "Incoming: " + order.ToString();
}
else {
orders.add(order.key,order);
route validNewOrder(order);
}
}
}
monitor OrderProcessor {
...
action onload() {
on all ValidNewOrder() as valid spawn processOrder(valid.order);
}
action processOrder( NewOrder order ) {
...
}
}