File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
CDI-2-0/src/main/java/com/readlearncode/priority Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 22
33import com .readlearncode .async .AuditEvent ;
44
5+ import javax .annotation .Priority ;
56import javax .enterprise .context .ApplicationScoped ;
67import javax .enterprise .event .ObservesAsync ;
78
1516public class AuditEventReciever4 {
1617
1718 // Order: Doesn't fire
18- public void receive (@ ObservesAsync AuditEvent auditEvent ) {
19+ public void receive (@ ObservesAsync @ Priority ( 1 ) AuditEvent auditEvent ) {
1920 System .out .println ("Priority: no (ObservesAsync) " +
2021 auditEvent .getPriority () + " " + auditEvent .getMessage ());
2122 }
Original file line number Diff line number Diff line change 1+ package com .readlearncode .priority ;
2+
3+ /**
4+ * Source code github.com/readlearncode
5+ *
6+ * @author Alex Theedom www.readlearncode.com
7+ * @version 1.0
8+ */
9+ public class ObserverEvent {
10+
11+ /*
12+ The CDI 2.0 API introduces the @Priority annotation that allows
13+ the order of observer methods.
14+
15+ When the fire method is called in what order are the observer
16+ methods executed.
17+ */
18+
19+
20+ // // Order: 2nd
21+ // public void observe1(@Observes @Priority(1000) AuditEvent auditEvent) {}
22+ //
23+ // // Order: 1st
24+ // public void observe2(@Observes @Priority(100) AuditEvent auditEvent) {}
25+ //
26+ // // Order: 3rd
27+ // public void observe3(@Observes @Priority(APPLICATION + 500) AuditEvent auditEvent) {}
28+ //
29+ // // Order: Doesn't fire
30+ // public void observe4(@ObservesAsync @Priority(1) AuditEvent auditEvent) {}
31+ //
32+ // // Order: 4th
33+ // public void observe5(@Observes @Priority(5000) AuditEvent auditEvent) {}
34+ }
You can’t perform that action at this time.
0 commit comments