This recipe will show you one of the main features introduced by CDI 2.0: Ordered Observers. Now, you can turn the observers job into something predictable:
- First, let's make an event to be observed:
public class MyEvent { private final String value; public MyEvent(String value){ this.value = value; } public String getValue(){ return value; }}
- Now, we build our observers and the server that will fire them:
public class OrderedObserver { public static void main(String[] args){ try(SeContainer container = SeContainerInitializer.newInstance().initialize()){ container .getBeanManager() .fireEvent(new MyEvent("event: " + System.currentTimeMillis())); } } public void thisEventBefore( @Observes @Priority(Interceptor.Priority ...