Async Events
@ViewScoped
@Named("eventBean")
public class EventBean implements Serializable {
private static final Logger LOG = Logger.getLogger(EventBean.class.getName());
@Inject
Event<Message> event;
private String message;
private String notification;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getNotification() {
return notification;
}
public void setNotification(String notification) {
this.notification = notification;
}
public void fireEvent() {
LOG.log(Level.INFO, "fire event async...");
event.fireAsync(new Message(this.message))
.thenAccept((m) -> this.setNotification(m+ " was sent"));
}
public void fireEventOptions() {
LOG.log(Level.INFO, "fire event async...");
event.fireAsync(
new Message(this.message),
NotificationOptions.builder()
.set("weld.async.notification.timeout", 1000)
.build()
);
}
}Last updated