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 ) {
...
}
}