javax.enterprise.inject.spi.Unmanaged Java Examples

The following examples show how to use javax.enterprise.inject.spi.Unmanaged. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: smallrye-fault-tolerance   Author: smallrye   File: DefaultFallbackHandlerProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public <T> FallbackHandler<T> get(FaultToleranceOperation operation) {
    if (operation.hasFallback()) {
        //noinspection Convert2Lambda
        return new FallbackHandler<T>() {
            @Override
            public T handle(ExecutionContext context) {
                Unmanaged<FallbackHandler<T>> unmanaged = new Unmanaged<>(beanManager,
                        operation.getFallback().get(FallbackConfig.VALUE));
                Unmanaged.UnmanagedInstance<FallbackHandler<T>> unmanagedInstance = unmanaged.newInstance();
                FallbackHandler<T> handler = unmanagedInstance.produce().inject().postConstruct().get();
                try {
                    return handler.handle(context);
                } finally {
                    // The instance exists to service a single invocation only
                    unmanagedInstance.preDestroy().dispose();
                }
            }
        };
    }
    return null;
}
 
Example #2
Source Project: thorntail   Author: thorntail   File: HealthExtension.java    License: Apache License 2.0 6 votes vote down vote up
public void afterDeploymentValidation(@Observes final AfterDeploymentValidation abd, BeanManager beanManager) {
    try {
        if (delegate != null) {
            Unmanaged<SmallRyeHealthReporter> unmanagedHealthCheck =
                new Unmanaged<>(beanManager, SmallRyeHealthReporter.class);
            reporterInstance = unmanagedHealthCheck.newInstance();
            reporter =  reporterInstance.produce().inject().postConstruct().get();
            monitor.registerHealthReporter(reporter);

            // THORN-2195: Use the correct TCCL when health checks are obtained
            // In WildFly, the TCCL should always be set to the top-level deployment CL during extension notification
            monitor.registerContextClassLoader(Thread.currentThread().getContextClassLoader());

            log.info(">> Added health reporter bean " + reporter);
            delegate = null;
        }

    } catch (Exception e) {
        throw new RuntimeException("Failed to register health reporter bean", e);
    }
}
 
Example #3
Source Project: hammock   Author: hammock-project   File: HammockInstanceManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object newInstance(Class<?> clazz) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException {
    try {
        Unmanaged.UnmanagedInstance<?> instance = new Unmanaged<>(beanManager, clazz).newInstance();
        instance.produce().inject().postConstruct();
        Object o = instance.get();
        instanceMap.put(o, instance);
        return o;
    } catch (Exception e) {
        return clazz.newInstance();
    }
}
 
Example #4
Source Project: hammock   Author: hammock-project   File: HammockInstanceManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException {
    Unmanaged.UnmanagedInstance remove = instanceMap.remove(o);
    if (remove != null) {
        remove.preDestroy();
        remove.dispose();
    }
}
 
Example #5
Source Project: hammock   Author: hammock-project   File: HammockInstanceFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public InstanceHandle<T> createInstance() {
    try {
        return new HammockInstanceHandle<>(new Unmanaged<>(beanManager, clazz).newInstance());
    }
    catch (Exception e) {
        try {
            return new BasicInstanceFactory<T>(clazz.newInstance());
        } catch (Exception ex) {
            throw new RuntimeException("Unable to instantiate "+clazz, ex);
        }
    }
}
 
Example #6
Source Project: hammock   Author: hammock-project   File: HammockInstanceHandle.java    License: Apache License 2.0 4 votes vote down vote up
HammockInstanceHandle(Unmanaged.UnmanagedInstance<T> instance) {
    this.instance = instance;
    instance.produce().inject().postConstruct();
}
 
Example #7
Source Project: hammock   Author: hammock-project   File: Unmanageable.java    License: Apache License 2.0 4 votes vote down vote up
public Unmanageable(Class<T> clazz) {
    this.instance = new Unmanaged<T>(clazz).newInstance();
    this.instance.produce().inject().postConstruct();
}