Search in sources :

Example 1 with Unmanaged

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);
    }
}
Also used : ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) Unmanaged(javax.enterprise.inject.spi.Unmanaged) HealthCheck(org.eclipse.microprofile.health.HealthCheck) NamingException(javax.naming.NamingException)

Example 2 with Unmanaged

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();
}
Also used : Unmanaged(javax.enterprise.inject.spi.Unmanaged) BeanManager(javax.enterprise.inject.spi.BeanManager)

Aggregations

Unmanaged (javax.enterprise.inject.spi.Unmanaged)2 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)1 NamingException (javax.naming.NamingException)1 HealthCheck (org.eclipse.microprofile.health.HealthCheck)1