Search in sources :

Example 6 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project keycloak by keycloak.

the class KeycloakClusteredSsoDeploymentProcessor method addCacheDependency.

private void addCacheDependency(DeploymentPhaseContext context, DeploymentUnit deploymentUnit, String cacheContainer, String cacheName) {
    ServiceName wf10CacheContainerServiceName = ServiceName.of("jboss", "infinispan", cacheContainer);
    final ServiceController<?> wf10CacheContainerService = context.getServiceRegistry().getService(wf10CacheContainerServiceName);
    boolean legacy = wf10CacheContainerService != null;
    ServiceTarget st = context.getServiceTarget();
    if (legacy) {
        ServiceName cacheServiceName = wf10CacheContainerServiceName.append(cacheName);
        ServiceController<?> cacheService = context.getServiceRegistry().getService(cacheServiceName);
        if (cacheService != null) {
            st.addDependency(cacheServiceName);
        }
    } else {
        CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        ServiceName cacheServiceName = support.getCapabilityServiceName("org.wildfly.clustering.infinispan.cache." + cacheContainer + "." + cacheName);
        ServiceController<?> cacheService = context.getServiceRegistry().getService(cacheServiceName);
        if (cacheService != null) {
            st.addDependency(cacheServiceName);
        }
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport)

Example 7 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class RaOperationUtil method installRaServicesAndDeployFromModule.

public static void installRaServicesAndDeployFromModule(OperationContext context, String name, ModifiableResourceAdapter resourceAdapter, String fullModuleName, final List<ServiceController<?>> newControllers) throws OperationFailedException {
    ServiceName raServiceName = installRaServices(context, name, resourceAdapter, newControllers);
    final boolean resolveProperties = true;
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final String moduleName;
    final CapabilityServiceSupport support = context.getCapabilityServiceSupport();
    // load module
    String slot = "main";
    if (fullModuleName.contains(":")) {
        slot = fullModuleName.substring(fullModuleName.indexOf(":") + 1);
        moduleName = fullModuleName.substring(0, fullModuleName.indexOf(":"));
    } else {
        moduleName = fullModuleName;
    }
    Module module;
    try {
        ModuleIdentifier moduleId = ModuleIdentifier.create(moduleName, slot);
        module = Module.getCallerModuleLoader().loadModule(moduleId);
    } catch (ModuleNotFoundException e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.raModuleNotFound(moduleName, e.getMessage()), e);
    } catch (ModuleLoadException e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
    }
    URL path = module.getExportedResource("META-INF/ra.xml");
    Closeable closable = null;
    try {
        VirtualFile child;
        if (path.getPath().contains("!")) {
            throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.compressedRarNotSupportedInModuleRA(moduleName));
        } else {
            child = VFS.getChild(path.getPath().split("META-INF")[0]);
            closable = VFS.mountReal(new File(path.getPath().split("META-INF")[0]), child);
        }
        // final Closeable closable = VFS.mountZip((InputStream) new JarInputStream(new FileInputStream(path.getPath().split("!")[0].split(":")[1])), path.getPath().split("!")[0].split(":")[1], child, TempFileProviderService.provider());
        final MountHandle mountHandle = new MountHandle(closable);
        final ResourceRoot resourceRoot = new ResourceRoot(child, mountHandle);
        final VirtualFile deploymentRoot = resourceRoot.getRoot();
        if (deploymentRoot == null || !deploymentRoot.exists())
            return;
        ConnectorXmlDescriptor connectorXmlDescriptor = RaDeploymentParsingProcessor.process(resolveProperties, deploymentRoot, null, name);
        IronJacamarXmlDescriptor ironJacamarXmlDescriptor = IronJacamarDeploymentParsingProcessor.process(deploymentRoot, resolveProperties);
        RaNativeProcessor.process(deploymentRoot);
        Map<ResourceRoot, Index> annotationIndexes = new HashMap<ResourceRoot, Index>();
        ResourceRootIndexer.indexResourceRoot(resourceRoot);
        Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX);
        if (index != null) {
            annotationIndexes.put(resourceRoot, index);
        }
        if (ironJacamarXmlDescriptor != null) {
            ConnectorLogger.SUBSYSTEM_RA_LOGGER.forceIJToNull();
            ironJacamarXmlDescriptor = null;
        }
        final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName());
        final ServiceController<?> deployerService = context.getServiceRegistry(true).getService(deployerServiceName);
        if (deployerService == null) {
            ServiceBuilder builder = ParsedRaDeploymentProcessor.process(connectorXmlDescriptor, ironJacamarXmlDescriptor, module.getClassLoader(), serviceTarget, annotationIndexes, RAR_MODULE.append(name), null, null, support);
            builder.requires(raServiceName);
            newControllers.add(builder.setInitialMode(ServiceController.Mode.ACTIVE).install());
        }
        String rarName = resourceAdapter.getArchive();
        if (fullModuleName.equals(rarName)) {
            ServiceName serviceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(name);
            InactiveResourceAdapterDeploymentService service = new InactiveResourceAdapterDeploymentService(connectorXmlDescriptor, module, name, name, RAR_MODULE.append(name), null, serviceTarget, null);
            newControllers.add(serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).install());
        }
    } catch (Exception e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
    } finally {
        if (closable != null) {
            try {
                closable.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) VirtualFile(org.jboss.vfs.VirtualFile) HashMap(java.util.HashMap) Closeable(java.io.Closeable) ConnectorXmlDescriptor(org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor) Index(org.jboss.jandex.Index) URL(java.net.URL) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) InactiveResourceAdapterDeploymentService(org.jboss.as.connector.services.resourceadapters.deployment.InactiveResourceAdapterDeploymentService) ModuleNotFoundException(org.jboss.modules.ModuleNotFoundException) MountHandle(org.jboss.as.server.deployment.module.MountHandle) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) IOException(java.io.IOException) ModuleNotFoundException(org.jboss.modules.ModuleNotFoundException) IOException(java.io.IOException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModuleLoadException(org.jboss.modules.ModuleLoadException) ValidateException(org.jboss.jca.common.api.validator.ValidateException) ServiceName(org.jboss.msc.service.ServiceName) IronJacamarXmlDescriptor(org.jboss.as.connector.metadata.xmldescriptors.IronJacamarXmlDescriptor) Module(org.jboss.modules.Module) File(java.io.File) VirtualFile(org.jboss.vfs.VirtualFile)

Example 8 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class EJBClientDescriptorMetaDataProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    // we only process top level deployment units
    if (deploymentUnit.getParent() != null) {
        return;
    }
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (module == null) {
        return;
    }
    // support for using capabilities to resolve service names
    CapabilityServiceSupport capabilityServiceSupport = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
    // check for EJB client interceptor configuration
    final List<EJBClientInterceptor> deploymentEjbClientInterceptors = getClassPathInterceptors(module.getClassLoader());
    List<EJBClientInterceptor> staticEjbClientInterceptors = deploymentUnit.getAttachment(org.jboss.as.ejb3.subsystem.Attachments.STATIC_EJB_CLIENT_INTERCEPTORS);
    List<EJBClientInterceptor> ejbClientInterceptors = new ArrayList<>();
    if (deploymentEjbClientInterceptors != null) {
        ejbClientInterceptors.addAll(deploymentEjbClientInterceptors);
    }
    if (staticEjbClientInterceptors != null) {
        ejbClientInterceptors.addAll(staticEjbClientInterceptors);
    }
    final boolean interceptorsDefined = ejbClientInterceptors != null && !ejbClientInterceptors.isEmpty();
    final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = deploymentUnit.getAttachment(Attachments.EJB_CLIENT_METADATA);
    // no explicit EJB client configuration in this deployment, so nothing to do
    if (ejbClientDescriptorMetaData == null && !interceptorsDefined) {
        return;
    }
    // install the descriptor based EJB client context service
    final ServiceName ejbClientContextServiceName = EJBClientContextService.DEPLOYMENT_BASE_SERVICE_NAME.append(deploymentUnit.getName());
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    // create the service
    final EJBClientContextService service = new EJBClientContextService();
    // add the service
    final ServiceBuilder<EJBClientContextService> serviceBuilder = serviceTarget.addService(ejbClientContextServiceName, service);
    if (appclient) {
        serviceBuilder.addDependency(EJBClientContextService.APP_CLIENT_URI_SERVICE_NAME, URI.class, service.getAppClientUri());
        serviceBuilder.addDependency(EJBClientContextService.APP_CLIENT_EJB_PROPERTIES_SERVICE_NAME, String.class, service.getAppClientEjbProperties());
    }
    // default transport providers: remote from config, local from service, in "else" below.
    serviceBuilder.addDependency(EJBClientConfiguratorService.SERVICE_NAME, EJBClientConfiguratorService.class, service.getConfiguratorServiceInjector());
    if (ejbClientDescriptorMetaData != null) {
        // profile and remoting-ejb-receivers cannot be used together
        checkDescriptorConfiguration(ejbClientDescriptorMetaData);
        final Injector<RemotingProfileService> profileServiceInjector = new Injector<RemotingProfileService>() {

            final Injector<EJBTransportProvider> injector = service.getLocalProviderInjector();

            boolean injected = false;

            public void inject(final RemotingProfileService value) throws InjectionException {
                final EJBTransportProvider provider = value.getLocalTransportProviderInjector().getOptionalValue();
                if (provider != null) {
                    injected = true;
                    injector.inject(provider);
                }
            }

            public void uninject() {
                if (injected) {
                    injected = false;
                    injector.uninject();
                }
            }
        };
        final String profile = ejbClientDescriptorMetaData.getProfile();
        final ServiceName profileServiceName;
        if (profile != null) {
            // set up a service for the named remoting profile
            profileServiceName = capabilityServiceSupport.getCapabilityServiceName(REMOTING_PROFILE_CAPABILITY_NAME, profile);
            // why below?
            serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, profileServiceInjector);
            serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, service.getProfileServiceInjector());
        } else {
            // if descriptor defines list of ejb-receivers instead of profile then we create internal ProfileService for this
            // application which contains defined receivers
            profileServiceName = ejbClientContextServiceName.append(INTERNAL_REMOTING_PROFILE);
            final Map<String, RemotingProfileService.RemotingConnectionSpec> remotingConnectionMap = new HashMap<>();
            final List<RemotingProfileService.HttpConnectionSpec> httpConnections = new ArrayList<>();
            final RemotingProfileService profileService = new RemotingProfileService(Collections.emptyList(), remotingConnectionMap, httpConnections);
            final ServiceBuilder<RemotingProfileService> profileServiceBuilder = serviceTarget.addService(profileServiceName, profileService);
            if (ejbClientDescriptorMetaData.isLocalReceiverExcluded() != Boolean.TRUE) {
                final Boolean passByValue = ejbClientDescriptorMetaData.isLocalReceiverPassByValue();
                profileServiceBuilder.addDependency(passByValue == Boolean.FALSE ? LocalTransportProvider.BY_REFERENCE_SERVICE_NAME : LocalTransportProvider.BY_VALUE_SERVICE_NAME, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
            }
            final Collection<EJBClientDescriptorMetaData.RemotingReceiverConfiguration> receiverConfigurations = ejbClientDescriptorMetaData.getRemotingReceiverConfigurations();
            for (EJBClientDescriptorMetaData.RemotingReceiverConfiguration receiverConfiguration : receiverConfigurations) {
                final String connectionRef = receiverConfiguration.getOutboundConnectionRef();
                final long connectTimeout = receiverConfiguration.getConnectionTimeout();
                final Properties channelCreationOptions = receiverConfiguration.getChannelCreationOptions();
                final OptionMap optionMap = getOptionMapFromProperties(channelCreationOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
                final InjectedValue<OutboundConnection> injector = new InjectedValue<>();
                final ServiceName internalServiceName = capabilityServiceSupport.getCapabilityServiceName(OUTBOUND_CONNECTION_CAPABILITY_NAME, connectionRef);
                profileServiceBuilder.addDependency(internalServiceName, OutboundConnection.class, injector);
                final RemotingProfileService.RemotingConnectionSpec connectionSpec = new RemotingProfileService.RemotingConnectionSpec(connectionRef, injector, optionMap, connectTimeout);
                remotingConnectionMap.put(connectionRef, connectionSpec);
            }
            for (EJBClientDescriptorMetaData.HttpConnectionConfiguration httpConfigurations : ejbClientDescriptorMetaData.getHttpConnectionConfigurations()) {
                final String uri = httpConfigurations.getUri();
                RemotingProfileService.HttpConnectionSpec httpConnectionSpec = new RemotingProfileService.HttpConnectionSpec(uri);
                httpConnections.add(httpConnectionSpec);
            }
            profileServiceBuilder.install();
            serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, profileServiceInjector);
            serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, service.getProfileServiceInjector());
        }
        // these items are the same no matter how we were configured
        final String deploymentNodeSelectorClassName = ejbClientDescriptorMetaData.getDeploymentNodeSelector();
        if (deploymentNodeSelectorClassName != null) {
            final DeploymentNodeSelector deploymentNodeSelector;
            try {
                deploymentNodeSelector = module.getClassLoader().loadClass(deploymentNodeSelectorClassName).asSubclass(DeploymentNodeSelector.class).getConstructor().newInstance();
            } catch (Exception e) {
                throw EjbLogger.ROOT_LOGGER.failedToCreateDeploymentNodeSelector(e, deploymentNodeSelectorClassName);
            }
            service.setDeploymentNodeSelector(deploymentNodeSelector);
        }
        final long invocationTimeout = ejbClientDescriptorMetaData.getInvocationTimeout();
        service.setInvocationTimeout(invocationTimeout);
        final int defaultCompression = ejbClientDescriptorMetaData.getDefaultCompression();
        service.setDefaultCompression(defaultCompression);
        // clusters
        final Collection<EJBClientDescriptorMetaData.ClusterConfig> clusterConfigs = ejbClientDescriptorMetaData.getClusterConfigs();
        if (!clusterConfigs.isEmpty()) {
            final List<EJBClientCluster> clientClusters = new ArrayList<>(clusterConfigs.size());
            AuthenticationContext clustersAuthenticationContext = AuthenticationContext.empty();
            for (EJBClientDescriptorMetaData.ClusterConfig clusterConfig : clusterConfigs) {
                MatchRule defaultRule = MatchRule.ALL.matchAbstractType("ejb", "jboss");
                AuthenticationConfiguration defaultAuthenticationConfiguration = AuthenticationConfiguration.EMPTY;
                final EJBClientCluster.Builder clientClusterBuilder = new EJBClientCluster.Builder();
                final String clusterName = clusterConfig.getClusterName();
                clientClusterBuilder.setName(clusterName);
                defaultRule = defaultRule.matchProtocol("cluster");
                defaultRule = defaultRule.matchUrnName(clusterName);
                final long maxAllowedConnectedNodes = clusterConfig.getMaxAllowedConnectedNodes();
                clientClusterBuilder.setMaximumConnectedNodes(maxAllowedConnectedNodes);
                final String clusterNodeSelectorClassName = clusterConfig.getNodeSelector();
                if (clusterNodeSelectorClassName != null) {
                    final ClusterNodeSelector clusterNodeSelector;
                    try {
                        clusterNodeSelector = module.getClassLoader().loadClass(clusterNodeSelectorClassName).asSubclass(ClusterNodeSelector.class).getConstructor().newInstance();
                    } catch (Exception e) {
                        throw EjbLogger.ROOT_LOGGER.failureDuringLoadOfClusterNodeSelector(clusterNodeSelectorClassName, clusterName, e);
                    }
                    clientClusterBuilder.setClusterNodeSelector(clusterNodeSelector);
                }
                final Properties clusterChannelCreationOptions = clusterConfig.getChannelCreationOptions();
                final OptionMap clusterChannelCreationOptionMap = getOptionMapFromProperties(clusterChannelCreationOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
                final Properties clusterConnectionOptions = clusterConfig.getConnectionOptions();
                final OptionMap clusterConnectionOptionMap = getOptionMapFromProperties(clusterConnectionOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
                final long clusterConnectTimeout = clusterConfig.getConnectTimeout();
                clientClusterBuilder.setConnectTimeoutMilliseconds(clusterConnectTimeout);
                if (clusterConnectionOptionMap != null) {
                    RemotingOptions.mergeOptionsIntoAuthenticationConfiguration(clusterConnectionOptionMap, defaultAuthenticationConfiguration);
                }
                clustersAuthenticationContext = clustersAuthenticationContext.with(defaultRule, defaultAuthenticationConfiguration);
                final Collection<EJBClientDescriptorMetaData.ClusterNodeConfig> clusterNodeConfigs = clusterConfig.getClusterNodeConfigs();
                for (EJBClientDescriptorMetaData.ClusterNodeConfig clusterNodeConfig : clusterNodeConfigs) {
                    MatchRule nodeRule = MatchRule.ALL.matchAbstractType("ejb", "jboss");
                    AuthenticationConfiguration nodeAuthenticationConfiguration = AuthenticationConfiguration.EMPTY;
                    final String nodeName = clusterNodeConfig.getNodeName();
                    nodeRule = nodeRule.matchProtocol("node");
                    nodeRule = nodeRule.matchUrnName(nodeName);
                    final Properties channelCreationOptions = clusterNodeConfig.getChannelCreationOptions();
                    final Properties connectionOptions = clusterNodeConfig.getConnectionOptions();
                    final OptionMap connectionOptionMap = getOptionMapFromProperties(connectionOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
                    final long connectTimeout = clusterNodeConfig.getConnectTimeout();
                    if (connectionOptionMap != null) {
                        RemotingOptions.mergeOptionsIntoAuthenticationConfiguration(connectionOptionMap, nodeAuthenticationConfiguration);
                    }
                    clustersAuthenticationContext = clustersAuthenticationContext.with(0, nodeRule, nodeAuthenticationConfiguration);
                }
                final EJBClientCluster clientCluster = clientClusterBuilder.build();
                clientClusters.add(clientCluster);
            }
            service.setClientClusters(clientClusters);
            service.setClustersAuthenticationContext(clustersAuthenticationContext);
        }
        deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_REMOTING_PROFILE_SERVICE_NAME, profileServiceName);
    } else {
        if (!appclient) {
            serviceBuilder.addDependency(LocalTransportProvider.DEFAULT_LOCAL_TRANSPORT_PROVIDER_SERVICE_NAME, EJBTransportProvider.class, service.getLocalProviderInjector());
        }
    }
    if (interceptorsDefined) {
        service.setClientInterceptors(ejbClientInterceptors);
    }
    // install the service
    serviceBuilder.install();
    EjbLogger.DEPLOYMENT_LOGGER.debugf("Deployment unit %s will use %s as the EJB client context service", deploymentUnit, ejbClientContextServiceName);
    // attach the service name of this EJB client context to the deployment unit
    phaseContext.addDeploymentDependency(ejbClientContextServiceName, EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE);
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE_NAME, ejbClientContextServiceName);
}
Also used : EJBClientInterceptor(org.jboss.ejb.client.EJBClientInterceptor) InjectedValue(org.jboss.msc.value.InjectedValue) OutboundConnection(org.jboss.as.network.OutboundConnection) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) HashMap(java.util.HashMap) EJBClientContextService(org.jboss.as.ejb3.remote.EJBClientContextService) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ArrayList(java.util.ArrayList) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ClusterNodeSelector(org.jboss.ejb.client.ClusterNodeSelector) Injector(org.jboss.msc.inject.Injector) RemotingProfileService(org.jboss.as.ejb3.remote.RemotingProfileService) ServiceTarget(org.jboss.msc.service.ServiceTarget) ServiceName(org.jboss.msc.service.ServiceName) Module(org.jboss.modules.Module) MatchRule(org.wildfly.security.auth.client.MatchRule) Properties(java.util.Properties) DeploymentNodeSelector(org.jboss.ejb.client.DeploymentNodeSelector) EJBClientDescriptorMetaData(org.jboss.as.ee.metadata.EJBClientDescriptorMetaData) EJBClientCluster(org.jboss.ejb.client.EJBClientCluster) AuthenticationConfiguration(org.wildfly.security.auth.client.AuthenticationConfiguration) InjectionException(org.jboss.msc.inject.InjectionException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) IOException(java.io.IOException) EJBTransportProvider(org.jboss.ejb.client.EJBTransportProvider) OptionMap(org.xnio.OptionMap) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 9 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class CacheDependenciesProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext context) {
    DeploymentUnit unit = context.getDeploymentUnit();
    final ServiceName name = unit.getServiceName();
    EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
        return;
    }
    final CapabilityServiceSupport support = unit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
    final ServiceTarget target = context.getServiceTarget();
    Set<SupplierDependency<CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance>>> dependencies = new HashSet<>();
    for (ComponentDescription description : moduleDescription.getComponentDescriptions()) {
        if (description instanceof StatefulComponentDescription) {
            StatefulComponentDescription statefulDescription = (StatefulComponentDescription) description;
            dependencies.add(new ServiceSupplierDependency<>(getCacheFactoryBuilderServiceName(statefulDescription)));
        }
    }
    Service service = new ChildTargetService(new Consumer<ServiceTarget>() {

        @Override
        public void accept(ServiceTarget target) {
            // Cache factory builder dependencies might still contain duplicates (if referenced via alias), so ensure we collect only distinct instances.
            Set<CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance>> builders = new HashSet<>(dependencies.size());
            for (Supplier<CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance>> dependency : dependencies) {
                builders.add(dependency.get());
            }
            for (CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance> builder : builders) {
                for (CapabilityServiceConfigurator configurator : builder.getDeploymentServiceConfigurators(unit)) {
                    configurator.configure(support).build(target).install();
                }
            }
        }
    });
    ServiceBuilder<?> builder = target.addService(name.append("cache-dependencies-installer"));
    for (Dependency dependency : dependencies) {
        dependency.register(builder);
    }
    builder.setInstance(service).install();
    // Install versioned marshalling configuration
    new MarshallingConfigurationRepositoryServiceConfigurator(unit).build(target).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
}
Also used : StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) HashSet(java.util.HashSet) Set(java.util.Set) StatefulSessionComponentInstance(org.jboss.as.ejb3.component.stateful.StatefulSessionComponentInstance) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) CacheFactoryBuilder(org.jboss.as.ejb3.cache.CacheFactoryBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) Supplier(java.util.function.Supplier) HashSet(java.util.HashSet) CapabilityServiceConfigurator(org.jboss.as.clustering.controller.CapabilityServiceConfigurator) ChildTargetService(org.wildfly.clustering.service.ChildTargetService) ServiceTarget(org.jboss.msc.service.ServiceTarget) MarshallingConfigurationRepositoryServiceConfigurator(org.jboss.as.ejb3.component.stateful.MarshallingConfigurationRepositoryServiceConfigurator) Service(org.jboss.msc.Service) ChildTargetService(org.wildfly.clustering.service.ChildTargetService) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) Dependency(org.wildfly.clustering.service.Dependency) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) ServiceName(org.jboss.msc.service.ServiceName) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SessionID(org.jboss.ejb.client.SessionID)

Example 10 with CapabilityServiceSupport

use of org.jboss.as.controller.capability.CapabilityServiceSupport in project wildfly by wildfly.

the class StatelessComponentDescription method createConfiguration.

@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
    final ComponentConfiguration statelessComponentConfiguration = new ComponentConfiguration(this, classIndex, moduleClassLoader, moduleLoader);
    // setup the component create service
    statelessComponentConfiguration.setComponentCreateServiceFactory(new StatelessComponentCreateServiceFactory());
    // setup the configurator to inject the PoolConfig in the StatelessSessionComponentCreateService
    final StatelessComponentDescription statelessComponentDescription = (StatelessComponentDescription) statelessComponentConfiguration.getComponentDescription();
    // setup a configurator to inject the PoolConfig in the StatelessSessionComponentCreateService
    getConfigurators().add(new ComponentConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
            // get CapabilitySupport to resolve service names
            final CapabilityServiceSupport support = context.getDeploymentUnit().getAttachment(CAPABILITY_SERVICE_SUPPORT);
            configuration.getCreateDependencies().add(new DependencyConfigurator<Service<Component>>() {

                @Override
                public void configureDependency(ServiceBuilder<?> serviceBuilder, Service<Component> service) throws DeploymentUnitProcessingException {
                    final StatelessSessionComponentCreateService statelessSessionComponentCreateService = (StatelessSessionComponentCreateService) service;
                    final String poolName = statelessComponentDescription.getPoolConfigName();
                    // If the default slsb pool config itself is not configured, then the pooling is disabled for the bean
                    if (poolName == null) {
                        if (statelessComponentDescription.isDefaultSlsbPoolAvailable()) {
                            ServiceName defaultPoolConfigServiceName = support.getCapabilityServiceName(DEFAULT_SLSB_POOL_CONFIG_CAPABILITY_NAME);
                            serviceBuilder.addDependency(defaultPoolConfigServiceName, PoolConfig.class, statelessSessionComponentCreateService.getPoolConfigInjector());
                        }
                    } else {
                        // pool name has been explicitly set so the pool config is a required dependency
                        ServiceName poolConfigServiceName = support.getCapabilityServiceName(STRICT_MAX_POOL_CONFIG_CAPABILITY_NAME, poolName);
                        serviceBuilder.addDependency(poolConfigServiceName, PoolConfig.class, statelessSessionComponentCreateService.getPoolConfigInjector());
                    }
                }
            });
        }
    });
    // add the bmt interceptor
    if (TransactionManagementType.BEAN.equals(this.getTransactionManagementType())) {
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                // add the bmt interceptor factory
                configuration.addComponentInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.Component.BMT_TRANSACTION_INTERCEPTOR, false);
            }
        });
    }
    getConfigurators().add(new ComponentConfigurator() {

        @Override
        public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
            if (TransactionManagementType.CONTAINER.equals(getTransactionManagementType())) {
                final EEApplicationClasses applicationClasses = context.getDeploymentUnit().getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
                InterceptorClassDescription interceptorConfig = ComponentDescription.mergeInterceptorConfig(configuration.getComponentClass(), applicationClasses.getClassByName(description.getComponentClassName()), description, MetadataCompleteMarker.isMetadataComplete(context.getDeploymentUnit()));
                configuration.addPostConstructInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPostConstruct(), true), InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
                configuration.addPreDestroyInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPreDestroy(), true), InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
                configuration.addTimeoutViewInterceptor(TimerCMTTxInterceptor.FACTORY, InterceptorOrder.View.CMT_TRANSACTION_INTERCEPTOR);
            }
            configuration.addTimeoutViewInterceptor(StatelessComponentInstanceAssociatingFactory.instance(), InterceptorOrder.View.ASSOCIATING_INTERCEPTOR);
        }
    });
    return statelessComponentConfiguration;
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) Service(org.jboss.msc.service.Service) ComponentTypeIdentityInterceptorFactory(org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory) StatelessRemoteViewInstanceFactory(org.jboss.as.ejb3.component.session.StatelessRemoteViewInstanceFactory) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) ServiceName(org.jboss.msc.service.ServiceName) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) Component(org.jboss.as.ee.component.Component)

Aggregations

CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)76 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)39 ServiceName (org.jboss.msc.service.ServiceName)38 ServiceTarget (org.jboss.msc.service.ServiceTarget)25 WeldCapability (org.jboss.as.weld.WeldCapability)19 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)18 Module (org.jboss.modules.Module)16 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)14 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)10 HashMap (java.util.HashMap)9 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)9 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)8 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)8 ValidatorFactory (javax.validation.ValidatorFactory)7 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)7 HashSet (java.util.HashSet)6 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)6 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)6 ModelNode (org.jboss.dmr.ModelNode)6 ModuleLoader (org.jboss.modules.ModuleLoader)6