Search in sources :

Example 1 with Producer

use of javax.enterprise.inject.spi.Producer in project tomcat by apache.

the class OpenWebBeansInstanceManager method destroyInstance.

@SuppressWarnings("unchecked")
@Override
public void destroyInstance(Object object) throws IllegalAccessException, InvocationTargetException {
    Instance injectorInstance = instances.get(object);
    if (injectorInstance != null) {
        try {
            ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(loader);
            try {
                BeanManagerImpl beanManager = WebBeansContext.currentInstance().getBeanManagerImpl();
                @SuppressWarnings("rawtypes") Producer producer = beanManager.getProducerForJavaEeComponent(injectorInstance.object.getClass());
                if (producer != null) {
                    producer.dispose(injectorInstance.object);
                } else if (injectorInstance.context != null) {
                    injectorInstance.context.release();
                }
            } finally {
                Thread.currentThread().setContextClassLoader(oldLoader);
            }
        } catch (Exception e) {
            log.error(sm.getString("instanceManager.destroyError", object), e);
        }
    }
    this.instanceManager.destroyInstance(object);
}
Also used : Producer(javax.enterprise.inject.spi.Producer) BeanManagerImpl(org.apache.webbeans.container.BeanManagerImpl) NamingException(javax.naming.NamingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with Producer

use of javax.enterprise.inject.spi.Producer in project Payara by payara.

the class MetricCDIExtension method registerCustomMetrics.

private void registerCustomMetrics(@Observes AfterDeploymentValidation adv, BeanManager manager) {
    MetricsService metricsService = Globals.getDefaultBaseServiceLocator().getService(MetricsService.class);
    MetricRegistry registry = metricsService.getOrAddRegistry(metricsService.getApplicationName());
    MetricsHelper helper = getReference(manager, MetricsHelper.class);
    for (Map.Entry<Producer<?>, AnnotatedMember<?>> entry : metrics.entrySet()) {
        AnnotatedMember<?> annotatedMember = entry.getValue();
        Producer<?> prod = entry.getKey();
        if (hasInjectionPoints(annotatedMember)) {
            continue;
        }
        Metadata metadata = helper.metadataOf(annotatedMember);
        registry.register(metadata.getName(), (Metric) prod.produce(manager.createCreationalContext(null)), metadata);
    }
    metrics.clear();
}
Also used : MetricProducer(fish.payara.microprofile.metrics.cdi.producer.MetricProducer) ProcessProducer(javax.enterprise.inject.spi.ProcessProducer) Producer(javax.enterprise.inject.spi.Producer) MetricRegistryProducer(fish.payara.microprofile.metrics.cdi.producer.MetricRegistryProducer) MetricsService(fish.payara.microprofile.metrics.MetricsService) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) MetricsHelper(fish.payara.microprofile.metrics.cdi.MetricsHelper) AnnotatedMember(javax.enterprise.inject.spi.AnnotatedMember) Metadata(org.eclipse.microprofile.metrics.Metadata) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Producer (javax.enterprise.inject.spi.Producer)2 MetricsService (fish.payara.microprofile.metrics.MetricsService)1 MetricsHelper (fish.payara.microprofile.metrics.cdi.MetricsHelper)1 MetricProducer (fish.payara.microprofile.metrics.cdi.producer.MetricProducer)1 MetricRegistryProducer (fish.payara.microprofile.metrics.cdi.producer.MetricRegistryProducer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AnnotatedMember (javax.enterprise.inject.spi.AnnotatedMember)1 ProcessProducer (javax.enterprise.inject.spi.ProcessProducer)1 NamingException (javax.naming.NamingException)1 BeanManagerImpl (org.apache.webbeans.container.BeanManagerImpl)1 Metadata (org.eclipse.microprofile.metrics.Metadata)1 MetricRegistry (org.eclipse.microprofile.metrics.MetricRegistry)1