Search in sources :

Example 1 with ResourceReferenceFactory

use of org.jboss.weld.injection.spi.ResourceReferenceFactory in project wildfly by wildfly.

the class AbstractResourceInjectionServices method createLazyResourceReferenceFactory.

protected ResourceReferenceFactory<Object> createLazyResourceReferenceFactory(final ContextNames.BindInfo ejbBindInfo) {
    return new ResourceReferenceFactory<Object>() {

        @Override
        public ResourceReference<Object> createResource() {
            final ManagedReferenceFactory factory = getManagedReferenceFactory(ejbBindInfo);
            if (factory == null) {
                return new SimpleResourceReference<>(null);
            }
            final ManagedReference instance = factory.getReference();
            return new ResourceReference<Object>() {

                @Override
                public Object getInstance() {
                    return instance.getInstance();
                }

                @Override
                public void release() {
                    instance.release();
                }
            };
        }
    };
}
Also used : ResourceReferenceFactory(org.jboss.weld.injection.spi.ResourceReferenceFactory) ContextListManagedReferenceFactory(org.jboss.as.naming.ContextListManagedReferenceFactory) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) SimpleResourceReference(org.jboss.weld.injection.spi.helpers.SimpleResourceReference) ManagedReference(org.jboss.as.naming.ManagedReference) ResourceReference(org.jboss.weld.injection.spi.ResourceReference) SimpleResourceReference(org.jboss.weld.injection.spi.helpers.SimpleResourceReference)

Example 2 with ResourceReferenceFactory

use of org.jboss.weld.injection.spi.ResourceReferenceFactory in project wildfly by wildfly.

the class WeldEjbInjectionServices method createLazyResourceReferenceFactory.

protected ResourceReferenceFactory<Object> createLazyResourceReferenceFactory(final ViewDescription viewDescription) {
    return new ResourceReferenceFactory<Object>() {

        @Override
        public ResourceReference<Object> createResource() {
            final ManagedReference instance;
            try {
                final ServiceController<?> controller = serviceRegistry.getRequiredService(viewDescription.getServiceName());
                final ComponentView view = (ComponentView) controller.getValue();
                instance = view.createInstance();
                return new ResourceReference<Object>() {

                    @Override
                    public Object getInstance() {
                        return instance.getInstance();
                    }

                    @Override
                    public void release() {
                        instance.release();
                    }
                };
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
}
Also used : ResourceReferenceFactory(org.jboss.weld.injection.spi.ResourceReferenceFactory) ComponentView(org.jboss.as.ee.component.ComponentView) ManagedReference(org.jboss.as.naming.ManagedReference) ResourceReference(org.jboss.weld.injection.spi.ResourceReference) SimpleResourceReference(org.jboss.weld.injection.spi.helpers.SimpleResourceReference) NamingException(javax.naming.NamingException)

Aggregations

ManagedReference (org.jboss.as.naming.ManagedReference)2 ResourceReference (org.jboss.weld.injection.spi.ResourceReference)2 ResourceReferenceFactory (org.jboss.weld.injection.spi.ResourceReferenceFactory)2 SimpleResourceReference (org.jboss.weld.injection.spi.helpers.SimpleResourceReference)2 NamingException (javax.naming.NamingException)1 ComponentView (org.jboss.as.ee.component.ComponentView)1 ContextListManagedReferenceFactory (org.jboss.as.naming.ContextListManagedReferenceFactory)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1