use of javax.enterprise.inject.spi.Unmanaged in project wildfly-swarm by wildfly-swarm.
the class HealthExtension method afterDeploymentValidation.
/**
* Instantiates <em>unmanaged instances</em> of HealthCheckProcedure and
* handle manually their CDI creation lifecycle.
* Add them to the {@link Monitor}.
*/
private void afterDeploymentValidation(@Observes final AfterDeploymentValidation abd, BeanManager beanManager) {
try {
for (AnnotatedType delegate : delegates) {
Unmanaged<HealthCheck> unmanagedHealthCheck = new Unmanaged<HealthCheck>(beanManager, delegate.getJavaClass());
Unmanaged.UnmanagedInstance<HealthCheck> healthCheckInstance = unmanagedHealthCheck.newInstance();
HealthCheck healthCheck = healthCheckInstance.produce().inject().postConstruct().get();
healthChecks.add(healthCheck);
healthCheckInstances.add(healthCheckInstance);
monitor.registerHealthBean(healthCheck);
log.info(">> Added health bean impl " + healthCheck);
}
// we don't need the references anymore
delegates.clear();
} catch (Exception e) {
throw new RuntimeException("Failed to register health bean", e);
}
}
use of javax.enterprise.inject.spi.Unmanaged in project cucumber-jvm by cucumber.
the class Cdi2Factory method getInstance.
@Override
public <T> T getInstance(Class<T> type) {
Unmanaged.UnmanagedInstance<?> instance = standaloneInstances.get(type);
if (instance != null) {
return type.cast(instance.get());
}
Instance<T> selected = container.select(type);
if (selected.isUnsatisfied()) {
BeanManager beanManager = container.getBeanManager();
Unmanaged<T> unmanaged = new Unmanaged<>(beanManager, type);
Unmanaged.UnmanagedInstance<T> value = unmanaged.newInstance();
value.produce();
value.inject();
value.postConstruct();
standaloneInstances.put(type, value);
return value.get();
}
return selected.get();
}
Aggregations