Search in sources :

Example 16 with ManagedReference

use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.

the class StatefulSessionObjectReferenceImpl method getBusinessObject.

@Override
@SuppressWarnings({ "unchecked" })
public synchronized <S> S getBusinessObject(Class<S> businessInterfaceType) {
    if (isRemoved()) {
        WeldEjbLogger.ROOT_LOGGER.ejbHashBeenRemoved(ejbComponent);
    }
    final String businessInterfaceName = businessInterfaceType.getName();
    ManagedReference managedReference = null;
    if (businessInterfaceToReference == null) {
        businessInterfaceToReference = new HashMap<String, ManagedReference>();
    } else {
        managedReference = businessInterfaceToReference.get(businessInterfaceName);
    }
    if (managedReference == null) {
        if (viewServices.containsKey(businessInterfaceType)) {
            final ServiceController<?> serviceController = currentServiceContainer().getRequiredService(viewServices.get(businessInterfaceType));
            final ComponentView view = (ComponentView) serviceController.getValue();
            try {
                managedReference = view.createInstance(Collections.<Object, Object>singletonMap(SessionID.class, id));
                businessInterfaceToReference.put(businessInterfaceName, managedReference);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        } else {
            throw WeldLogger.ROOT_LOGGER.viewNotFoundOnEJB(businessInterfaceType.getName(), ejbComponent.getComponentName());
        }
    }
    return (S) managedReference.getInstance();
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) ManagedReference(org.jboss.as.naming.ManagedReference) IOException(java.io.IOException)

Example 17 with ManagedReference

use of org.jboss.as.naming.ManagedReference 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)

Example 18 with ManagedReference

use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.

the class WeldInjectionInterceptor method processInvocation.

@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
    WeldInjectionContext injectionContext = context.getPrivateData(WeldInjectionContext.class);
    ManagedReference reference = (ManagedReference) context.getPrivateData(ComponentInstance.class).getInstanceData(BasicComponentInstance.INSTANCE_KEY);
    if (reference != null) {
        injectionContext.inject(reference.getInstance());
    }
    return context.proceed();
}
Also used : ManagedReference(org.jboss.as.naming.ManagedReference)

Example 19 with ManagedReference

use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.

the class WeldInterceptorInjectionInterceptor method processInvocation.

@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
    WeldInjectionContext injectionContext = context.getPrivateData(WeldInjectionContext.class);
    final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
    //now inject the interceptors
    for (final Class<?> interceptorClass : interceptorClasses) {
        final ManagedReference instance = (ManagedReference) componentInstance.getInstanceData(interceptorClass);
        if (instance != null) {
            injectionContext.injectInterceptor(instance.getInstance());
        }
    }
    return context.proceed();
}
Also used : ComponentInstance(org.jboss.as.ee.component.ComponentInstance) ManagedReference(org.jboss.as.naming.ManagedReference)

Example 20 with ManagedReference

use of org.jboss.as.naming.ManagedReference in project wildfly by wildfly.

the class EjbJndiBindingsDeploymentUnitProcessor method registerControlPointBinding.

private void registerControlPointBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName, final DeploymentUnit deploymentUnit) {
    final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
    final InjectedValue<ClassLoader> viewClassLoader = new InjectedValue<ClassLoader>();
    final InjectedValue<ControlPoint> controlPointInjectedValue = new InjectedValue<>();
    final RemoteViewInjectionSource delegate = new RemoteViewInjectionSource(null, moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
    final ServiceName depName = ControlPointService.serviceName(deploymentUnit.getParent() == null ? deploymentUnit.getName() : deploymentUnit.getParent().getName(), EJBComponentSuspendDeploymentUnitProcessor.ENTRY_POINT_NAME + deploymentUnit.getName() + "." + componentDescription.getComponentName());
    componentDescription.getConfigurators().add((context, description, configuration) -> {
        viewClassLoader.setValue(Values.immediateValue(configuration.getModuleClassLoader()));
        configuration.getCreateDependencies().add((serviceBuilder, service) -> serviceBuilder.addDependency(depName, ControlPoint.class, controlPointInjectedValue));
    });
    //we need to wrap the injection source to allow graceful shutdown to function, although this is not ideal
    //as it will also reject local lookups as well, although in general local code should never be looking up the
    //exported bindings
    //the other option would be to reject it at the remote naming service level, however then we loose the per-deployment granularity
    final InjectionSource is = new InjectionSource() {

        @Override
        public void getResourceValue(ResolutionContext resolutionContext, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
            final InjectedValue<ManagedReferenceFactory> delegateInjection = new InjectedValue<>();
            delegate.getResourceValue(resolutionContext, serviceBuilder, phaseContext, delegateInjection);
            injector.inject(new ManagedReferenceFactory() {

                @Override
                public ManagedReference getReference() {
                    ControlPoint cp = controlPointInjectedValue.getValue();
                    try {
                        RunResult res = cp.beginRequest();
                        if (res != RunResult.RUN) {
                            throw EjbLogger.ROOT_LOGGER.containerSuspended();
                        }
                        try {
                            return delegateInjection.getValue().getReference();
                        } finally {
                            cp.requestComplete();
                        }
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }
    };
    moduleDescription.getBindingConfigurations().add(new BindingConfiguration(jndiName, is));
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) ManagedReference(org.jboss.as.naming.ManagedReference) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) InjectionSource(org.jboss.as.ee.component.InjectionSource) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) Injector(org.jboss.msc.inject.Injector) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) RunResult(org.wildfly.extension.requestcontroller.RunResult) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Aggregations

ManagedReference (org.jboss.as.naming.ManagedReference)25 ComponentView (org.jboss.as.ee.component.ComponentView)7 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)7 NamingException (javax.naming.NamingException)4 ImmediateManagedReference (org.jboss.as.naming.ImmediateManagedReference)4 InterceptorContext (org.jboss.invocation.InterceptorContext)4 Method (java.lang.reflect.Method)3 MalformedURLException (java.net.MalformedURLException)3 ComponentInstance (org.jboss.as.ee.component.ComponentInstance)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 InitialContext (javax.naming.InitialContext)2 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)2 Component (org.jboss.as.ee.component.Component)2 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)2 ComponentFactory (org.jboss.as.ee.component.ComponentFactory)2 InjectionSource (org.jboss.as.ee.component.InjectionSource)2 ExtendedEntityManager (org.jboss.as.jpa.container.ExtendedEntityManager)2 Injector (org.jboss.msc.inject.Injector)2 ServiceName (org.jboss.msc.service.ServiceName)2