Skip to content

Instantly share code, notes, and snippets.

@ljnelson
Created February 14, 2018 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljnelson/cbcaa74e9726a3c6c1e77b09034b5573 to your computer and use it in GitHub Desktop.
Save ljnelson/cbcaa74e9726a3c6c1e77b09034b5573 to your computer and use it in GitHub Desktop.
private final <T extends HasMetadata, X extends Listable<? extends KubernetesResourceList> & VersionWatchable<? extends Closeable, Watcher<T>>> void startControllers(@Observes @Initialized(ApplicationScoped.class) @Priority(LIBRARY_AFTER) final Object ignored, final BeanManager beanManager) {
if (beanManager != null) {
for (final Bean<?> bean : this.beans) {
assert bean != null;
final Set<Annotation> qualifiers = bean.getQualifiers();
final Map<Object, T> knownObjects = new HashMap<>();
final EventDistributor<T> eventDistributor = new EventDistributor<>(knownObjects);
eventDistributor.addConsumer(new CDIEventDistributor<T>(qualifiers, null /* no NotificationOptions; TODO */, this.syncNeeded, this.asyncNeeded));
@SuppressWarnings("unchecked") // we know an Operation is of type X
final X contextualReference = (X)beanManager.getReference(bean, getOperationType(bean), beanManager.createCreationalContext(bean));
final Controller<T> controller = new Controller<>(contextualReference, knownObjects, eventDistributor);
controller.start();
this.controllers.add(controller);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment