Search in sources :

Example 46 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class DirectAdminObjectActivatorService method start.

@Override
public void start(StartContext context) throws StartException {
    ROOT_LOGGER.debugf("started DirectConnectionFactoryActivatorService %s", context.getController().getName());
    String aoClass = null;
    try {
        Connector cmd = mdr.getValue().getResourceAdapter(raId);
        if (cmd.getVersion() == Connector.Version.V_10) {
            throw ConnectorLogger.ROOT_LOGGER.adminObjectForJCA10(resourceAdapter, jndiName);
        } else {
            ResourceAdapter ra1516 = (ResourceAdapter) cmd.getResourceadapter();
            if (ra1516.getAdminObjects() != null) {
                for (AdminObject ao : ra1516.getAdminObjects()) {
                    if (ao.getAdminobjectClass().getValue().equals(className))
                        aoClass = ao.getAdminobjectClass().getValue();
                }
            }
        }
        if (aoClass == null || !aoClass.equals(className)) {
            throw ConnectorLogger.ROOT_LOGGER.invalidAdminObject(aoClass, resourceAdapter, jndiName);
        }
        Map<String, String> raConfigProperties = new HashMap<String, String>();
        Map<String, String> aoConfigProperties = new HashMap<String, String>();
        if (properties != null) {
            for (Map.Entry<String, String> prop : properties.entrySet()) {
                String key = prop.getKey();
                String value = prop.getValue();
                if (key.startsWith("ra.")) {
                    raConfigProperties.put(key.substring(3), value);
                } else if (key.startsWith("ao.")) {
                    aoConfigProperties.put(key.substring(3), value);
                } else {
                    aoConfigProperties.put(key, value);
                }
            }
        }
        org.jboss.jca.common.api.metadata.resourceadapter.AdminObject ao = new AdminObjectImpl(aoConfigProperties, aoClass, jndiName, poolName(aoClass, className), Boolean.TRUE, Boolean.TRUE);
        Activation activation = new ActivationImpl(null, null, TransactionSupportEnum.LocalTransaction, Collections.<ConnectionDefinition>emptyList(), Collections.singletonList(ao), null, Collections.<String>emptyList(), null, null);
        String serviceName = jndiName;
        serviceName = serviceName.replace(':', '_');
        serviceName = serviceName.replace('/', '_');
        ResourceAdapterActivatorService activator = new ResourceAdapterActivatorService(cmd, activation, module.getClassLoader(), serviceName);
        activator.setCreateBinderService(false);
        activator.setBindInfo(bindInfo);
        ServiceTarget serviceTarget = context.getChildTarget();
        ServiceBuilder adminObjectServiceBuilder = serviceTarget.addService(ConnectorServices.RESOURCE_ADAPTER_ACTIVATOR_SERVICE.append(serviceName), activator).addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, activator.getMdrInjector()).addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, activator.getRaRepositoryInjector()).addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, activator.getManagementRepositoryInjector()).addDependency(ConnectorServices.RESOURCE_ADAPTER_REGISTRY_SERVICE, ResourceAdapterDeploymentRegistry.class, activator.getRegistryInjector()).addDependency(ConnectorServices.getCachedCapabilityServiceName(ConnectorServices.TRANSACTION_INTEGRATION_CAPABILITY_NAME), TransactionIntegration.class, activator.getTxIntegrationInjector()).addDependency(ConnectorServices.CONNECTOR_CONFIG_SERVICE, JcaSubsystemConfiguration.class, activator.getConfigInjector()).addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, activator.getCcmInjector());
        adminObjectServiceBuilder.requires(ConnectorServices.getCachedCapabilityServiceName(NamingService.CAPABILITY_NAME));
        adminObjectServiceBuilder.requires(ConnectorServices.getCachedCapabilityServiceName(ConnectorServices.LOCAL_TRANSACTION_PROVIDER_CAPABILITY));
        adminObjectServiceBuilder.requires(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append("default"));
        adminObjectServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    } catch (Exception e) {
        throw new StartException(e);
    }
}
Also used : Connector(org.jboss.jca.common.api.metadata.spec.Connector) HashMap(java.util.HashMap) JcaSubsystemConfiguration(org.jboss.as.connector.subsystems.jca.JcaSubsystemConfiguration) ServiceTarget(org.jboss.msc.service.ServiceTarget) AdminObjectImpl(org.jboss.jca.common.metadata.resourceadapter.AdminObjectImpl) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) StartException(org.jboss.msc.service.StartException) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ActivationImpl(org.jboss.jca.common.metadata.resourceadapter.ActivationImpl) ResourceAdapter(org.jboss.jca.common.api.metadata.spec.ResourceAdapter) ResourceAdapterRepository(org.jboss.jca.core.spi.rar.ResourceAdapterRepository) StartException(org.jboss.msc.service.StartException) AdminObject(org.jboss.jca.common.api.metadata.spec.AdminObject) HashMap(java.util.HashMap) Map(java.util.Map) ResourceAdapterDeploymentRegistry(org.jboss.as.connector.services.resourceadapters.deployment.registry.ResourceAdapterDeploymentRegistry)

Example 47 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class MessageDrivenComponentDescription method createConfiguration.

@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
    final ComponentConfiguration mdbComponentConfiguration = new ComponentConfiguration(this, classIndex, moduleClassLoader, moduleLoader);
    // setup the component create service
    final Class<?> messageListenerInterface;
    try {
        messageListenerInterface = Class.forName(getMessageListenerInterfaceName(), true, moduleClassLoader);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    mdbComponentConfiguration.setComponentCreateServiceFactory(new MessageDrivenComponentCreateServiceFactory(messageListenerInterface));
    final MessageDrivenComponentDescription mdbComponentDescription = (MessageDrivenComponentDescription) mdbComponentConfiguration.getComponentDescription();
    // setup a configurator to inject the PoolConfig in the MessageDrivenComponentCreateService
    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);
            MessageDrivenComponentDescription mdbDescription = (MessageDrivenComponentDescription) description;
            configuration.getCreateDependencies().add(new DependencyConfigurator<Service<Component>>() {

                @Override
                public void configureDependency(ServiceBuilder<?> serviceBuilder, Service<Component> service) throws DeploymentUnitProcessingException {
                    // add any dependencies here
                    final MessageDrivenComponentCreateService mdbComponentCreateService = (MessageDrivenComponentCreateService) service;
                    final String poolName = mdbComponentDescription.getPoolConfigName();
                    // If the default mdb pool config itself is not configured, then pooling is disabled for the bean
                    if (poolName == null) {
                        if (mdbComponentDescription.isDefaultMdbPoolAvailable()) {
                            ServiceName defaultPoolConfigServiceName = support.getCapabilityServiceName(DEFAULT_MDB_POOL_CONFIG_CAPABILITY_NAME);
                            serviceBuilder.addDependency(defaultPoolConfigServiceName, PoolConfig.class, mdbComponentCreateService.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, mdbComponentCreateService.getPoolConfigInjector());
                    }
                }
            });
        }
    });
    // set up a configurator to inject ResourceAdapterService dependencies into the MessageDrivenComponentCreateService
    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<MessageDrivenComponentCreateService>() {

                @Override
                public void configureDependency(ServiceBuilder<?> serviceBuilder, MessageDrivenComponentCreateService service) throws DeploymentUnitProcessingException {
                    final ServiceName raServiceName = ConnectorServices.getResourceAdapterServiceName(MessageDrivenComponentDescription.this.resourceAdapterName);
                    // add the dependency on the RA service
                    serviceBuilder.addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, service.getResourceAdapterRepositoryInjector());
                    serviceBuilder.addDependency(raServiceName, ResourceAdapter.class, service.getResourceAdapterInjector());
                }
            });
        }
    });
    getConfigurators().add(new ComponentConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
            final ServiceName suspendControllerName = context.getDeploymentUnit().getAttachment(CAPABILITY_SERVICE_SUPPORT).getCapabilityServiceName("org.wildfly.server.suspend-controller");
            configuration.getCreateDependencies().add(new DependencyConfigurator<MessageDrivenComponentCreateService>() {

                @Override
                public void configureDependency(final ServiceBuilder<?> serviceBuilder, final MessageDrivenComponentCreateService mdbComponentCreateService) throws DeploymentUnitProcessingException {
                    serviceBuilder.addDependency(suspendControllerName, SuspendController.class, mdbComponentCreateService.getSuspendControllerInjectedValue());
                }
            });
        }
    });
    // 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);
            }
        });
    } else {
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                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);
            }
        });
    }
    return mdbComponentConfiguration;
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) 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) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) 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)

Example 48 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class SessionBeanObjectViewConfigurator method configure.

@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
    // note that we don't have to handle all methods on the EJBObject, as some are handled client side
    final DeploymentReflectionIndex index = context.getDeploymentUnit().getAttachment(Attachments.REFLECTION_INDEX);
    for (final Method method : configuration.getProxyFactory().getCachedMethods()) {
        if (method.getName().equals("getPrimaryKey") && method.getParameterCount() == 0) {
            configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
            configuration.addViewInterceptor(method, PRIMARY_KEY_INTERCEPTOR, InterceptorOrder.View.COMPONENT_DISPATCHER);
        } else if (method.getName().equals("remove") && method.getParameterCount() == 0) {
            handleRemoveMethod(componentConfiguration, configuration, index, method);
        } else if (method.getName().equals("getEJBLocalHome") && method.getParameterCount() == 0) {
            configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
            final GetHomeInterceptorFactory factory = new GetHomeInterceptorFactory();
            configuration.addViewInterceptor(method, factory, InterceptorOrder.View.COMPONENT_DISPATCHER);
            final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescription) componentConfiguration.getComponentDescription();
            componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

                @Override
                public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
                    EjbHomeViewDescription ejbLocalHomeView = componentDescription.getEjbLocalHomeView();
                    if (ejbLocalHomeView == null) {
                        throw EjbLogger.ROOT_LOGGER.beanLocalHomeInterfaceIsNull(componentDescription.getComponentName());
                    }
                    serviceBuilder.addDependency(ejbLocalHomeView.getServiceName(), ComponentView.class, factory.getViewToCreate());
                }
            });
        } else if (method.getName().equals("getEJBHome") && method.getParameterCount() == 0) {
            configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
            final GetHomeInterceptorFactory factory = new GetHomeInterceptorFactory();
            configuration.addViewInterceptor(method, factory, InterceptorOrder.View.COMPONENT_DISPATCHER);
            final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescription) componentConfiguration.getComponentDescription();
            componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

                @Override
                public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
                    EjbHomeViewDescription ejbHomeView = componentDescription.getEjbHomeView();
                    if (ejbHomeView == null) {
                        throw EjbLogger.ROOT_LOGGER.beanHomeInterfaceIsNull(componentDescription.getComponentName());
                    }
                    serviceBuilder.addDependency(ejbHomeView.getServiceName(), ComponentView.class, factory.getViewToCreate());
                }
            });
        } else if (method.getName().equals("getHandle") && method.getParameterCount() == 0) {
        // ignore, handled client side
        } else if (method.getName().equals("isIdentical") && method.getParameterCount() == 1 && (method.getParameterTypes()[0].equals(EJBObject.class) || method.getParameterTypes()[0].equals(EJBLocalObject.class))) {
            handleIsIdenticalMethod(componentConfiguration, configuration, index, method);
        } else {
            final Method componentMethod = ClassReflectionIndexUtil.findMethod(index, componentConfiguration.getComponentClass(), MethodIdentifier.getIdentifierForMethod(method));
            if (componentMethod != null) {
                if (!Modifier.isPublic(componentMethod.getModifiers())) {
                    EjbLogger.ROOT_LOGGER.ejbBusinessMethodMustBePublic(componentMethod);
                }
                configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)), InterceptorOrder.View.COMPONENT_DISPATCHER);
                configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
            } else if (method.getDeclaringClass() != Object.class && method.getDeclaringClass() != WriteReplaceInterface.class) {
                throw EjbLogger.ROOT_LOGGER.couldNotFindViewMethodOnEjb(method, description.getViewClassName(), componentConfiguration.getComponentName());
            }
        }
        EjbValidationsUtil.verifyMethodIsNotFinalNorStatic(method, index.getClass().getName());
    }
    configuration.addClientPostConstructInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
    configuration.addClientPreDestroyInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) GetHomeInterceptorFactory(org.jboss.as.ejb3.component.interceptors.GetHomeInterceptorFactory) EjbHomeViewDescription(org.jboss.as.ejb3.component.EjbHomeViewDescription) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) Method(java.lang.reflect.Method) WriteReplaceInterface(org.jboss.as.ee.component.serialization.WriteReplaceInterface) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ComponentView(org.jboss.as.ee.component.ComponentView) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) ComponentDispatcherInterceptor(org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor) ComponentStartService(org.jboss.as.ee.component.ComponentStartService)

Example 49 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class BatchEnvironmentProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.hasAttachment(Attachments.MODULE)) {
        BatchLogger.LOGGER.tracef("Processing deployment '%s' for the batch environment.", deploymentUnit.getName());
        // Configure and attach the job resolver for all deployments
        final WildFlyJobXmlResolver jobXmlResolver = WildFlyJobXmlResolver.forDeployment(deploymentUnit);
        // Skip the rest of the processing for EAR's, only sub-deployments need an environment configured
        if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit))
            return;
        // Get the class loader
        final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
        final ClassLoader moduleClassLoader = module.getClassLoader();
        final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
        JobRepository jobRepository = null;
        String jobRepositoryName = null;
        String dataSourceName = null;
        String jobExecutorName = null;
        Boolean restartJobsOnResume = null;
        // Check for a deployment descriptor
        BatchEnvironmentMetaData metaData = deploymentUnit.getAttachment(BatchAttachments.BATCH_ENVIRONMENT_META_DATA);
        if (metaData == null) {
            // Check the parent
            final DeploymentUnit parent = deploymentUnit.getParent();
            if (parent != null) {
                metaData = parent.getAttachment(BatchAttachments.BATCH_ENVIRONMENT_META_DATA);
            }
        }
        if (metaData != null) {
            jobRepository = metaData.getJobRepository();
            jobRepositoryName = metaData.getJobRepositoryName();
            dataSourceName = metaData.getDataSourceName();
            jobExecutorName = metaData.getExecutorName();
            restartJobsOnResume = metaData.getRestartJobsOnResume();
        }
        final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        final String deploymentName = deploymentUnit.getName();
        // Create the job operator service used interact with a deployments batch job
        final JobOperatorService jobOperatorService = new JobOperatorService(restartJobsOnResume, deploymentName, jobXmlResolver);
        // Create the batch environment
        final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        final NamespaceContextSelector namespaceContextSelector = eeModuleDescription == null ? null : eeModuleDescription.getNamespaceContextSelector();
        final BatchEnvironmentService service = new BatchEnvironmentService(moduleClassLoader, jobXmlResolver, deploymentName, namespaceContextSelector);
        final ServiceBuilder<SecurityAwareBatchEnvironment> serviceBuilder = serviceTarget.addService(BatchServiceNames.batchEnvironmentServiceName(deploymentUnit), service);
        // Add a dependency to the thread-pool
        if (jobExecutorName != null) {
            // Register the named thread-pool capability
            serviceBuilder.addDependency(Capabilities.THREAD_POOL_CAPABILITY.getCapabilityServiceName(jobExecutorName), JobExecutor.class, service.getJobExecutorInjector());
        }
        // Register the required services
        serviceBuilder.addDependency(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getCapabilityServiceName(), BatchConfiguration.class, service.getBatchConfigurationInjector());
        // Ensure local transaction support is started
        serviceBuilder.requires(support.getCapabilityServiceName(Capabilities.LOCAL_TRANSACTION_PROVIDER_CAPABILITY));
        final ServiceName artifactFactoryServiceName = BatchServiceNames.batchArtifactFactoryServiceName(deploymentUnit);
        final ArtifactFactoryService artifactFactoryService = new ArtifactFactoryService();
        final ServiceBuilder<ArtifactFactory> artifactFactoryServiceBuilder = serviceTarget.addService(artifactFactoryServiceName, artifactFactoryService);
        // Register the bean manager if this is a Jakarta Contexts and Dependency Injection deployment
        if (support.hasCapability(WELD_CAPABILITY_NAME)) {
            final WeldCapability api = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get();
            if (api.isPartOfWeldDeployment(deploymentUnit)) {
                BatchLogger.LOGGER.tracef("Adding BeanManager service dependency for deployment %s", deploymentUnit.getName());
                api.addBeanManagerService(deploymentUnit, artifactFactoryServiceBuilder, artifactFactoryService.getBeanManagerInjector());
            }
        }
        artifactFactoryServiceBuilder.install();
        serviceBuilder.addDependency(artifactFactoryServiceName, WildFlyArtifactFactory.class, service.getArtifactFactoryInjector());
        if (jobRepositoryName != null) {
            // Register a named job repository
            serviceBuilder.addDependency(support.getCapabilityServiceName(Capabilities.JOB_REPOSITORY_CAPABILITY.getName(), jobRepositoryName), JobRepository.class, service.getJobRepositoryInjector());
        } else if (dataSourceName != null) {
            // Register a jdbc job repository with data-source
            final JdbcJobRepositoryService jdbcJobRepositoryService = new JdbcJobRepositoryService();
            final ServiceName jobRepositoryServiceName = support.getCapabilityServiceName(Capabilities.JOB_REPOSITORY_CAPABILITY.getName(), deploymentName);
            final ServiceBuilder<JobRepository> jobRepositoryServiceBuilder = Services.addServerExecutorDependency(serviceTarget.addService(jobRepositoryServiceName, jdbcJobRepositoryService), jdbcJobRepositoryService.getExecutorServiceInjector()).addDependency(support.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY, dataSourceName), DataSource.class, jdbcJobRepositoryService.getDataSourceInjector());
            jobRepositoryServiceBuilder.install();
            serviceBuilder.addDependency(jobRepositoryServiceName, JobRepository.class, service.getJobRepositoryInjector());
        } else if (jobRepository != null) {
            // Use the job repository as defined in the deployment descriptor
            service.getJobRepositoryInjector().setValue(new ImmediateValue<>(jobRepository));
        }
        if (rcPresent) {
            serviceBuilder.addDependency(RequestController.SERVICE_NAME, RequestController.class, service.getRequestControllerInjector());
        }
        // Install the batch environment service
        serviceBuilder.install();
        // Install the JobOperatorService
        ServiceName jobOperatorServiceName = BatchServiceNames.jobOperatorServiceName(deploymentUnit);
        Services.addServerExecutorDependency(serviceTarget.addService(jobOperatorServiceName, jobOperatorService).addDependency(support.getCapabilityServiceName(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getName()), BatchConfiguration.class, jobOperatorService.getBatchConfigurationInjector()).addDependency(support.getCapabilityServiceName(Capabilities.SUSPEND_CONTROLLER_CAPABILITY), SuspendController.class, jobOperatorService.getSuspendControllerInjector()).addDependency(support.getCapabilityServiceName(Capabilities.PROCESS_STATE_NOTIFIER_CAPABILITY), ProcessStateNotifier.class, jobOperatorService.getProcessStateInjector()).addDependency(BatchServiceNames.batchEnvironmentServiceName(deploymentUnit), SecurityAwareBatchEnvironment.class, jobOperatorService.getBatchEnvironmentInjector()), jobOperatorService.getExecutorServiceInjector()).install();
        // Add the JobOperatorService to the deployment unit
        deploymentUnit.putAttachment(BatchAttachments.JOB_OPERATOR, jobOperatorService);
        deploymentUnit.addToAttachmentList(DEPLOYMENT_COMPLETE_SERVICES, jobOperatorServiceName);
        // Add the JobOperator to the context selector
        selector.registerContext(moduleClassLoader, JobOperatorContext.create(jobOperatorService));
    }
}
Also used : JobRepository(org.jberet.repository.JobRepository) NamespaceContextSelector(org.jboss.as.naming.context.NamespaceContextSelector) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) BatchConfiguration(org.wildfly.extension.batch.jberet.BatchConfiguration) ServiceTarget(org.jboss.msc.service.ServiceTarget) JdbcJobRepositoryService(org.wildfly.extension.batch.jberet.job.repository.JdbcJobRepositoryService) WeldCapability(org.jboss.as.weld.WeldCapability) ProcessStateNotifier(org.jboss.as.controller.ProcessStateNotifier) DataSource(javax.sql.DataSource) ArtifactFactory(org.jberet.spi.ArtifactFactory) ServiceName(org.jboss.msc.service.ServiceName) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 50 with ServiceBuilder

use of org.jboss.msc.service.ServiceBuilder in project wildfly by wildfly.

the class DataSourceDefinitionInjectionSource method getResourceValue.

// --- //
@Override
public void getResourceValue(ResolutionContext context, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
    AgroalConnectionFactoryConfigurationSupplier connectionFactoryConfiguration = new AgroalConnectionFactoryConfigurationSupplier();
    try {
        Class<?> providerClass = phaseContext.getDeploymentUnit().getAttachment(MODULE).getClassLoader().loadClass(className);
        if (providerClass != null && !DataSource.class.isAssignableFrom(providerClass) && !Driver.class.isAssignableFrom(providerClass)) {
            throw AgroalLogger.SERVICE_LOGGER.invalidDeploymentConnectionProvider();
        }
        connectionFactoryConfiguration.connectionProviderClass(providerClass);
    } catch (ClassNotFoundException e) {
        throw AgroalLogger.SERVICE_LOGGER.loadClassDeploymentException(e, className);
    }
    for (Map.Entry<String, String> property : properties.entrySet()) {
        connectionFactoryConfiguration.jdbcProperty(property.getKey(), property.getValue());
    }
    if (databaseName != null && !databaseName.isEmpty()) {
        connectionFactoryConfiguration.jdbcProperty(DATABASE_NAME_PROP, databaseName);
    }
    if (description != null && !description.isEmpty()) {
        connectionFactoryConfiguration.jdbcProperty(DESCRIPTION_PROP, description);
    }
    if (serverName != null && !serverName.isEmpty()) {
        connectionFactoryConfiguration.jdbcProperty(SERVER_NAME_PROP, serverName);
    }
    if (portNumber >= 0) {
        connectionFactoryConfiguration.jdbcProperty(PORT_NUMBER_PROP, Integer.toString(portNumber));
    }
    if (loginTimeout >= 0) {
        connectionFactoryConfiguration.jdbcProperty(LOGIN_TIMEOUT_PROP, Integer.toString(loginTimeout));
    }
    if (maxStatements >= 0) {
        connectionFactoryConfiguration.jdbcProperty(MAX_STATEMENTS_PROP, Integer.toString(maxStatements));
    }
    if (url != null && !url.isEmpty()) {
        connectionFactoryConfiguration.jdbcUrl(url);
    }
    if (user != null && !user.isEmpty()) {
        connectionFactoryConfiguration.principal(new NamePrincipal(user));
    }
    if (password != null && !password.isEmpty()) {
        connectionFactoryConfiguration.credential(new SimplePassword(password));
    }
    connectionFactoryConfiguration.jdbcTransactionIsolation(AgroalConnectionFactoryConfiguration.TransactionIsolation.fromLevel(isolationLevel));
    AgroalConnectionPoolConfigurationSupplier connectionPoolConfiguration = new AgroalConnectionPoolConfigurationSupplier();
    connectionPoolConfiguration.connectionFactoryConfiguration(connectionFactoryConfiguration);
    if (initialPoolSize >= 0) {
        connectionPoolConfiguration.initialSize(initialPoolSize);
    }
    if (minPoolSize >= 0) {
        connectionPoolConfiguration.minSize(minPoolSize);
    }
    if (maxPoolSize >= 0) {
        connectionPoolConfiguration.maxSize(maxPoolSize);
    }
    if (maxIdleTime >= 0) {
        connectionPoolConfiguration.reapTimeout(Duration.ofSeconds(maxIdleTime));
    }
    AgroalDataSourceConfigurationSupplier dataSourceConfiguration = new AgroalDataSourceConfigurationSupplier();
    dataSourceConfiguration.connectionPoolConfiguration(connectionPoolConfiguration);
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);
    ServiceName dataSourceServiceName = DATASOURCE_DEFINITION_SERVICE_PREFIX.append(bindInfo.getBinderServiceName().getCanonicalName());
    // This is the service responsible for the JNDI binding, with a dependency on the datasource service that acts as a ManagedReferenceFactory and is used as the injection source
    BinderService binderService = new BinderService(bindInfo.getBindName(), this);
    phaseContext.getServiceTarget().addService(bindInfo.getBinderServiceName(), binderService).addDependency(dataSourceServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).install();
    ServiceBuilder svcBuilder = phaseContext.getServiceTarget().addService(dataSourceServiceName);
    Supplier<TransactionSynchronizationRegistry> tsrSupplier = null;
    if (transactional) {
        CapabilityServiceSupport css = phaseContext.getDeploymentUnit().getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        ServiceName tsrName = css.getCapabilityServiceName("org.wildfly.transactions.transaction-synchronization-registry");
        // noinspection unchecked
        tsrSupplier = (Supplier<TransactionSynchronizationRegistry>) svcBuilder.requires(tsrName);
    }
    DataSourceDefinitionService dataSourceService = new DataSourceDefinitionService(bindInfo, transactional, dataSourceConfiguration, tsrSupplier);
    svcBuilder.setInstance(dataSourceService).install();
    serviceBuilder.requires(bindInfo.getBinderServiceName());
    serviceBuilder.addDependency(dataSourceServiceName, ManagedReferenceFactory.class, injector);
}
Also used : AgroalDataSourceConfigurationSupplier(io.agroal.api.configuration.supplier.AgroalDataSourceConfigurationSupplier) NamePrincipal(io.agroal.api.security.NamePrincipal) AgroalConnectionFactoryConfigurationSupplier(io.agroal.api.configuration.supplier.AgroalConnectionFactoryConfigurationSupplier) DataSource(javax.sql.DataSource) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) BinderService(org.jboss.as.naming.service.BinderService) AgroalConnectionPoolConfigurationSupplier(io.agroal.api.configuration.supplier.AgroalConnectionPoolConfigurationSupplier) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) SimplePassword(io.agroal.api.security.SimplePassword) Map(java.util.Map) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Aggregations

ServiceBuilder (org.jboss.msc.service.ServiceBuilder)59 ServiceName (org.jboss.msc.service.ServiceName)35 ServiceTarget (org.jboss.msc.service.ServiceTarget)23 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)17 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)15 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)14 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)14 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)12 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)12 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)10 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)9 Module (org.jboss.modules.Module)9 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)7 ArrayList (java.util.ArrayList)6 OperationFailedException (org.jboss.as.controller.OperationFailedException)6 Resource (org.jboss.as.controller.registry.Resource)6 ModelNode (org.jboss.dmr.ModelNode)6