Search in sources :

Example 11 with ComponentView

use of org.jboss.as.ee.component.ComponentView 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 12 with ComponentView

use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.

the class WeldEjbInjectionServices method handleServiceLookup.

private ResourceReferenceFactory<Object> handleServiceLookup(ViewDescription viewDescription, InjectionPoint injectionPoint) {
    /*
         * Try to obtain ComponentView eagerly and validate the resource type
         */
    final ComponentView view = getComponentView(viewDescription);
    if (view != null && injectionPoint.getAnnotated().isAnnotationPresent(Produces.class)) {
        Class<?> clazz = view.getViewClass();
        Class<?> injectionPointRawType = Reflections.getRawType(injectionPoint.getType());
        //we just compare names, as for remote views the actual classes may be loaded from different class loaders
        Class<?> c = clazz;
        boolean found = false;
        while (c != null && c != Object.class) {
            if (injectionPointRawType.getName().equals(c.getName())) {
                found = true;
                break;
            }
            c = c.getSuperclass();
        }
        if (!found) {
            throw BeanLogger.LOG.invalidResourceProducerType(injectionPoint.getAnnotated(), clazz.getName());
        }
        return new ComponentViewToResourceReferenceFactoryAdapter<Object>(view);
    } else {
        return new LazyResourceReferenceFactory(viewDescription, serviceRegistry);
    }
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) Produces(javax.enterprise.inject.Produces)

Example 13 with ComponentView

use of org.jboss.as.ee.component.ComponentView 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 14 with ComponentView

use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.

the class DeploymentRepositoryProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (eeModuleDescription == null) {
        return;
    }
    // Note, we do not use the EEModuleDescription.getApplicationName() because that API returns the
    // module name if the top level unit isn't a .ear, which is not what we want. We really want a
    // .ear name as application name (that's the semantic in EJB spec). So use EEModuleDescription.getEarApplicationName
    String applicationName = eeModuleDescription.getEarApplicationName();
    // if it's not a .ear deployment then set app name to empty string
    applicationName = applicationName == null ? "" : applicationName;
    final DeploymentModuleIdentifier identifier = new DeploymentModuleIdentifier(applicationName, eeModuleDescription.getModuleName(), eeModuleDescription.getDistinctName());
    final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
    final Map<String, EjbDeploymentInformation> deploymentInformationMap = new HashMap<String, EjbDeploymentInformation>();
    final Set<ServiceName> componentStartServices = new HashSet<ServiceName>();
    final Map<ServiceName, InjectedValue<?>> injectedValues = new HashMap<ServiceName, InjectedValue<?>>();
    for (final ComponentDescription component : componentDescriptions) {
        if (component instanceof EJBComponentDescription) {
            final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) component;
            componentStartServices.add(component.getStartServiceName());
            final InjectedValue<EJBComponent> componentInjectedValue = new InjectedValue<EJBComponent>();
            injectedValues.put(component.getCreateServiceName(), componentInjectedValue);
            final Map<String, InjectedValue<ComponentView>> remoteViews = new HashMap<String, InjectedValue<ComponentView>>();
            final Map<String, InjectedValue<ComponentView>> localViews = new HashMap<String, InjectedValue<ComponentView>>();
            for (final ViewDescription view : ejbComponentDescription.getViews()) {
                boolean remoteView = false;
                if (view instanceof EJBViewDescription) {
                    final MethodIntf viewType = ((EJBViewDescription) view).getMethodIntf();
                    if (viewType == MethodIntf.HOME || viewType == MethodIntf.REMOTE) {
                        remoteView = true;
                    }
                }
                final InjectedValue<ComponentView> componentViewInjectedValue = new InjectedValue<ComponentView>();
                if (remoteView) {
                    remoteViews.put(view.getViewClassName(), componentViewInjectedValue);
                } else {
                    localViews.put(view.getViewClassName(), componentViewInjectedValue);
                }
                injectedValues.put(view.getServiceName(), componentViewInjectedValue);
            }
            final InjectedValue<EjbIIOPService> iorFactory = new InjectedValue<EjbIIOPService>();
            if (ejbComponentDescription.isExposedViaIiop()) {
                injectedValues.put(ejbComponentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), iorFactory);
            }
            final EjbDeploymentInformation info = new EjbDeploymentInformation(ejbComponentDescription.getEJBName(), componentInjectedValue, remoteViews, localViews, module.getClassLoader(), iorFactory);
            deploymentInformationMap.put(ejbComponentDescription.getEJBName(), info);
        }
    }
    final StartupCountdown countdown = deploymentUnit.getAttachment(Attachments.STARTUP_COUNTDOWN);
    final ModuleDeployment deployment = new ModuleDeployment(identifier, deploymentInformationMap, countdown);
    ServiceName moduleDeploymentService = deploymentUnit.getServiceName().append(ModuleDeployment.SERVICE_NAME);
    final ServiceBuilder<ModuleDeployment> builder = phaseContext.getServiceTarget().addService(moduleDeploymentService, deployment);
    for (Map.Entry<ServiceName, InjectedValue<?>> entry : injectedValues.entrySet()) {
        builder.addDependency(entry.getKey(), (InjectedValue<Object>) entry.getValue());
    }
    builder.addDependency(DeploymentRepository.SERVICE_NAME, DeploymentRepository.class, deployment.getDeploymentRepository());
    builder.install();
    final ModuleDeployment.ModuleDeploymentStartService deploymentStart = new ModuleDeployment.ModuleDeploymentStartService(identifier, countdown);
    final ServiceBuilder<Void> startBuilder = phaseContext.getServiceTarget().addService(deploymentUnit.getServiceName().append(ModuleDeployment.START_SERVICE_NAME), deploymentStart);
    startBuilder.addDependencies(componentStartServices);
    startBuilder.addDependency(moduleDeploymentService);
    startBuilder.addDependency(DeploymentRepository.SERVICE_NAME, DeploymentRepository.class, deploymentStart.getDeploymentRepository());
    startBuilder.install();
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) HashMap(java.util.HashMap) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) ModuleDeployment(org.jboss.as.ejb3.deployment.ModuleDeployment) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown) HashSet(java.util.HashSet) EjbDeploymentInformation(org.jboss.as.ejb3.deployment.EjbDeploymentInformation) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) ComponentView(org.jboss.as.ee.component.ComponentView) ServiceName(org.jboss.msc.service.ServiceName) DeploymentModuleIdentifier(org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EjbIIOPService(org.jboss.as.ejb3.iiop.EjbIIOPService) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with ComponentView

use of org.jboss.as.ee.component.ComponentView in project wildfly by wildfly.

the class StatefulRemoveInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext context) throws Exception {
    final Component component = context.getPrivateData(Component.class);
    //if a session bean is participating in a transaction, it
    //is an error for a client to invoke the remove method
    //on the session object's home or component interface.
    final ComponentView view = context.getPrivateData(ComponentView.class);
    if (view != null) {
        Ejb2xViewType viewType = view.getPrivateData(Ejb2xViewType.class);
        if (viewType != null) {
            //this means it is an EJB 2.x view
            //which is not allowed to remove while enrolled in a TX
            final StatefulTransactionMarker marker = context.getPrivateData(StatefulTransactionMarker.class);
            if (marker != null && !marker.isFirstInvocation()) {
                throw EjbLogger.ROOT_LOGGER.cannotRemoveWhileParticipatingInTransaction();
            }
        }
    }
    // just log a WARN and throw back the original exception
    if (component instanceof StatefulSessionComponent == false) {
        throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, StatefulSessionComponent.class);
    }
    final StatefulSessionComponent statefulComponent = (StatefulSessionComponent) component;
    Object invocationResult = null;
    try {
        // proceed
        invocationResult = context.proceed();
    } catch (Exception e) {
        // then just throw back the exception and don't remove the session instance.
        if (this.isApplicationException(statefulComponent, e.getClass(), context.getMethod()) && this.retainIfException) {
            throw e;
        }
        // otherwise, just remove it and throw back the original exception
        final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
        final SessionID sessionId = statefulComponentInstance.getId();
        statefulComponent.removeSession(sessionId);
        throw e;
    }
    final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
    final SessionID sessionId = statefulComponentInstance.getId();
    // just remove the session because of a call to @Remove method
    statefulComponent.removeSession(sessionId);
    // return the invocation result
    return invocationResult;
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) ComponentInstance(org.jboss.as.ee.component.ComponentInstance) Ejb2xViewType(org.jboss.as.ejb3.component.Ejb2xViewType) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) Component(org.jboss.as.ee.component.Component) SessionID(org.jboss.ejb.client.SessionID)

Aggregations

ComponentView (org.jboss.as.ee.component.ComponentView)24 ManagedReference (org.jboss.as.naming.ManagedReference)7 Method (java.lang.reflect.Method)6 Component (org.jboss.as.ee.component.Component)6 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)6 EjbDeploymentInformation (org.jboss.as.ejb3.deployment.EjbDeploymentInformation)4 HashMap (java.util.HashMap)3 MethodIntf (org.jboss.as.ejb3.component.MethodIntf)3 InterceptorContext (org.jboss.invocation.InterceptorContext)3 IOException (java.io.IOException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 HashSet (java.util.HashSet)2 NamingException (javax.naming.NamingException)2 StartupCountdown (org.jboss.as.ee.component.deployers.StartupCountdown)2 CancellationFlag (org.jboss.as.ejb3.component.interceptors.CancellationFlag)2 DeploymentModuleIdentifier (org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier)2 ModuleDeployment (org.jboss.as.ejb3.deployment.ModuleDeployment)2 SessionID (org.jboss.ejb.client.SessionID)2 InjectedValue (org.jboss.msc.value.InjectedValue)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1