/** * * @param executor a specific {@link Executor} to handle observer notification * @return an immutable holder of an executor */ static NotificationOptions ofExecutor(Executor executor) { return builder().setExecutor(executor).build(); }
private CompletableFuture invokeObserverMethodAsync(Object event, EventMetadataImpl metadata, ObserverMethod<? super Object> observer, NotificationOptions notificationOptions) { CompletableFuture<?> future = new CompletableFuture<>(); CompletableFuture.runAsync(() -> { try { runAsync(event, metadata, observer); future.complete(null); } catch (WebBeansException wbe) { future.completeExceptionally(wbe.getCause()); } }, notificationOptions.getExecutor() == null ? defaultNotificationOptions.getExecutor() : notificationOptions.getExecutor()); return future; }
final NotificationMode mode = initModeOption(options.get(WeldNotificationOptions.MODE)); final Long timeout = initTimeoutOption(options.get(WeldNotificationOptions.TIMEOUT)); final Consumer<Runnable> securityContextActionConsumer = securityServices.getSecurityContextAssociator(); final ObserverExceptionHandler exceptionHandler;
public NotificationManager(WebBeansContext webBeansContext) { this.webBeansContext = webBeansContext; this.defaultNotificationOptions = NotificationOptions.ofExecutor(getDefaultExecutor()); }
/** * Delivers the given asynchronous event object to given observer asynchronous observer methods. * * Asynchronous observer methods are scheduled to be notified in a separate thread. Note that this method exits just after event delivery to asynchronous * observer methods is scheduled. {@link EventMetadata} is made available for injection into observer methods, if needed. * * Note that if any of the observer methods throws an exception, it is never thrown out of this method. Instead, all the exceptions are grouped together * using {@link CompletionException} and the returned {@link CompletionStage} fails with this compound exception. * * If an executor is provided then observer methods are notified using this executor. Otherwise, Weld's task executor is used. * * @param observers the given observer methods * @param event the given event object * @param metadata event metadata * @param options */ public <T, U extends T> CompletionStage<U> notifyAsync(ResolvedObservers<T> observers, U event, EventMetadata metadata, NotificationOptions options) { if (!observers.isMetadataRequired()) { metadata = null; } return notifyAsyncObservers(observers.getAsyncObservers(), event, metadata, options.getExecutor(), options); }
final NotificationMode mode = initModeOption(options.get(WeldNotificationOptions.MODE)); final Long timeout = initTimeoutOption(options.get(WeldNotificationOptions.TIMEOUT)); final Consumer<Runnable> securityContextActionConsumer = securityServices.getSecurityContextAssociator(); final ObserverExceptionHandler exceptionHandler;
@Test @SpecAssertions({ @SpecAssertion(section = EVENT, id = "ee") }) public void testCustomExecutor() throws InterruptedException { BlockingQueue<Message> queue = new LinkedBlockingQueue<>(); NotificationOptions notificationOptions = NotificationOptions.ofExecutor(new CustomExecutor()); event.fireAsync(new Message(), notificationOptions).thenAccept(queue::add); Message message = queue.poll(2, TimeUnit.SECONDS); assertNotNull(message); assertTrue(MessageObserver.observed.get()); assertTrue(CustomExecutor.executed.get()); }
/** * * @param optionName name of the option to set * @param optionValue value for the option * @return an immutable holder of a single option */ static NotificationOptions of(String optionName, Object optionValue) { return builder().set(optionName, optionValue).build(); }
/** * Delivers the given asynchronous event object to given observer asynchronous observer methods. * * Asynchronous observer methods are scheduled to be notified in a separate thread. Note that this method exits just after event delivery to asynchronous * observer methods is scheduled. {@link EventMetadata} is made available for injection into observer methods, if needed. * * Note that if any of the observer methods throws an exception, it is never thrown out of this method. Instead, all the exceptions are grouped together * using {@link CompletionException} and the returned {@link CompletionStage} fails with this compound exception. * * If an executor is provided then observer methods are notified using this executor. Otherwise, Weld's task executor is used. * * @param observers the given observer methods * @param event the given event object * @param metadata event metadata * @param options */ public <T, U extends T> CompletionStage<U> notifyAsync(ResolvedObservers<T> observers, U event, EventMetadata metadata, NotificationOptions options) { if (!observers.isMetadataRequired()) { metadata = null; } return notifyAsyncObservers(observers.getAsyncObservers(), event, metadata, options.getExecutor(), options); }
final NotificationMode mode = initModeOption(options.get(WeldNotificationOptions.MODE)); final Long timeout = initTimeoutOption(options.get(WeldNotificationOptions.TIMEOUT)); final Consumer<Runnable> securityContextActionConsumer = securityServices.getSecurityContextAssociator(); final ObserverExceptionHandler exceptionHandler;
/** * * @param optionName name of the option to set * @param optionValue value for the option * @return an immutable holder of a single option */ static NotificationOptions of(String optionName, Object optionValue) { return builder().set(optionName, optionValue).build(); }
/** * Delivers the given asynchronous event object to given observer asynchronous observer methods. * * Asynchronous observer methods are scheduled to be notified in a separate thread. Note that this method exits just after event delivery to asynchronous * observer methods is scheduled. {@link EventMetadata} is made available for injection into observer methods, if needed. * * Note that if any of the observer methods throws an exception, it is never thrown out of this method. Instead, all the exceptions are grouped together * using {@link CompletionException} and the returned {@link CompletionStage} fails with this compound exception. * * If an executor is provided then observer methods are notified using this executor. Otherwise, Weld's task executor is used. * * @param observers the given observer methods * @param event the given event object * @param metadata event metadata * @param options */ public <T, U extends T> CompletionStage<U> notifyAsync(ResolvedObservers<T> observers, U event, EventMetadata metadata, NotificationOptions options) { if (!observers.isMetadataRequired()) { metadata = null; } return notifyAsyncObservers(observers.getAsyncObservers(), event, metadata, options.getExecutor(), options); }
final NotificationMode mode = initModeOption(options.get(WeldNotificationOptions.MODE)); final Long timeout = initTimeoutOption(options.get(WeldNotificationOptions.TIMEOUT)); final Consumer<Runnable> securityContextActionConsumer = securityServices.getSecurityContextAssociator(); final ObserverExceptionHandler exceptionHandler;
/** * * @param executor a specific {@link Executor} to handle observer notification * @return an immutable holder of an executor */ static NotificationOptions ofExecutor(Executor executor) { return builder().setExecutor(executor).build(); }
/** * Delivers the given asynchronous event object to given observer asynchronous observer methods. * * Asynchronous observer methods are scheduled to be notified in a separate thread. Note that this method exits just after event delivery to asynchronous * observer methods is scheduled. {@link EventMetadata} is made available for injection into observer methods, if needed. * * Note that if any of the observer methods throws an exception, it is never thrown out of this method. Instead, all the exceptions are grouped together * using {@link CompletionException} and the returned {@link CompletionStage} fails with this compound exception. * * If an executor is provided then observer methods are notified using this executor. Otherwise, Weld's task executor is used. * * @param observers the given observer methods * @param event the given event object * @param metadata event metadata * @param options */ public <T, U extends T> CompletionStage<U> notifyAsync(ResolvedObservers<T> observers, U event, EventMetadata metadata, NotificationOptions options) { if (!observers.isMetadataRequired()) { metadata = null; } return notifyAsyncObservers(observers.getAsyncObservers(), event, metadata, options.getExecutor(), options); }
final NotificationMode mode = initModeOption(options.get(WeldNotificationOptions.MODE)); final Long timeout = initTimeoutOption(options.get(WeldNotificationOptions.TIMEOUT)); final Consumer<Runnable> securityContextActionConsumer = securityServices.getSecurityContextAssociator(); final ObserverExceptionHandler exceptionHandler;
/** * * @param executor a specific {@link Executor} to handle observer notification * @return an immutable holder of an executor */ static NotificationOptions ofExecutor(Executor executor) { return builder().setExecutor(executor).build(); }
/** * Delivers the given asynchronous event object to given observer asynchronous observer methods. * * Asynchronous observer methods are scheduled to be notified in a separate thread. Note that this method exits just after event delivery to asynchronous * observer methods is scheduled. {@link EventMetadata} is made available for injection into observer methods, if needed. * * Note that if any of the observer methods throws an exception, it is never thrown out of this method. Instead, all the exceptions are grouped together * using {@link CompletionException} and the returned {@link CompletionStage} fails with this compound exception. * * If an executor is provided then observer methods are notified using this executor. Otherwise, Weld's task executor is used. * * @param observers the given observer methods * @param event the given event object * @param metadata event metadata * @param options */ public <T, U extends T> CompletionStage<U> notifyAsync(ResolvedObservers<T> observers, U event, EventMetadata metadata, NotificationOptions options) { if (!observers.isMetadataRequired()) { metadata = null; } return notifyAsyncObservers(observers.getAsyncObservers(), event, metadata, options.getExecutor(), options); }
/** * * @param timeout The timeout in milliseconds * @return notification options with {@value #TIMEOUT} set */ static NotificationOptions withTimeout(long timeout) { return NotificationOptions.builder().set(TIMEOUT, timeout).build(); }
.getExecutor().execute(() -> {});