How to do it...

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:

  1. 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;    }}
  1. 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 ...

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.