use of javax.enterprise.inject.spi.EventMetadata in project core by weld.
the class FastEvent method of.
/**
* Constructs a new FastEvent instance
* @param type the event type
* @param manager the bean manager
* @param notifier the notifier to be used for observer method resolution
* @param qualifiers the event qualifiers
* @return
*/
public static <T> FastEvent<T> of(Class<T> type, BeanManagerImpl manager, ObserverNotifier notifier, Annotation... qualifiers) {
ResolvedObservers<T> resolvedObserverMethods = notifier.<T>resolveObserverMethods(type, qualifiers);
if (resolvedObserverMethods.isMetadataRequired()) {
EventMetadata metadata = new EventMetadataImpl(type, null, qualifiers);
CurrentEventMetadata metadataService = manager.getServices().get(CurrentEventMetadata.class);
return new FastEventWithMetadataPropagation<T>(resolvedObserverMethods, metadata, metadataService);
} else {
return new FastEvent<T>(resolvedObserverMethods);
}
}
use of javax.enterprise.inject.spi.EventMetadata in project core by weld.
the class ObserverNotifier method notifyAsyncObservers.
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);
}
// We should always initialize and validate all notification options first
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;
CompletableFuture<U> completableFuture;
if (observers.size() > 1 && NotificationMode.PARALLEL.equals(mode)) {
// Attempt to notify async observers in parallel
exceptionHandler = new CollectingExceptionHandler(new CopyOnWriteArrayList<>());
List<CompletableFuture<T>> completableFutures = new ArrayList<>(observers.size());
for (ObserverMethod<? super T> observer : observers) {
completableFutures.add(CompletableFuture.supplyAsync(createSupplier(securityContextActionConsumer, event, metadata, exceptionHandler, false, () -> {
notifyAsyncObserver(observer, event, metadata, exceptionHandler);
}), executor));
}
completableFuture = CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[] {})).thenApply((ignoredVoid) -> {
handleExceptions(exceptionHandler);
return event;
});
} else {
// Async observers are notified serially in a single worker thread
exceptionHandler = new CollectingExceptionHandler();
completableFuture = CompletableFuture.supplyAsync(createSupplier(securityContextActionConsumer, event, metadata, exceptionHandler, true, () -> {
for (ObserverMethod<? super T> observer : observers) {
notifyAsyncObserver(observer, event, metadata, exceptionHandler);
}
}), executor);
}
// If NotificationOptionKeys.TIMEOUT is set, we will trigger the counter and use CompletableFuture.anyOf()
if (timeout != null) {
completableFuture = CompletableFuture.anyOf(completableFuture, startTimer(timeout)).thenApply((ignoredObject) -> event);
}
return new AsyncEventDeliveryStage<>(completableFuture, executor);
}
use of javax.enterprise.inject.spi.EventMetadata in project core by weld.
the class ProbeObserver method notify.
@Override
public void notify(Object event) {
EventMetadata metadata = currentEventMetadata.peek();
if (excludePattern != null && excludePattern.matcher(Formats.formatType(metadata.getType(), false)).matches()) {
ProbeLogger.LOG.eventExcluded(metadata.getType());
return;
}
boolean containerEvent = isContainerEvent(metadata.getQualifiers());
List<ObserverMethod<?>> observers = resolveObservers(metadata, containerEvent);
EventInfo info = new EventInfo(metadata.getType(), metadata.getQualifiers(), event, metadata.getInjectionPoint(), observers, containerEvent, System.currentTimeMillis());
probe.addEvent(info);
}
use of javax.enterprise.inject.spi.EventMetadata in project core by weld.
the class HttpContextLifecycle method fireEventForApplicationScope.
private void fireEventForApplicationScope(ServletContext ctx, Annotation qualifier) {
if (module != null) {
// Deliver events sequentially
synchronized (container) {
if (module.isWebModule()) {
module.fireEvent(ServletContext.class, ctx, qualifier);
} else {
// fallback for backward compatibility
ServletLogger.LOG.noEeModuleDescriptor(beanManager);
final EventMetadata metadata = new EventMetadataImpl(ServletContext.class, null, Collections.singleton(qualifier));
beanManager.getAccessibleLenientObserverNotifier().fireEvent(ServletContext.class, ctx, metadata, qualifier);
}
}
}
}
use of javax.enterprise.inject.spi.EventMetadata in project core by weld.
the class BeanDeploymentModule method fireEvent.
/**
* Fire an event and notify observers that belong to this module.
* @param eventType
* @param event
* @param qualifiers
*/
public void fireEvent(Type eventType, Object event, Annotation... qualifiers) {
final EventMetadata metadata = new EventMetadataImpl(eventType, null, qualifiers);
notifier.fireEvent(eventType, event, metadata, qualifiers);
}
Aggregations