Search in sources :

Example 21 with BinderService

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

the class WeldBeanManagerServiceProcessor method bindBeanManager.

private void bindBeanManager(ServiceTarget serviceTarget, ServiceName beanManagerServiceName, ServiceName contextServiceName, final Collection<ServiceName> dependencies, final ServiceRegistry serviceRegistry) {
    final ServiceName beanManagerBindingServiceName = contextServiceName.append("BeanManager");
    dependencies.add(beanManagerBindingServiceName);
    BinderService beanManagerBindingService = new BinderService("BeanManager");
    final BeanManagerManagedReferenceFactory referenceFactory = new BeanManagerManagedReferenceFactory();
    serviceTarget.addService(beanManagerBindingServiceName, beanManagerBindingService).addInjection(beanManagerBindingService.getManagedObjectInjector(), referenceFactory).addDependency(contextServiceName, ServiceBasedNamingStore.class, beanManagerBindingService.getNamingStoreInjector()).addDependency(beanManagerServiceName, BeanManager.class, referenceFactory.beanManager).install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ServiceName(org.jboss.msc.service.ServiceName) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 22 with BinderService

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

the class DsXmlDeploymentInstallProcessor method startDataSource.

private void startDataSource(final AbstractDataSourceService dataSourceService, final String jndiName, final String driverName, final ServiceTarget serviceTarget, final ManagementResourceRegistration registration, final Resource resource, final String managementName, boolean requireLegacySecurity, final boolean isTransactional) {
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    final ServiceName dataSourceServiceName = AbstractDataSourceService.getServiceName(bindInfo);
    final ServiceBuilder<?> dataSourceServiceBuilder = Services.addServerExecutorDependency(serviceTarget.addService(dataSourceServiceName, dataSourceService), dataSourceService.getExecutorServiceInjector(), false).addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, dataSourceService.getMdrInjector()).addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector()).addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(DEFAULT_NAME)).addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, dataSourceService.getTransactionIntegrationInjector()).addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, dataSourceService.getManagementRepositoryInjector()).addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, dataSourceService.getCcmInjector()).addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, dataSourceService.getDriverRegistryInjector()).addDependency(NamingService.SERVICE_NAME);
    if (requireLegacySecurity) {
        dataSourceServiceBuilder.addDependency(SimpleSecurityManagerService.SERVICE_NAME, ServerSecurityManager.class, dataSourceService.getServerSecurityManager());
        dataSourceServiceBuilder.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class, dataSourceService.getSubjectFactoryInjector());
    }
    //Register an empty override model regardless of we're enabled or not - the statistics listener will add the relevant childresources
    if (registration.isAllowsOverride()) {
        ManagementResourceRegistration overrideRegistration = registration.getOverrideModel(managementName);
        if (overrideRegistration == null || overrideRegistration.isAllowsOverride()) {
            overrideRegistration = registration.registerOverrideModel(managementName, DataSourcesSubsystemProviders.OVERRIDE_DS_DESC);
        }
        DataSourceStatisticsService statsService = new DataSourceStatisticsService(registration, false);
        serviceTarget.addService(dataSourceServiceName.append(Constants.STATISTICS), statsService).addDependency(dataSourceServiceName).addDependency(CommonDeploymentService.getServiceName(bindInfo), CommonDeployment.class, statsService.getCommonDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
        DataSourceStatisticsService.registerStatisticsResources(resource);
    }
    // else should probably throw an ISE or something
    final ServiceName driverServiceName = ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_"));
    if (driverServiceName != null) {
        dataSourceServiceBuilder.addDependency(driverServiceName, Driver.class, dataSourceService.getDriverInjector());
    }
    final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService();
    final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(jndiName);
    final ServiceBuilder<?> referenceBuilder = serviceTarget.addService(referenceFactoryServiceName, referenceFactoryService).addDependency(dataSourceServiceName, javax.sql.DataSource.class, referenceFactoryService.getDataSourceInjector());
    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<?> controller, final ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        if (isTransactional) {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName);
                        } else {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundNonJTADataSource(jndiName);
                        }
                        break;
                    }
                case START_REQUESTED_to_DOWN:
                    {
                        if (isTransactional) {
                            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;
                    }
            }
        }
    });
    dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
}
Also used : DataSourceStatisticsService(org.jboss.as.connector.services.datasources.statistics.DataSourceStatisticsService) DataSourceReferenceFactoryService(org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) BinderService(org.jboss.as.naming.service.BinderService) MetadataRepository(org.jboss.jca.core.spi.mdr.MetadataRepository) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) DriverRegistry(org.jboss.as.connector.services.driver.registry.DriverRegistry) ServiceController(org.jboss.msc.service.ServiceController) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 23 with BinderService

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

the class DataSourceDefinitionInjectionSource method startDataSource.

private void startDataSource(final AbstractDataSourceService dataSourceService, final ContextNames.BindInfo bindInfo, final EEModuleDescription moduleDescription, final ResolutionContext context, final ServiceTarget serviceTarget, final ServiceBuilder valueSourceServiceBuilder, final Injector<ManagedReferenceFactory> injector) {
    final ServiceName dataSourceServiceName = AbstractDataSourceService.getServiceName(bindInfo);
    final ServiceBuilder<?> dataSourceServiceBuilder = Services.addServerExecutorDependency(serviceTarget.addService(dataSourceServiceName, dataSourceService), dataSourceService.getExecutorServiceInjector(), false).addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, dataSourceService.getMdrInjector()).addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector()).addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(DEFAULT_NAME)).addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, dataSourceService.getTransactionIntegrationInjector()).addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, dataSourceService.getManagementRepositoryInjector()).addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, dataSourceService.getCcmInjector()).addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, dataSourceService.getDriverRegistryInjector()).addDependency(NamingService.SERVICE_NAME);
    // We don't need to inject legacy security subsystem services. They are only used with a configured legacy
    // security domain, and the annotation does not support configuring that
    //        if(securityEnabled) {
    //            dataSourceServiceBuilder.addDependency(SimpleSecurityManagerService.SERVICE_NAME, ServerSecurityManager.class,
    //                    dataSourceService.getServerSecurityManager());
    //            dataSourceServiceBuilder.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class,
    //                    dataSourceService.getSubjectFactoryInjector());
    //        }
    final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService();
    final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName());
    final ServiceBuilder<?> referenceBuilder = serviceTarget.addService(referenceFactoryServiceName, referenceFactoryService).addDependency(dataSourceServiceName, javax.sql.DataSource.class, referenceFactoryService.getDataSourceInjector());
    final BinderService binderService = new BinderService(bindInfo.getBindName(), this);
    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 (isTransactional()) {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName);
                        } else {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundNonJTADataSource(jndiName);
                        }
                        break;
                    }
                case START_REQUESTED_to_DOWN:
                    {
                        if (isTransactional()) {
                            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;
                    }
            }
        }
    });
    dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    valueSourceServiceBuilder.addDependency(bindInfo.getBinderServiceName(), ManagedReferenceFactory.class, injector);
}
Also used : DataSourceReferenceFactoryService(org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService) BinderService(org.jboss.as.naming.service.BinderService) MetadataRepository(org.jboss.jca.core.spi.mdr.MetadataRepository) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) DriverRegistry(org.jboss.as.connector.services.driver.registry.DriverRegistry) ServiceController(org.jboss.msc.service.ServiceController)

Example 24 with BinderService

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

the class PersistenceUnitServiceHandler method entityManagerBind.

private static void entityManagerBind(EEModuleDescription eeModuleDescription, ServiceTarget serviceTarget, final PersistenceUnitMetadata pu, ServiceName puServiceName, TransactionManager transactionManager, TransactionSynchronizationRegistry transactionSynchronizationRegistry) {
    if (pu.getProperties().containsKey(ENTITYMANAGER_JNDI_PROPERTY)) {
        String jndiName = pu.getProperties().get(ENTITYMANAGER_JNDI_PROPERTY).toString();
        final ContextNames.BindInfo bindingInfo;
        if (jndiName.startsWith("java:")) {
            bindingInfo = ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jndiName);
        } else {
            bindingInfo = ContextNames.bindInfoFor(jndiName);
        }
        ROOT_LOGGER.tracef("binding the transaction scoped entity manager to jndi name '%s'", bindingInfo.getAbsoluteJndiName());
        final BinderService binderService = new BinderService(bindingInfo.getBindName());
        serviceTarget.addService(bindingInfo.getBinderServiceName(), binderService).addDependency(bindingInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addDependency(puServiceName, PersistenceUnitServiceImpl.class, new Injector<PersistenceUnitServiceImpl>() {

            @Override
            public void inject(final PersistenceUnitServiceImpl value) throws InjectionException {
                binderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(new TransactionScopedEntityManager(pu.getScopedPersistenceUnitName(), Collections.emptyMap(), value.getEntityManagerFactory(), SynchronizationType.SYNCHRONIZED, transactionSynchronizationRegistry, transactionManager))));
            }

            @Override
            public void uninject() {
                binderService.getNamingStoreInjector().uninject();
            }
        }).install();
    }
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) PhaseOnePersistenceUnitServiceImpl(org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl) PersistenceUnitServiceImpl(org.jboss.as.jpa.service.PersistenceUnitServiceImpl) TransactionScopedEntityManager(org.jboss.as.jpa.container.TransactionScopedEntityManager) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) CastingInjector(org.jboss.msc.inject.CastingInjector) Injector(org.jboss.msc.inject.Injector) ContextNames(org.jboss.as.naming.deployment.ContextNames) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 25 with BinderService

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

the class PersistenceUnitServiceHandler method entityManagerFactoryBind.

private static void entityManagerFactoryBind(EEModuleDescription eeModuleDescription, ServiceTarget serviceTarget, PersistenceUnitMetadata pu, ServiceName puServiceName) {
    if (pu.getProperties().containsKey(ENTITYMANAGERFACTORY_JNDI_PROPERTY)) {
        String jndiName = pu.getProperties().get(ENTITYMANAGERFACTORY_JNDI_PROPERTY).toString();
        final ContextNames.BindInfo bindingInfo;
        if (jndiName.startsWith("java:")) {
            bindingInfo = ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jndiName);
        } else {
            bindingInfo = ContextNames.bindInfoFor(jndiName);
        }
        ROOT_LOGGER.tracef("binding the entity manager factory to jndi name '%s'", bindingInfo.getAbsoluteJndiName());
        final BinderService binderService = new BinderService(bindingInfo.getBindName());
        serviceTarget.addService(bindingInfo.getBinderServiceName(), binderService).addDependency(bindingInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addDependency(puServiceName, PersistenceUnitServiceImpl.class, new Injector<PersistenceUnitServiceImpl>() {

            @Override
            public void inject(final PersistenceUnitServiceImpl value) throws InjectionException {
                binderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value.getEntityManagerFactory())));
            }

            @Override
            public void uninject() {
                binderService.getNamingStoreInjector().uninject();
            }
        }).install();
    }
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) PhaseOnePersistenceUnitServiceImpl(org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl) PersistenceUnitServiceImpl(org.jboss.as.jpa.service.PersistenceUnitServiceImpl) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) CastingInjector(org.jboss.msc.inject.CastingInjector) Injector(org.jboss.msc.inject.Injector) ContextNames(org.jboss.as.naming.deployment.ContextNames) ImmediateValue(org.jboss.msc.value.ImmediateValue)

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