Day 02 — Qualifiers, Producers, Interceptors & Decoupled Events¶
Daily Time Investment: 2.5 hours | Week: 1 | Phase: 3
Daily Schedule¶
| Segment | Duration | Activity |
|---|---|---|
| Core Theory | 45 min | Custom @Qualifier, @Produces/@Disposes, @AroundInvoke, @Observes/@ObservesAsync |
| Book Reading | 30 min | EE8 AppDev Ch5 (Qualifiers & Events) + EE Patterns Ch5 (Interceptors) |
| Hands-On Lab | 75 min | @Monitored interceptor with ThreadMXBean; decoupled audit event bus |
Files in This Day¶
-
EE8 AppDev Ch5 — Qualifiers & CDI Events
Qualifiers,
@Produces,@Disposes, synchronous vs async events, event ordering with@Priority.Chapter 5 scopes & injection are in Day 01 — this page focuses on the advanced wiring section.
-
EE Patterns Ch5 — Infrastructural Patterns
Adam Bien's patterns: Service Starter (
@Startup @Singleton), Singleton caching, Thread Tracker (@AroundInvoke), Context Holder (TransactionSynchronizationRegistry), Bean Locator, Payload Extractor, Dependency Injection Extender. -
Lab Guide — CDI Advanced Wiring
Build enum-backed qualifiers,
@Produces/@Disposesresource factories,@AroundInvokeperformance interceptors, and sync+async CDI event bus using Weld SE.
Prerequisites to Continue¶
New concepts in Phase 3 not seen in Phase 1 or Phase 2
InvocationContext— CDI passes this to@AroundInvokemethods; gives access togetMethod(),getParameters(),getTarget(), and criticallyproceed()(calls the actual method)ManagementFactory.getThreadMXBean()— returnsThreadMXBeanfor per-thread CPU time; bridges Phase 2 JVM internals into Phase 3 interceptors- Record types as event payloads — Java 16+ records (
record AuditEvent(String id, Instant time) {}) are ideal CDI event payloads — immutable, value-based, no boilerplate CompletionStage— returned byevent.fireAsync()— the sameCompletionStage/CompletableFuturefrom Phase 1 concurrency@InterceptorBindingvs@Qualifier— both are meta-annotations but serve different purposes: qualifiers disambiguate injection, interceptor bindings attach cross-cutting behavior