Source:
<code>protected <T, U extends T> CompletionStage<U> notifyAsyncObservers(List<ObserverMethod<? super T>> observers, U event, EventMetadata metadata, Executor executor, NotificationOptions options) { if (executor == null) { executor = asyncEventExecutor; } if (observers.isEmpty()) { return AsyncEventDeliveryStage.completed(event, executor); } final NotificationMode mode = initMode(options.get(WeldNotificationOptions.MODE)); <START> final Long timeout = verifyNotificationTimeoutOption(options); <END> final SecurityContext securityContext = securityServices.getSecurityContext(); final ObserverExceptionHandler exceptionHandler; CompletableFuture<U> completableFuture; if (observers.size() > 1 && NotificationMode.PARALLEL.equals(mode)) { exceptionHandler = new CollectingExceptionHandler(new CopyOnWriteArrayList<>()); List<CompletableFuture<T>> completableFutures = new ArrayList<>(observers.size()); for (ObserverMethod<? super T> observer : observers) { completableFutures.add(CompletableFuture.supplyAsync(createSupplier(securityContext, event, metadata, exceptionHandler, false, () -> { notifyAsyncObserver(observer, event, metadata, exceptionHandler); }), executor)); } completableFuture = CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[] {})).thenApply((ignoredVoid) -> { handleExceptions(exceptionHandler); return event; }); } else { exceptionHandler = new CollectingExceptionHandler(); completableFuture = CompletableFuture.supplyAsync(createSupplier(securityContext, event, metadata, exceptionHandler, true, () -> { for (ObserverMethod<? super T> observer : observers) { notifyAsyncObserver(observer, event, metadata, exceptionHandler); } }), executor); } if (timeout != null) { completableFuture = CompletableFuture.anyOf(completableFuture, startTimer(timeout)).thenApply((ignoredObject) -> event); } return new AsyncEventDeliveryStage<>(completableFuture, executor); }</code><technical_language>unify init/validation method names. If initX template change it: * initModeOption()/initTimeoutOption() * initializeMode()/initializeTimeout() * verifyModeOption()/verifyTimeoutOption() * ..</technical_language>

Target:
protected <T, U extends T> CompletionStage<U> notifyAsyncObservers(List<ObserverMethod<? super T>> observers, U event, EventMetadata metadata, Executor executor, NotificationOptions options) { if (executor == null) { executor = asyncEventExecutor; } if (observers.isEmpty()) { return AsyncEventDeliveryStage.completed(event, executor); } final NotificationMode mode = initModeOption(options.get(WeldNotificationOptions.MODE)); final Long timeout = initTimeoutOption(options.get(WeldNotificationOptions.TIMEOUT)); final SecurityContext securityContext = securityServices.getSecurityContext(); final ObserverExceptionHandler exceptionHandler; CompletableFuture<U> completableFuture; if (observers.size() > 1 && NotificationMode.PARALLEL.equals(mode)) { exceptionHandler = new CollectingExceptionHandler(new CopyOnWriteArrayList<>()); List<CompletableFuture<T>> completableFutures = new ArrayList<>(observers.size()); for (ObserverMethod<? super T> observer : observers) { completableFutures.add(CompletableFuture.supplyAsync(createSupplier(securityContext, event, metadata, exceptionHandler, false, () -> { notifyAsyncObserver(observer, event, metadata, exceptionHandler); }), executor)); } completableFuture = CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[] {})).thenApply((ignoredVoid) -> { handleExceptions(exceptionHandler); return event; }); } else { exceptionHandler = new CollectingExceptionHandler(); completableFuture = CompletableFuture.supplyAsync(createSupplier(securityContext, event, metadata, exceptionHandler, true, () -> { for (ObserverMethod<? super T> observer : observers) { notifyAsyncObserver(observer, event, metadata, exceptionHandler); } }), executor); } if (timeout != null) { completableFuture = CompletableFuture.anyOf(completableFuture, startTimer(timeout)).thenApply((ignoredObject) -> event); } return new AsyncEventDeliveryStage<>(completableFuture, executor); }