I was sitting in a session next to Adrian Colyer, and he showed me what he had literally just hacked up.
It is a nice proof of concept showing a DSL for event driven code.
It allows you to simply specify a publisher:
class Producer {
public Producer() {}
@RaisesEvent("price-update") private int price;
@RaisesEvent("calculation-complete")
public int calculate(int x, int y) {
return x*y;
}
public void setPrice(int price) {
this.price = price;
}
}
and a subscriber:
@EventSubscriber static class Recipient {
// exposed public fields for testing
public int calculationResult = 0;
public int price = 0;
@OnEvent("calculation-complete")
void onCalculationCompletion(MethodBasedEvent event) {
System.out.println("calculation-complete, result = "
+ event.getResult());
calculationResult = (Integer)event.getResult();
}
@OnEvent("price-update")
void onPriceUpdate(FieldBasedEvent event){
System.out.println("price-update, new price = "
+ event.getValue());
price = (Integer) event.getValue();
}
}
I hope that this could be firmed up, and maybe at some point make it into the ajlib project! :)

