CDIEventDistributor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final class CDIEventDistributor<T extends HasMetadata> implements Consumer<AbstractEvent<? extends T>> { | |
private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0]; | |
private final Annotation[] qualifiers; | |
private final NotificationOptions notificationOptions; | |
private final boolean syncNeeded; | |
private final boolean asyncNeeded; | |
private CDIEventDistributor(final Set<Annotation> qualifiers, final NotificationOptions notificationOptions, final boolean syncNeeded, final boolean asyncNeeded) { | |
super(); | |
if (qualifiers == null) { | |
this.qualifiers = EMPTY_ANNOTATION_ARRAY; | |
} else { | |
this.qualifiers = qualifiers.toArray(new Annotation[qualifiers.size()]); | |
} | |
this.notificationOptions = notificationOptions; | |
this.syncNeeded = syncNeeded; | |
this.asyncNeeded = asyncNeeded; | |
} | |
@Override | |
public final void accept(final AbstractEvent<? extends T> controllerEvent) { | |
if (controllerEvent != null && (this.syncNeeded || this.asyncNeeded)) { | |
final BeanManager beanManager = CDI.current().getBeanManager(); | |
assert beanManager != null; | |
final javax.enterprise.event.Event<Object> cdiEventMachinery = beanManager.getEvent(); | |
assert cdiEventMachinery != null; | |
final TypeLiteral<AbstractEvent<? extends T>> eventTypeLiteral = new TypeLiteral<AbstractEvent<? extends T>>() { | |
private static final long serialVersionUID = 1L; | |
}; | |
final javax.enterprise.event.Event<AbstractEvent<? extends T>> broadcaster = cdiEventMachinery.select(eventTypeLiteral, this.qualifiers); | |
assert broadcaster != null; | |
if (this.asyncNeeded) { | |
if (this.notificationOptions == null) { | |
broadcaster.fireAsync(controllerEvent); | |
} else { | |
broadcaster.fireAsync(controllerEvent, this.notificationOptions); | |
} | |
} | |
if (this.syncNeeded) { | |
broadcaster.fire(controllerEvent); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment