Search in sources :

Example 1 with ViewService

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

the class ComponentInstallProcessor method deployComponent.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void deployComponent(final DeploymentPhaseContext phaseContext, final ComponentConfiguration configuration, final List<ServiceName> jndiDependencies, final ServiceName bindingDependencyService) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    final String applicationName = configuration.getApplicationName();
    final String moduleName = configuration.getModuleName();
    final String componentName = configuration.getComponentName();
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    //create additional injectors
    final ServiceName createServiceName = configuration.getComponentDescription().getCreateServiceName();
    final ServiceName startServiceName = configuration.getComponentDescription().getStartServiceName();
    final BasicComponentCreateService createService = configuration.getComponentCreateServiceFactory().constructService(configuration);
    final ServiceBuilder<Component> createBuilder = serviceTarget.addService(createServiceName, createService);
    // inject the DU
    createBuilder.addDependency(deploymentUnit.getServiceName(), DeploymentUnit.class, createService.getDeploymentUnitInjector());
    final ComponentStartService startService = new ComponentStartService();
    final ServiceBuilder<Component> startBuilder = serviceTarget.addService(startServiceName, startService);
    deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_COMPLETE_SERVICES, startServiceName);
    //WFLY-1402 we don't add the bindings to the jndi dependencies list directly, instead
    //the bindings depend on the this artificial service
    ServiceName jndiDepServiceName = configuration.getComponentDescription().getServiceName().append(JNDI_BINDINGS_SERVICE);
    final ServiceBuilder<Void> jndiDepServiceBuilder = serviceTarget.addService(jndiDepServiceName, Service.NULL);
    jndiDependencies.add(jndiDepServiceName);
    // Add all service dependencies
    for (DependencyConfigurator configurator : configuration.getCreateDependencies()) {
        configurator.configureDependency(createBuilder, createService);
    }
    for (DependencyConfigurator configurator : configuration.getStartDependencies()) {
        configurator.configureDependency(startBuilder, startService);
    }
    // START depends on CREATE
    startBuilder.addDependency(createServiceName, BasicComponent.class, startService.getComponentInjector());
    Services.addServerExecutorDependency(startBuilder, startService.getExecutorInjector(), false);
    //don't start components until all bindings are up
    startBuilder.addDependency(bindingDependencyService);
    final ServiceName contextServiceName;
    //set up the naming context if necessary
    if (configuration.getComponentDescription().getNamingMode() == ComponentNamingMode.CREATE) {
        final NamingStoreService contextService = new NamingStoreService(true);
        serviceTarget.addService(configuration.getComponentDescription().getContextServiceName(), contextService).install();
    }
    final InjectionSource.ResolutionContext resolutionContext = new InjectionSource.ResolutionContext(configuration.getComponentDescription().getNamingMode() == ComponentNamingMode.USE_MODULE, configuration.getComponentName(), configuration.getModuleName(), configuration.getApplicationName());
    // Iterate through each view, creating the services for each
    for (ViewConfiguration viewConfiguration : configuration.getViews()) {
        final ServiceName serviceName = viewConfiguration.getViewServiceName();
        final ViewService viewService = new ViewService(viewConfiguration);
        final ServiceBuilder<ComponentView> componentViewServiceBuilder = serviceTarget.addService(serviceName, viewService);
        componentViewServiceBuilder.addDependency(createServiceName, Component.class, viewService.getComponentInjector());
        for (final DependencyConfigurator<ViewService> depConfig : viewConfiguration.getDependencies()) {
            depConfig.configureDependency(componentViewServiceBuilder, viewService);
        }
        componentViewServiceBuilder.install();
        startBuilder.addDependency(serviceName);
        // The bindings for the view
        for (BindingConfiguration bindingConfiguration : viewConfiguration.getBindingConfigurations()) {
            final String bindingName = bindingConfiguration.getName();
            final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(applicationName, moduleName, componentName, bindingName);
            final BinderService service = new BinderService(bindInfo.getBindName(), bindingConfiguration.getSource());
            //these bindings should never be merged, if a view binding is duplicated it is an error
            jndiDepServiceBuilder.addDependency(bindInfo.getBinderServiceName());
            ServiceBuilder<ManagedReferenceFactory> serviceBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), service);
            bindingConfiguration.getSource().getResourceValue(resolutionContext, serviceBuilder, phaseContext, service.getManagedObjectInjector());
            serviceBuilder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, service.getNamingStoreInjector());
            serviceBuilder.install();
        }
    }
    if (configuration.getComponentDescription().getNamingMode() == ComponentNamingMode.CREATE) {
        // The bindings for the component
        final Set<ServiceName> bound = new HashSet<ServiceName>();
        processBindings(phaseContext, configuration, serviceTarget, resolutionContext, configuration.getComponentDescription().getBindingConfigurations(), jndiDepServiceBuilder, bound);
        //class level bindings should be ignored if the deployment is metadata complete
        if (!MetadataCompleteMarker.isMetadataComplete(phaseContext.getDeploymentUnit())) {
            // The bindings for the component class
            new ClassDescriptionTraversal(configuration.getComponentClass(), applicationClasses) {

                @Override
                protected void handle(final Class<?> clazz, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
                    if (classDescription != null) {
                        processBindings(phaseContext, configuration, serviceTarget, resolutionContext, classDescription.getBindingConfigurations(), jndiDepServiceBuilder, bound);
                    }
                }
            }.run();
            for (InterceptorDescription interceptor : configuration.getComponentDescription().getAllInterceptors()) {
                final Class<?> interceptorClass;
                try {
                    interceptorClass = module.getClassLoader().loadClass(interceptor.getInterceptorClassName());
                } catch (ClassNotFoundException e) {
                    throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, interceptor.getInterceptorClassName(), configuration.getComponentClass());
                }
                if (interceptorClass != null) {
                    new ClassDescriptionTraversal(interceptorClass, applicationClasses) {

                        @Override
                        protected void handle(final Class<?> clazz, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
                            if (classDescription != null) {
                                processBindings(phaseContext, configuration, serviceTarget, resolutionContext, classDescription.getBindingConfigurations(), jndiDepServiceBuilder, bound);
                            }
                        }
                    }.run();
                }
            }
        }
    }
    createBuilder.install();
    startBuilder.install();
    jndiDepServiceBuilder.install();
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) ClassDescriptionTraversal(org.jboss.as.ee.component.ClassDescriptionTraversal) NamingStoreService(org.jboss.as.naming.service.NamingStoreService) BinderService(org.jboss.as.naming.service.BinderService) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) InterceptorDescription(org.jboss.as.ee.component.InterceptorDescription) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) BasicComponent(org.jboss.as.ee.component.BasicComponent) Component(org.jboss.as.ee.component.Component) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) ComponentStartService(org.jboss.as.ee.component.ComponentStartService) ContextNames(org.jboss.as.naming.deployment.ContextNames) HashSet(java.util.HashSet) ServiceTarget(org.jboss.msc.service.ServiceTarget) ViewService(org.jboss.as.ee.component.ViewService) BasicComponentCreateService(org.jboss.as.ee.component.BasicComponentCreateService) ComponentView(org.jboss.as.ee.component.ComponentView) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) ServiceName(org.jboss.msc.service.ServiceName) InjectionSource(org.jboss.as.ee.component.InjectionSource) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 2 with ViewService

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

the class SessionBeanHomeProcessor method configureHome.

private void configureHome(final DeploymentPhaseContext phaseContext, final ComponentDescription componentDescription, final SessionBeanComponentDescription ejbComponentDescription, final EJBViewDescription homeView, final EJBViewDescription ejbObjectView) {
    homeView.getConfigurators().add(new ViewConfigurator() {

        @Override
        public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
            configuration.addClientPostConstructInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
            configuration.addClientPreDestroyInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
            //loop over methods looking for create methods:
            for (Method method : configuration.getProxyFactory().getCachedMethods()) {
                if (method.getName().startsWith("create")) {
                    //we have a create method
                    if (ejbObjectView == null) {
                        throw EjbLogger.ROOT_LOGGER.invalidEjbLocalInterface(componentDescription.getComponentName());
                    }
                    Method initMethod = resolveInitMethod(ejbComponentDescription, method);
                    final SessionBeanHomeInterceptorFactory factory = new SessionBeanHomeInterceptorFactory(initMethod);
                    //add a dependency on the view to create
                    configuration.getDependencies().add(new DependencyConfigurator<ViewService>() {

                        @Override
                        public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ViewService service) throws DeploymentUnitProcessingException {
                            serviceBuilder.addDependency(ejbObjectView.getServiceName(), ComponentView.class, factory.getViewToCreate());
                        }
                    });
                    //add the interceptor
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                } else if (method.getName().equals("getEJBMetaData") && method.getParameterTypes().length == 0 && ((EJBViewDescription) description).getMethodIntf() == MethodIntf.HOME) {
                    final Class<?> ejbObjectClass;
                    try {
                        ejbObjectClass = ClassLoadingUtils.loadClass(ejbObjectView.getViewClassName(), context.getDeploymentUnit());
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getComponentName());
                    }
                    final EjbMetadataInterceptor factory = new EjbMetadataInterceptor(ejbObjectClass, configuration.getViewClass().asSubclass(EJBHome.class), null, true, componentDescription instanceof StatelessComponentDescription);
                    //add a dependency on the view to create
                    componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

                        @Override
                        public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
                            serviceBuilder.addDependency(configuration.getViewServiceName(), ComponentView.class, factory.getHomeView());
                        }
                    });
                    //add the interceptor
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(factory), InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                } else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Object.class) {
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, InvalidRemoveExceptionMethodInterceptor.FACTORY, InterceptorOrder.View.INVALID_METHOD_EXCEPTION);
                } else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Handle.class) {
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, HomeRemoveInterceptor.FACTORY, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                }
            }
        }
    });
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EJBHome(javax.ejb.EJBHome) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) Method(java.lang.reflect.Method) ViewService(org.jboss.as.ee.component.ViewService) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) Handle(javax.ejb.Handle) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) SessionBeanHomeInterceptorFactory(org.jboss.as.ejb3.component.interceptors.SessionBeanHomeInterceptorFactory) ComponentView(org.jboss.as.ee.component.ComponentView) StatelessComponentDescription(org.jboss.as.ejb3.component.stateless.StatelessComponentDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) EjbMetadataInterceptor(org.jboss.as.ejb3.component.interceptors.EjbMetadataInterceptor) ComponentStartService(org.jboss.as.ee.component.ComponentStartService)

Aggregations

ComponentStartService (org.jboss.as.ee.component.ComponentStartService)2 ComponentView (org.jboss.as.ee.component.ComponentView)2 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)2 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)2 ViewService (org.jboss.as.ee.component.ViewService)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 EJBHome (javax.ejb.EJBHome)1 Handle (javax.ejb.Handle)1 BasicComponent (org.jboss.as.ee.component.BasicComponent)1 BasicComponentCreateService (org.jboss.as.ee.component.BasicComponentCreateService)1 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)1 ClassDescriptionTraversal (org.jboss.as.ee.component.ClassDescriptionTraversal)1 Component (org.jboss.as.ee.component.Component)1 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)1 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)1 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)1 InjectionSource (org.jboss.as.ee.component.InjectionSource)1 InterceptorDescription (org.jboss.as.ee.component.InterceptorDescription)1