Search in sources :

Example 6 with BinderService

use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.

the class BinderServiceUtil method installAliasBinderService.

public static void installAliasBinderService(final ServiceTarget serviceTarget, final BindInfo bindInfo, final String alias) {
    final BindInfo aliasBindInfo = ContextNames.bindInfoFor(alias);
    final BinderService aliasBinderService = new BinderService(alias);
    aliasBinderService.getManagedObjectInjector().inject(new AliasManagedReferenceFactory(bindInfo.getAbsoluteJndiName()));
    serviceTarget.addService(aliasBindInfo.getBinderServiceName(), aliasBinderService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, aliasBinderService.getNamingStoreInjector()).addDependency(bindInfo.getBinderServiceName()).addListener(new AbstractServiceListener<ManagedReferenceFactory>() {

        @Override
        public void transition(ServiceController<? extends ManagedReferenceFactory> controller, ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        ROOT_LOGGER.boundJndiName(alias);
                        break;
                    }
                case STOPPING_to_DOWN:
                    {
                        ROOT_LOGGER.unboundJndiName(alias);
                        break;
                    }
                case REMOVING_to_REMOVED:
                    {
                        ROOT_LOGGER.debugf("Removed messaging object [%s]", alias);
                        break;
                    }
            }
        }
    }).install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) ContextListAndJndiViewManagedReferenceFactory(org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory) ContextListManagedReferenceFactory(org.jboss.as.naming.ContextListManagedReferenceFactory) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) AbstractServiceListener(org.jboss.msc.service.AbstractServiceListener) ServiceController(org.jboss.msc.service.ServiceController) BindInfo(org.jboss.as.naming.deployment.ContextNames.BindInfo)

Example 7 with BinderService

use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.

the class AbstractDataSourceAdd method secondRuntimeStep.

static void secondRuntimeStep(OperationContext context, ModelNode operation, ManagementResourceRegistration datasourceRegistration, ModelNode model, boolean isXa) throws OperationFailedException {
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final ModelNode address = operation.require(OP_ADDR);
    final String dsName = PathAddress.pathAddress(address).getLastElement().getValue();
    final String jndiName = JNDI_NAME.resolveModelAttribute(context, model).asString();
    final ServiceRegistry registry = context.getServiceRegistry(true);
    final List<ServiceName> serviceNames = registry.getServiceNames();
    final boolean elytronEnabled = ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean();
    final ServiceName dataSourceServiceName = context.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY_NAME, dsName, DataSource.class);
    final ServiceController<?> dataSourceController = registry.getService(dataSourceServiceName);
    final ExceptionSupplier<CredentialSource, Exception> credentialSourceExceptionExceptionSupplier = dataSourceController.getService() instanceof AbstractDataSourceService ? ((AbstractDataSourceService) dataSourceController.getService()).getCredentialSourceSupplierInjector().getOptionalValue() : null;
    final ExceptionSupplier<CredentialSource, Exception> recoveryCredentialSourceExceptionExceptionSupplier = dataSourceController.getService() instanceof AbstractDataSourceService ? ((AbstractDataSourceService) dataSourceController.getService()).getRecoveryCredentialSourceSupplierInjector().getOptionalValue() : null;
    final boolean jta;
    if (isXa) {
        jta = true;
        final ModifiableXaDataSource dataSourceConfig;
        try {
            dataSourceConfig = xaFrom(context, model, dsName, credentialSourceExceptionExceptionSupplier, recoveryCredentialSourceExceptionExceptionSupplier);
        } catch (ValidateException e) {
            throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToCreate("XaDataSource", operation, e.getLocalizedMessage()));
        }
        final ServiceName xaDataSourceConfigServiceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName);
        final XADataSourceConfigService xaDataSourceConfigService = new XADataSourceConfigService(dataSourceConfig);
        final ServiceBuilder<?> builder = serviceTarget.addService(xaDataSourceConfigServiceName, xaDataSourceConfigService);
        // add dependency on security domain service if applicable
        final DsSecurity dsSecurityConfig = dataSourceConfig.getSecurity();
        if (dsSecurityConfig != null) {
            final String securityDomainName = dsSecurityConfig.getSecurityDomain();
            if (!elytronEnabled && securityDomainName != null) {
                builder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomainName));
            }
        }
        // add dependency on security domain service if applicable for recovery config
        if (dataSourceConfig.getRecovery() != null) {
            final Credential credential = dataSourceConfig.getRecovery().getCredential();
            if (credential != null) {
                final String securityDomainName = credential.getSecurityDomain();
                if (!RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean() && securityDomainName != null) {
                    builder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomainName));
                }
            }
        }
        int propertiesCount = 0;
        for (ServiceName name : serviceNames) {
            if (xaDataSourceConfigServiceName.append("xa-datasource-properties").isParentOf(name)) {
                final ServiceController<?> xaConfigPropertyController = registry.getService(name);
                XaDataSourcePropertiesService xaPropService = (XaDataSourcePropertiesService) xaConfigPropertyController.getService();
                if (!ServiceController.State.UP.equals(xaConfigPropertyController.getState())) {
                    propertiesCount++;
                    xaConfigPropertyController.setMode(ServiceController.Mode.ACTIVE);
                    builder.addDependency(name, String.class, xaDataSourceConfigService.getXaDataSourcePropertyInjector(xaPropService.getName()));
                } else {
                    throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source.xa-config-property", name));
                }
            }
        }
        if (propertiesCount == 0) {
            throw ConnectorLogger.ROOT_LOGGER.xaDataSourcePropertiesNotPresent();
        }
        builder.install();
    } else {
        final ModifiableDataSource dataSourceConfig;
        try {
            dataSourceConfig = from(context, model, dsName, credentialSourceExceptionExceptionSupplier);
        } catch (ValidateException e) {
            throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToCreate("DataSource", operation, e.getLocalizedMessage()));
        }
        jta = dataSourceConfig.isJTA();
        final ServiceName dataSourceCongServiceName = DataSourceConfigService.SERVICE_NAME_BASE.append(dsName);
        final DataSourceConfigService configService = new DataSourceConfigService(dataSourceConfig);
        final ServiceBuilder<?> builder = serviceTarget.addService(dataSourceCongServiceName, configService);
        // add dependency on security domain service if applicable
        final DsSecurity dsSecurityConfig = dataSourceConfig.getSecurity();
        if (dsSecurityConfig != null) {
            final String securityDomainName = dsSecurityConfig.getSecurityDomain();
            if (!elytronEnabled && securityDomainName != null) {
                builder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomainName));
            }
        }
        for (ServiceName name : serviceNames) {
            if (dataSourceCongServiceName.append("connection-properties").isParentOf(name)) {
                final ServiceController<?> connPropServiceController = registry.getService(name);
                ConnectionPropertiesService connPropService = (ConnectionPropertiesService) connPropServiceController.getService();
                if (!ServiceController.State.UP.equals(connPropServiceController.getState())) {
                    connPropServiceController.setMode(ServiceController.Mode.ACTIVE);
                    builder.addDependency(name, String.class, configService.getConnectionPropertyInjector(connPropService.getName()));
                } else {
                    throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source.connectionProperty", name));
                }
            }
        }
        builder.install();
    }
    final ServiceName dataSourceServiceNameAlias = AbstractDataSourceService.SERVICE_NAME_BASE.append(jndiName).append(Constants.STATISTICS);
    if (dataSourceController != null) {
        if (!ServiceController.State.UP.equals(dataSourceController.getState())) {
            final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
            DataSourceStatisticsService statsService = new DataSourceStatisticsService(datasourceRegistration, statsEnabled);
            serviceTarget.addService(dataSourceServiceName.append(Constants.STATISTICS), statsService).addAliases(dataSourceServiceNameAlias).addDependency(dataSourceServiceName).addDependency(CommonDeploymentService.getServiceName(ContextNames.bindInfoFor(jndiName)), CommonDeployment.class, statsService.getCommonDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
            dataSourceController.setMode(ServiceController.Mode.ACTIVE);
        } else {
            throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source", dsName));
        }
    } else {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceNotAvailable("Data-source", dsName));
    }
    final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService();
    final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(dsName);
    final ServiceBuilder<?> referenceBuilder = serviceTarget.addService(referenceFactoryServiceName, referenceFactoryService).addDependency(dataSourceServiceName, DataSource.class, referenceFactoryService.getDataSourceInjector());
    referenceBuilder.install();
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    final BinderService binderService = new BinderService(bindInfo.getBindName());
    final ServiceBuilder<?> binderBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addListener(new AbstractServiceListener<Object>() {

        public void transition(final ServiceController<? extends Object> controller, final ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        if (jta) {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName);
                        } else {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundNonJTADataSource(jndiName);
                        }
                        break;
                    }
                case STOPPING_to_DOWN:
                    {
                        if (jta) {
                            SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName);
                        } else {
                            SUBSYSTEM_DATASOURCES_LOGGER.unBoundNonJTADataSource(jndiName);
                        }
                        break;
                    }
                case REMOVING_to_REMOVED:
                    {
                        SUBSYSTEM_DATASOURCES_LOGGER.debugf("Removed JDBC Data-source [%s]", jndiName);
                        break;
                    }
            }
        }
    });
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
    binderBuilder.install();
}
Also used : ValidateException(org.jboss.jca.common.api.validator.ValidateException) DataSourceStatisticsService(org.jboss.as.connector.services.datasources.statistics.DataSourceStatisticsService) BinderService(org.jboss.as.naming.service.BinderService) ServiceController(org.jboss.msc.service.ServiceController) CredentialSource(org.wildfly.security.credential.source.CredentialSource) ContextNames(org.jboss.as.naming.deployment.ContextNames) Credential(org.jboss.jca.common.api.metadata.common.Credential) DsSecurity(org.jboss.jca.common.api.metadata.ds.DsSecurity) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ValidateException(org.jboss.jca.common.api.validator.ValidateException) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 8 with BinderService

use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.

the class ModuleJndiBindingProcessor method addJndiBinding.

protected void addJndiBinding(final EEModuleConfiguration module, final BindingConfiguration bindingConfiguration, final DeploymentPhaseContext phaseContext, final List<ServiceName> dependencies) throws DeploymentUnitProcessingException {
    // Gather information about the dependency
    final String bindingName = bindingConfiguration.getName().startsWith("java:") ? bindingConfiguration.getName() : "java:module/env/" + bindingConfiguration.getName();
    InjectionSource.ResolutionContext resolutionContext = new InjectionSource.ResolutionContext(true, module.getModuleName(), module.getModuleName(), module.getApplicationName());
    // Check to see if this entry should actually be bound into JNDI.
    if (bindingName != null) {
        final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(module.getApplicationName(), module.getModuleName(), module.getModuleName(), false, bindingName);
        dependencies.add(bindInfo.getBinderServiceName());
        if (bindingName.startsWith("java:comp") || bindingName.startsWith("java:module") || bindingName.startsWith("java:app")) {
            //this is a binding that does not need to be shared.
            try {
                final BinderService service = new BinderService(bindInfo.getBindName(), bindingConfiguration.getSource());
                ServiceBuilder<ManagedReferenceFactory> serviceBuilder = phaseContext.getServiceTarget().addService(bindInfo.getBinderServiceName(), service);
                bindingConfiguration.getSource().getResourceValue(resolutionContext, serviceBuilder, phaseContext, service.getManagedObjectInjector());
                serviceBuilder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, service.getNamingStoreInjector());
                serviceBuilder.install();
            } catch (DuplicateServiceException e) {
                ServiceController<ManagedReferenceFactory> registered = (ServiceController<ManagedReferenceFactory>) CurrentServiceContainer.getServiceContainer().getService(bindInfo.getBinderServiceName());
                if (registered == null)
                    throw e;
                BinderService service = (BinderService) registered.getService();
                if (!service.getSource().equals(bindingConfiguration.getSource()))
                    throw EeLogger.ROOT_LOGGER.conflictingBinding(bindingName, bindingConfiguration.getSource());
            } catch (CircularDependencyException e) {
                throw EeLogger.ROOT_LOGGER.circularDependency(bindingName);
            }
        } else {
            BinderService service;
            try {
                service = new BinderService(bindInfo.getBindName(), bindingConfiguration.getSource(), true);
                ServiceBuilder<ManagedReferenceFactory> serviceBuilder = CurrentServiceContainer.getServiceContainer().addService(bindInfo.getBinderServiceName(), service);
                bindingConfiguration.getSource().getResourceValue(resolutionContext, serviceBuilder, phaseContext, service.getManagedObjectInjector());
                serviceBuilder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, service.getNamingStoreInjector());
                serviceBuilder.install();
            } catch (DuplicateServiceException e) {
                final ServiceController<ManagedReferenceFactory> controller = (ServiceController<ManagedReferenceFactory>) CurrentServiceContainer.getServiceContainer().getService(bindInfo.getBinderServiceName());
                if (controller == null)
                    throw e;
                service = (BinderService) controller.getService();
                if (!equals(service.getSource(), bindingConfiguration.getSource())) {
                    throw EeLogger.ROOT_LOGGER.conflictingBinding(bindingName, bindingConfiguration.getSource());
                }
            }
            //as these bindings are not child services
            //we need to add a listener that released the service when the deployment stops
            service.acquire();
            ServiceController<?> unitService = CurrentServiceContainer.getServiceContainer().getService(phaseContext.getDeploymentUnit().getServiceName());
            unitService.addListener(new BinderReleaseListener(service));
        }
    } else {
        throw EeLogger.ROOT_LOGGER.nullBindingName(bindingConfiguration);
    }
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) DuplicateServiceException(org.jboss.msc.service.DuplicateServiceException) ContextInjectionSource(org.jboss.as.ee.naming.ContextInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ServiceController(org.jboss.msc.service.ServiceController) CircularDependencyException(org.jboss.msc.service.CircularDependencyException) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 9 with BinderService

use of org.jboss.as.naming.service.BinderService 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 10 with BinderService

use of org.jboss.as.naming.service.BinderService in project wildfly by wildfly.

the class ComponentInstallProcessor method processBindings.

@SuppressWarnings("unchecked")
private void processBindings(DeploymentPhaseContext phaseContext, ComponentConfiguration configuration, ServiceTarget serviceTarget, InjectionSource.ResolutionContext resolutionContext, List<BindingConfiguration> bindings, final ServiceBuilder<?> jndiDepServiceBuilder, final Set<ServiceName> bound) throws DeploymentUnitProcessingException {
    //we only handle java:comp bindings for components that have their own namespace here, the rest are processed by ModuleJndiBindingProcessor
    for (BindingConfiguration bindingConfiguration : bindings) {
        if (bindingConfiguration.getName().startsWith("java:comp") || !bindingConfiguration.getName().startsWith("java:")) {
            final String bindingName = bindingConfiguration.getName().startsWith("java:comp") ? bindingConfiguration.getName() : "java:comp/env/" + bindingConfiguration.getName();
            final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(configuration.getApplicationName(), configuration.getModuleName(), configuration.getComponentName(), configuration.getComponentDescription().getNamingMode() == ComponentNamingMode.CREATE, bindingName);
            if (bound.contains(bindInfo.getBinderServiceName())) {
                continue;
            }
            bound.add(bindInfo.getBinderServiceName());
            try {
                final BinderService service = new BinderService(bindInfo.getBindName(), bindingConfiguration.getSource());
                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();
            } catch (DuplicateServiceException e) {
                ServiceController<ManagedReferenceFactory> registered = (ServiceController<ManagedReferenceFactory>) CurrentServiceContainer.getServiceContainer().getService(bindInfo.getBinderServiceName());
                if (registered == null)
                    throw e;
                BinderService service = (BinderService) registered.getService();
                if (!service.getSource().equals(bindingConfiguration.getSource()))
                    throw EeLogger.ROOT_LOGGER.conflictingBinding(bindingName, bindingConfiguration.getSource());
            } catch (CircularDependencyException e) {
                throw EeLogger.ROOT_LOGGER.circularDependency(bindingName);
            }
        }
    }
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) DuplicateServiceException(org.jboss.msc.service.DuplicateServiceException) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ServiceController(org.jboss.msc.service.ServiceController) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) CircularDependencyException(org.jboss.msc.service.CircularDependencyException) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Aggregations

BinderService (org.jboss.as.naming.service.BinderService)33 ServiceName (org.jboss.msc.service.ServiceName)18 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)17 ValueManagedReferenceFactory (org.jboss.as.naming.ValueManagedReferenceFactory)14 ContextNames (org.jboss.as.naming.deployment.ContextNames)14 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)12 ServiceTarget (org.jboss.msc.service.ServiceTarget)10 ServiceController (org.jboss.msc.service.ServiceController)9 ImmediateValue (org.jboss.msc.value.ImmediateValue)6 OperationFailedException (org.jboss.as.controller.OperationFailedException)3 BindInfo (org.jboss.as.naming.deployment.ContextNames.BindInfo)3 NamingStoreService (org.jboss.as.naming.service.NamingStoreService)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 ModelNode (org.jboss.dmr.ModelNode)3 Injector (org.jboss.msc.inject.Injector)3 HashSet (java.util.HashSet)2 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)2 UserTransaction (javax.transaction.UserTransaction)2 DriverRegistry (org.jboss.as.connector.services.driver.registry.DriverRegistry)2 DataSourceReferenceFactoryService (org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService)2