January 2018
Intermediate to advanced
350 pages
9h 7m
English
CDI 2.0 introduces the notion of asynchronous events. It is a manner of asynchronously firing an event for the caller. Here is a sample usage:
public class AsyncSender { private static final Logger log = Logger.getLogger(AsyncSender.class.getName()); @Inject private Event<MyEvent> sender; public void send(final MyEvent event) { final CompletionStage<MyEvent> cs = sender.fireAsync(event); cs.thenRun(() -> { // some post processing once all observers got notified }); }}
This code snippet sends an asynchronous event, thanks to fireAsync. The interesting part of this API is that it returns CompletionStage, which enables you to chain some logic after the event has notified all the asynchronous observers.
Read now
Unlock full access