Search in sources :

Example 66 with ServiceRegistry

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

the class SocketBroadcastGroupAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    ServiceRegistry registry = context.getServiceRegistry(false);
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = registry.getService(serviceName);
    if (service != null) {
        context.reloadRequired();
    } else {
        final String name = context.getCurrentAddressValue();
        final ServiceTarget target = context.getServiceTarget();
        ServiceBuilder builder = target.addService(GroupBindingService.getBroadcastBaseServiceName(serviceName).append(name));
        builder.setInstance(new GroupBindingService(builder.requires(SocketBinding.JBOSS_BINDING_NAME.append(model.get(SOCKET_BINDING).asString()))));
        builder.install();
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 67 with ServiceRegistry

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

the class GetInstalledDriverOperationHandler method execute.

@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    validator.validate(operation);
    final String name = operation.require(DRIVER_NAME.getName()).asString();
    if (context.isNormalServer()) {
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
                ServiceRegistry registry = context.getServiceRegistry(false);
                DriverRegistry driverRegistry = (DriverRegistry) registry.getRequiredService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE).getValue();
                ServiceModuleLoader serviceModuleLoader = (ServiceModuleLoader) registry.getRequiredService(Services.JBOSS_SERVICE_MODULE_LOADER).getValue();
                ModelNode result = new ModelNode();
                InstalledDriver driver = driverRegistry.getInstalledDriver(name);
                ModelNode driverNode = new ModelNode();
                driverNode.get(DRIVER_NAME.getName()).set(driver.getDriverName());
                if (driver.isFromDeployment()) {
                    driverNode.get(DEPLOYMENT_NAME.getName()).set(driver.getDriverName());
                    driverNode.get(DRIVER_MODULE_NAME.getName());
                    driverNode.get(MODULE_SLOT.getName());
                    driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName());
                    driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName());
                } else {
                    driverNode.get(DEPLOYMENT_NAME.getName());
                    driverNode.get(DRIVER_MODULE_NAME.getName()).set(driver.getModuleName().getName());
                    driverNode.get(MODULE_SLOT.getName()).set(driver.getModuleName() != null ? driver.getModuleName().getSlot() : "");
                    driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).set(driver.getDataSourceClassName() != null ? driver.getDataSourceClassName() : "");
                    driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).set(driver.getXaDataSourceClassName() != null ? driver.getXaDataSourceClassName() : "");
                }
                driverNode.get(DATASOURCE_CLASS_INFO.getName()).set(dsClsInfoNode(serviceModuleLoader, driver.getModuleName(), driver.getDataSourceClassName(), driver.getXaDataSourceClassName()));
                driverNode.get(DRIVER_CLASS_NAME.getName()).set(driver.getDriverClassName());
                driverNode.get(DRIVER_MAJOR_VERSION.getName()).set(driver.getMajorVersion());
                driverNode.get(DRIVER_MINOR_VERSION.getName()).set(driver.getMinorVersion());
                driverNode.get(JDBC_COMPLIANT.getName()).set(driver.isJdbcCompliant());
                result.add(driverNode);
                context.getResult().set(result);
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) DriverRegistry(org.jboss.as.connector.services.driver.registry.DriverRegistry) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ServiceModuleLoader(org.jboss.as.server.moduleservice.ServiceModuleLoader) ModelNode(org.jboss.dmr.ModelNode)

Example 68 with ServiceRegistry

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

the class GlobalDirectoryDependencyProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ServiceName depUnitServiceName = deploymentUnit.getServiceName();
    final DeploymentUnit parent = deploymentUnit.getParent();
    final DeploymentUnit topLevelDeployment = parent == null ? deploymentUnit : parent;
    final ExternalModule externalModuleService = topLevelDeployment.getAttachment(Attachments.EXTERNAL_MODULE_SERVICE);
    final ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final CapabilityServiceSupport capabilitySupport = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    final ServiceRegistry serviceRegistry = phaseContext.getServiceRegistry();
    final ServiceTarget target = phaseContext.getServiceTarget();
    final ServiceTarget externalServiceTarget = deploymentUnit.getAttachment(Attachments.EXTERNAL_SERVICE_TARGET);
    final ServiceName allDirReadyServiceName = depUnitServiceName.append("directory-services-ready");
    final ServiceBuilder<?> allDirReadyServiceBuilder = target.addService(allDirReadyServiceName);
    final List<Supplier<GlobalDirectoryResourceDefinition.GlobalDirectory>> allDirReadySuppliers = new ArrayList<>();
    final ServiceName csName = capabilitySupport.getCapabilityServiceName(EE_GLOBAL_DIRECTORY_CAPABILITY_NAME);
    List<ServiceName> serviceNames = serviceRegistry.getServiceNames();
    for (ServiceName serviceName : serviceNames) {
        if (csName.isParentOf(serviceName)) {
            Supplier<GlobalDirectoryResourceDefinition.GlobalDirectory> pathRequirement = allDirReadyServiceBuilder.requires(serviceName);
            allDirReadySuppliers.add(pathRequirement);
        }
    }
    if (!allDirReadySuppliers.isEmpty()) {
        GlobalDirectoryDeploymentService globalDirDepService = new GlobalDirectoryDeploymentService(allDirReadySuppliers, externalModuleService, moduleSpecification, moduleLoader, serviceRegistry, externalServiceTarget);
        allDirReadyServiceBuilder.requires(phaseContext.getPhaseServiceName());
        allDirReadyServiceBuilder.setInstance(globalDirDepService).install();
        phaseContext.requires(allDirReadyServiceName, new DelegatingSupplier());
    }
}
Also used : ModuleLoader(org.jboss.modules.ModuleLoader) ServiceTarget(org.jboss.msc.service.ServiceTarget) ArrayList(java.util.ArrayList) GlobalDirectoryDeploymentService(org.jboss.as.ee.subsystem.GlobalDirectoryDeploymentService) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) DelegatingSupplier(org.jboss.as.server.deployment.DelegatingSupplier) ServiceName(org.jboss.msc.service.ServiceName) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) GlobalDirectoryResourceDefinition(org.jboss.as.ee.subsystem.GlobalDirectoryResourceDefinition) DelegatingSupplier(org.jboss.as.server.deployment.DelegatingSupplier) Supplier(java.util.function.Supplier) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ExternalModule(org.jboss.as.server.moduleservice.ExternalModule) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 69 with ServiceRegistry

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

the class AbstractDataSourceOperations method getDataSource.

// --- //
private static AgroalDataSource getDataSource(OperationContext context) throws OperationFailedException {
    ServiceRegistry registry = context.getServiceRegistry(false);
    String dataSourceName = context.getCurrentAddressValue();
    switch(context.getCurrentAddress().getLastElement().getKey()) {
        case DataSourceOperations.DATASOURCE_SERVICE_NAME:
            ServiceController<?> controller = registry.getRequiredService(AbstractDataSourceDefinition.DATA_SOURCE_CAPABILITY.getCapabilityServiceName(dataSourceName));
            return ((AgroalDataSource) controller.getValue());
        case XADataSourceOperations.XADATASOURCE_SERVICE_NAME:
            ServiceController<?> xaController = registry.getRequiredService(AbstractDataSourceDefinition.DATA_SOURCE_CAPABILITY.getCapabilityServiceName(dataSourceName));
            return ((AgroalDataSource) xaController.getValue());
        default:
            throw AgroalLogger.SERVICE_LOGGER.unknownDatasourceServiceType(context.getCurrentAddress().getLastElement().getKey());
    }
}
Also used : ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Example 70 with ServiceRegistry

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

the class RaOperationUtil method restartIfPresent.

public static ServiceName restartIfPresent(OperationContext context, final String raName, final String id) throws OperationFailedException {
    final ServiceName raDeploymentServiceName = ConnectorServices.getDeploymentServiceName(raName, id);
    final ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController raServiceController = registry.getService(raDeploymentServiceName);
    if (raServiceController != null) {
        final org.jboss.msc.service.ServiceController.Mode originalMode = raServiceController.getMode();
        final UninterruptibleCountDownLatch latch = new UninterruptibleCountDownLatch(1);
        raServiceController.addListener(new LifecycleListener() {

            @Override
            public void handleEvent(ServiceController controller, LifecycleEvent event) {
                latch.awaitUninterruptibly();
                if (event == LifecycleEvent.DOWN) {
                    try {
                        final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, id));
                        Activation raxml = (Activation) RaxmlController.getValue();
                        ((ResourceAdapterXmlDeploymentService) controller.getService()).setRaxml(raxml);
                        controller.compareAndSetMode(ServiceController.Mode.NEVER, originalMode);
                    } finally {
                        controller.removeListener(this);
                    }
                }
            }
        });
        try {
            raServiceController.setMode(ServiceController.Mode.NEVER);
        } finally {
            latch.countDown();
        }
        return raDeploymentServiceName;
    } else {
        return null;
    }
}
Also used : UninterruptibleCountDownLatch(org.jboss.as.controller.UninterruptibleCountDownLatch) ServiceName(org.jboss.msc.service.ServiceName) LifecycleEvent(org.jboss.msc.service.LifecycleEvent) ServiceController(org.jboss.msc.service.ServiceController) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) LifecycleListener(org.jboss.msc.service.LifecycleListener)

Aggregations

ServiceRegistry (org.jboss.msc.service.ServiceRegistry)74 ServiceName (org.jboss.msc.service.ServiceName)51 ModelNode (org.jboss.dmr.ModelNode)22 PathAddress (org.jboss.as.controller.PathAddress)15 ServiceTarget (org.jboss.msc.service.ServiceTarget)15 OperationFailedException (org.jboss.as.controller.OperationFailedException)13 ServiceController (org.jboss.msc.service.ServiceController)12 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)8 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)8 OperationContext (org.jboss.as.controller.OperationContext)6 Resource (org.jboss.as.controller.registry.Resource)6 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)5 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)5 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)4 PathElement (org.jboss.as.controller.PathElement)4 DefaultAccessTimeoutService (org.jboss.as.ejb3.component.DefaultAccessTimeoutService)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 ArrayList (java.util.ArrayList)2 BridgeConfiguration (org.apache.activemq.artemis.core.config.BridgeConfiguration)2 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)2