Search in sources :

Example 16 with LifecycleListener

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

the class JMSDestinationDefinitionInjectionSource method inject.

private <D extends Destination> void inject(ServiceBuilder<?> serviceBuilder, Injector<ManagedReferenceFactory> injector, Service<D> destinationService) {
    final ContextListAndJndiViewManagedReferenceFactory referenceFactoryService = new MessagingJMSDestinationManagedReferenceFactory(destinationService);
    injector.inject(referenceFactoryService);
    serviceBuilder.addListener(new LifecycleListener() {

        private volatile boolean bound;

        public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) {
            switch(event) {
                case UP:
                    {
                        ROOT_LOGGER.boundJndiName(jndiName);
                        bound = true;
                        break;
                    }
                case DOWN:
                    {
                        if (bound) {
                            ROOT_LOGGER.unboundJndiName(jndiName);
                        }
                        break;
                    }
                case REMOVED:
                    {
                        ROOT_LOGGER.debugf("Removed messaging object [%s]", jndiName);
                        break;
                    }
            }
        }
    });
}
Also used : LifecycleEvent(org.jboss.msc.service.LifecycleEvent) LifecycleListener(org.jboss.msc.service.LifecycleListener) ContextListAndJndiViewManagedReferenceFactory(org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory)

Example 17 with LifecycleListener

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

the class WildFlyBindingRegistry method unbind.

/**
 * Unbind the resource and wait until the corresponding binding service is effectively removed.
 */
@Override
public void unbind(String name) {
    if (name == null || name.isEmpty()) {
        throw MessagingLogger.ROOT_LOGGER.cannotUnbindJndiName();
    }
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
    ServiceController<?> bindingService = container.getService(bindInfo.getBinderServiceName());
    if (bindingService == null) {
        ROOT_LOGGER.debugf("Cannot unbind %s since no binding exists with that name", name);
        return;
    }
    // remove the binding service
    final CountDownLatch latch = new CountDownLatch(1);
    bindingService.addListener(new LifecycleListener() {

        @Override
        public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) {
            if (event == LifecycleEvent.REMOVED) {
                ROOT_LOGGER.unboundJndiName(bindInfo.getAbsoluteJndiName());
                latch.countDown();
            }
        }
    });
    try {
        bindingService.setMode(ServiceController.Mode.REMOVE);
    } finally {
        try {
            latch.await();
        } catch (InterruptedException ie) {
            ROOT_LOGGER.failedToUnbindJndiName(name, 5, SECONDS.toString().toLowerCase(Locale.US));
        }
    }
}
Also used : LifecycleEvent(org.jboss.msc.service.LifecycleEvent) LifecycleListener(org.jboss.msc.service.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 18 with LifecycleListener

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

the class AdministeredObjectDefinitionInjectionSource method getResourceValue.

public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    String raId = resourceAdapter;
    if (resourceAdapter.startsWith("#")) {
        raId = deploymentUnit.getParent().getName() + raId;
    }
    String deployerServiceName = raId;
    if (!raId.endsWith(".rar")) {
        deployerServiceName = deployerServiceName + ".rar";
        raId = deployerServiceName;
    }
    SUBSYSTEM_RA_LOGGER.debugf("@AdministeredObjectDefinition: %s for %s binding to %s ", className, resourceAdapter, jndiName);
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);
    DirectAdminObjectActivatorService service = new DirectAdminObjectActivatorService(jndiName, className, resourceAdapter, raId, properties, module, bindInfo);
    ServiceName serviceName = DirectAdminObjectActivatorService.SERVICE_NAME_BASE.append(jndiName);
    final ServiceBuilder sb = phaseContext.getServiceTarget().addService(serviceName, service);
    sb.addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, service.getMdrInjector());
    sb.requires(ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(deployerServiceName));
    sb.setInitialMode(ServiceController.Mode.ACTIVE).install();
    serviceBuilder.addDependency(AdminObjectReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName()), ManagedReferenceFactory.class, injector);
    serviceBuilder.addListener(new LifecycleListener() {

        private volatile boolean bound;

        public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) {
            switch(event) {
                case UP:
                    {
                        DEPLOYMENT_CONNECTOR_LOGGER.adminObjectAnnotation(jndiName);
                        bound = true;
                        break;
                    }
                case DOWN:
                    {
                        if (bound) {
                            DEPLOYMENT_CONNECTOR_LOGGER.unboundJca("AdminObject", jndiName);
                        }
                        break;
                    }
                case REMOVED:
                    {
                        DEPLOYMENT_CONNECTOR_LOGGER.debugf("Removed JCA AdminObject [%s]", jndiName);
                    }
            }
        }
    });
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) DirectAdminObjectActivatorService(org.jboss.as.connector.services.resourceadapters.DirectAdminObjectActivatorService) LifecycleEvent(org.jboss.msc.service.LifecycleEvent) LifecycleListener(org.jboss.msc.service.LifecycleListener) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ContextNames(org.jboss.as.naming.deployment.ContextNames) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 19 with LifecycleListener

use of org.jboss.msc.service.LifecycleListener 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 CapabilityServiceSupport support) {
    final ServiceName dataSourceServiceName = AbstractDataSourceService.getServiceName(bindInfo);
    final ServiceBuilder<?> dataSourceServiceBuilder = Services.addServerExecutorDependency(serviceTarget.addService(dataSourceServiceName, dataSourceService), dataSourceService.getExecutorServiceInjector()).addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, dataSourceService.getMdrInjector()).addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector()).addDependency(support.getCapabilityServiceName(ConnectorServices.TRANSACTION_INTEGRATION_CAPABILITY_NAME), 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());
    dataSourceServiceBuilder.requires(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(DEFAULT_NAME));
    dataSourceServiceBuilder.requires(support.getCapabilityServiceName(NamingService.CAPABILITY_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 LifecycleListener() {

        private volatile boolean bound;

        public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) {
            switch(event) {
                case UP:
                    {
                        if (isTransactional()) {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName);
                        } else {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundNonJTADataSource(jndiName);
                        }
                        bound = true;
                        break;
                    }
                case DOWN:
                    {
                        if (bound) {
                            if (isTransactional()) {
                                SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName);
                            } else {
                                SUBSYSTEM_DATASOURCES_LOGGER.unBoundNonJTADataSource(jndiName);
                            }
                        }
                        break;
                    }
                case 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 : TransactionIntegration(org.jboss.jca.core.spi.transaction.TransactionIntegration) DataSourceReferenceFactoryService(org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService) LifecycleListener(org.jboss.msc.service.LifecycleListener) BinderService(org.jboss.as.naming.service.BinderService) MetadataRepository(org.jboss.jca.core.spi.mdr.MetadataRepository) CachedConnectionManager(org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) LifecycleEvent(org.jboss.msc.service.LifecycleEvent)

Example 20 with LifecycleListener

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

the class ConnectionFactoryDefinitionInjectionSource method getResourceValue.

public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    String raId = resourceAdapter;
    if (resourceAdapter.startsWith("#")) {
        raId = deploymentUnit.getParent().getName() + raId;
    }
    String deployerServiceName = raId;
    if (!raId.endsWith(".rar")) {
        deployerServiceName = deployerServiceName + ".rar";
        raId = deployerServiceName;
    }
    SUBSYSTEM_RA_LOGGER.debugf("@ConnectionFactoryDefinition: %s for %s binding to %s ", interfaceName, resourceAdapter, jndiName);
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);
    DirectConnectionFactoryActivatorService service = new DirectConnectionFactoryActivatorService(jndiName, interfaceName, resourceAdapter, raId, maxPoolSize, minPoolSize, properties, transactionSupport, module, bindInfo, legacySecurityAvailable);
    ServiceName serviceName = DirectConnectionFactoryActivatorService.SERVICE_NAME_BASE.append(jndiName);
    final ServiceBuilder sb = phaseContext.getServiceTarget().addService(serviceName, service);
    sb.addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, service.getMdrInjector());
    sb.requires(ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(deployerServiceName));
    sb.setInitialMode(ServiceController.Mode.ACTIVE).install();
    serviceBuilder.addDependency(ConnectionFactoryReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName()), ManagedReferenceFactory.class, injector);
    serviceBuilder.addListener(new LifecycleListener() {

        public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) {
            switch(event) {
                case UP:
                    {
                        DEPLOYMENT_CONNECTOR_LOGGER.connectionFactoryAnnotation(jndiName);
                        break;
                    }
                case DOWN:
                    {
                        break;
                    }
                case REMOVED:
                    {
                        DEPLOYMENT_CONNECTOR_LOGGER.debugf("Removed JCA ConnectionFactory [%s]", jndiName);
                    }
            }
        }
    });
}
Also used : DirectConnectionFactoryActivatorService(org.jboss.as.connector.services.resourceadapters.DirectConnectionFactoryActivatorService) ServiceName(org.jboss.msc.service.ServiceName) LifecycleEvent(org.jboss.msc.service.LifecycleEvent) LifecycleListener(org.jboss.msc.service.LifecycleListener) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ContextNames(org.jboss.as.naming.deployment.ContextNames) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Aggregations

LifecycleListener (org.jboss.msc.service.LifecycleListener)23 LifecycleEvent (org.jboss.msc.service.LifecycleEvent)22 ServiceName (org.jboss.msc.service.ServiceName)11 CountDownLatch (java.util.concurrent.CountDownLatch)9 ContextNames (org.jboss.as.naming.deployment.ContextNames)8 ServiceController (org.jboss.msc.service.ServiceController)7 BinderService (org.jboss.as.naming.service.BinderService)6 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)5 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)3 ExecutorService (java.util.concurrent.ExecutorService)2 DataSourceStatisticsService (org.jboss.as.connector.services.datasources.statistics.DataSourceStatisticsService)2 DataSourceReferenceFactoryService (org.jboss.as.connector.subsystems.datasources.DataSourceReferenceFactoryService)2 ContextListAndJndiViewManagedReferenceFactory (org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory)2 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 Module (org.jboss.modules.Module)2 ServiceContainer (org.jboss.msc.service.ServiceContainer)2 StartException (org.jboss.msc.service.StartException)2 CompletableFuture (java.util.concurrent.CompletableFuture)1