Search in sources :

Example 11 with ServiceTarget

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

the class DiscoveryGroupAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String name = address.getLastElement().getValue();
    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 ServiceTarget target = context.getServiceTarget();
        if (model.hasDefined(JGROUPS_CHANNEL.getName())) {
        // nothing to do, in that case, the clustering.jgroups subsystem will have setup the stack
        } else if (model.hasDefined(RemoteTransportDefinition.SOCKET_BINDING.getName())) {
            final GroupBindingService bindingService = new GroupBindingService();
            target.addService(GroupBindingService.getDiscoveryBaseServiceName(serviceName).append(name), bindingService).addDependency(SocketBinding.JBOSS_BINDING_NAME.append(model.get(SOCKET_BINDING).asString()), SocketBinding.class, bindingService.getBindingRef()).install();
        }
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceTarget(org.jboss.msc.service.ServiceTarget) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Example 12 with ServiceTarget

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

the class ModClusterSubsystemAdd method performBoottime.

@Override
public void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    ServiceTarget target = context.getServiceTarget();
    final ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
    final ModelNode modelConfig = fullModel.get(ModClusterConfigResourceDefinition.PATH.getKeyValuePair());
    ModClusterConfigurationServiceBuilder configurationBuilder = new ModClusterConfigurationServiceBuilder();
    configurationBuilder.configure(context, modelConfig).build(target).install();
    // Construct LoadBalanceFactorProvider and call pluggable boot time handlers.
    Set<LoadMetric> metrics = new HashSet<>();
    final LoadBalanceFactorProvider loadProvider = getModClusterLoadProvider(metrics, context, modelConfig);
    for (BoottimeHandlerProvider handler : ServiceLoader.load(BoottimeHandlerProvider.class, BoottimeHandlerProvider.class.getClassLoader())) {
        handler.performBoottime(metrics, context, operation, modelConfig);
    }
    final String connector = CONNECTOR.resolveModelAttribute(context, modelConfig).asString();
    final int statusInterval = STATUS_INTERVAL.resolveModelAttribute(context, modelConfig).asInt();
    InjectedValue<ModClusterConfiguration> modClusterConfiguration = new InjectedValue<>();
    ContainerEventHandlerService service = new ContainerEventHandlerService(modClusterConfiguration, loadProvider);
    // Install the main service
    new AsynchronousServiceBuilder<>(ContainerEventHandlerService.SERVICE_NAME, service).build(target).addDependency(configurationBuilder.getServiceName(), ModClusterConfiguration.class, modClusterConfiguration).setInitialMode(Mode.ACTIVE).install();
    // Install services for web container integration
    for (ContainerEventHandlerAdapterBuilder adapterBuilder : ServiceLoader.load(ContainerEventHandlerAdapterBuilder.class, ContainerEventHandlerAdapterBuilder.class.getClassLoader())) {
        adapterBuilder.build(target, connector, statusInterval).setInitialMode(Mode.PASSIVE).install();
    }
}
Also used : ModClusterConfiguration(org.jboss.modcluster.config.ModClusterConfiguration) InjectedValue(org.jboss.msc.value.InjectedValue) ServiceTarget(org.jboss.msc.service.ServiceTarget) LoadBalanceFactorProvider(org.jboss.modcluster.load.LoadBalanceFactorProvider) SimpleLoadBalanceFactorProvider(org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProvider) DynamicLoadBalanceFactorProvider(org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider) LoadMetric(org.jboss.modcluster.load.metric.LoadMetric) AsynchronousServiceBuilder(org.wildfly.clustering.service.AsynchronousServiceBuilder) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet)

Example 13 with ServiceTarget

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

the class ParsedServiceDeploymentProcessor method deploy.

/**
     * Process a deployment for JbossService configuration.  Will install a {@code JBossService} for each configured service.
     *
     * @param phaseContext the deployment unit context
     * @throws DeploymentUnitProcessingException
     */
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final JBossServiceXmlDescriptor serviceXmlDescriptor = deploymentUnit.getAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY);
    if (serviceXmlDescriptor == null) {
        // Skip deployments without a service xml descriptor
        return;
    }
    // assert module
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null)
        throw SarLogger.ROOT_LOGGER.failedToGetAttachment("module", deploymentUnit);
    // assert reflection index
    final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
    if (reflectionIndex == null)
        throw SarLogger.ROOT_LOGGER.failedToGetAttachment("reflection index", deploymentUnit);
    // install services
    final ClassLoader classLoader = module.getClassLoader();
    final List<JBossServiceConfig> serviceConfigs = serviceXmlDescriptor.getServiceConfigs();
    final ServiceTarget target = phaseContext.getServiceTarget();
    final Map<String, ServiceComponentInstantiator> serviceComponents = deploymentUnit.getAttachment(ServiceAttachments.SERVICE_COMPONENT_INSTANTIATORS);
    for (final JBossServiceConfig serviceConfig : serviceConfigs) {
        addServices(target, serviceConfig, classLoader, reflectionIndex, serviceComponents != null ? serviceComponents.get(serviceConfig.getName()) : null, phaseContext);
    }
}
Also used : JBossServiceXmlDescriptor(org.jboss.as.service.descriptor.JBossServiceXmlDescriptor) ServiceTarget(org.jboss.msc.service.ServiceTarget) JBossServiceConfig(org.jboss.as.service.descriptor.JBossServiceConfig) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) ServiceComponentInstantiator(org.jboss.as.service.component.ServiceComponentInstantiator)

Example 14 with ServiceTarget

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

the class AbstractPojoPhase method startInternal.

protected void startInternal(StartContext context) throws StartException {
    try {
        executeInstalls();
        // only after describe do we have a bean
        if (getLifecycleState().isAfter(BeanState.DESCRIBED)) {
            addCallbacks(true);
            addCallbacks(false);
            ServiceRegistry registry = context.getController().getServiceContainer();
            InstancesService.addInstance(registry, context.getChildTarget(), getLifecycleState(), getBean());
        }
        // do we have a next phase
        final AbstractPojoPhase nextPhase = createNextPhase();
        if (nextPhase != null) {
            final BeanState state = getLifecycleState();
            final BeanState next = state.next();
            final BeanMetaDataConfig beanConfig = getBeanConfig();
            final ServiceName name = BeanMetaDataConfig.toBeanName(beanConfig.getName(), next);
            final ServiceTarget serviceTarget = context.getChildTarget();
            final ServiceBuilder serviceBuilder = serviceTarget.addService(name, nextPhase);
            registerAliases(serviceBuilder, next);
            final ConfigVisitor visitor = new DefaultConfigVisitor(serviceBuilder, state, getModule(), getIndex(), getBeanInfo());
            beanConfig.visit(visitor);
            nextPhase.setModule(getModule());
            nextPhase.setBeanConfig(getBeanConfig());
            nextPhase.setIndex(getIndex());
            nextPhase.setBeanInfo(getBeanInfo());
            nextPhase.setBean(getBean());
            serviceBuilder.install();
        }
    } catch (Throwable t) {
        throw new StartException(t);
    }
}
Also used : DefaultConfigVisitor(org.jboss.as.pojo.descriptor.DefaultConfigVisitor) ConfigVisitor(org.jboss.as.pojo.descriptor.ConfigVisitor) DefaultConfigVisitor(org.jboss.as.pojo.descriptor.DefaultConfigVisitor) BeanState(org.jboss.as.pojo.BeanState) BeanMetaDataConfig(org.jboss.as.pojo.descriptor.BeanMetaDataConfig) ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) StartException(org.jboss.msc.service.StartException) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 15 with ServiceTarget

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

the class SingletonServiceActivator method activate.

@Override
public void activate(ServiceActivatorContext context) {
    try {
        SingletonServiceBuilderFactory factory = (SingletonServiceBuilderFactory) context.getServiceRegistry().getRequiredService(SingletonServiceName.BUILDER.getServiceName(CONTAINER_NAME)).awaitValue();
        ServiceTarget target = context.getServiceTarget();
        install(target, factory, SERVICE_A_NAME, SERVICE_A_PREFERRED_NODE);
        install(target, factory, SERVICE_B_NAME, SERVICE_B_PREFERRED_NODE);
    } catch (InterruptedException e) {
        throw new ServiceRegistryException(e);
    }
}
Also used : SingletonServiceBuilderFactory(org.wildfly.clustering.singleton.SingletonServiceBuilderFactory) ServiceTarget(org.jboss.msc.service.ServiceTarget) ServiceRegistryException(org.jboss.msc.service.ServiceRegistryException)

Aggregations

ServiceTarget (org.jboss.msc.service.ServiceTarget)108 ServiceName (org.jboss.msc.service.ServiceName)57 PathAddress (org.jboss.as.controller.PathAddress)30 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)26 ModelNode (org.jboss.dmr.ModelNode)26 Module (org.jboss.modules.Module)18 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)15 OperationFailedException (org.jboss.as.controller.OperationFailedException)12 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)11 ContextNames (org.jboss.as.naming.deployment.ContextNames)11 Resource (org.jboss.as.controller.registry.Resource)10 BinderService (org.jboss.as.naming.service.BinderService)10 AbstractDeploymentChainStep (org.jboss.as.server.AbstractDeploymentChainStep)10 DeploymentProcessorTarget (org.jboss.as.server.DeploymentProcessorTarget)10 PathElement (org.jboss.as.controller.PathElement)9 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)9 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)9 ServiceController (org.jboss.msc.service.ServiceController)8 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5