Prioritized Event Observers with CDI 2.0 (EDR1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyEventPayload { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PrioritizedObservers { | |
@Inject | |
private Event<MyEventPayload> event; | |
public void trigger(){ | |
event.fire(new MyEventPayload()); | |
} | |
public void observeBeforeOtherObservers(@Observes @Priority(Interceptor.Priority.APPLICATION - 1) MyEventPayload payload){ | |
System.out.println("Notified before all other observers"); | |
} | |
public void observeAfterOtherObservers(@Observes @Priority(Interceptor.Priority.APPLICATION + 501) MyEventPayload payload){ | |
System.out.println("Notified after all other observers"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment