Search in sources :

Example 1 with AliasServiceBuilder

use of org.wildfly.clustering.service.AliasServiceBuilder in project wildfly by wildfly.

the class CacheContainerServiceHandler method installServices.

@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    String name = context.getCurrentAddressValue();
    // This can happen if the ejb cache-container is added to a running server
    if (context.getProcessType().isServer() && !context.isBooting() && name.equals("ejb")) {
        Resource rootResource = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
        PathElement ejbPath = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "ejb3");
        if (rootResource.hasChild(ejbPath) && rootResource.getChild(ejbPath).hasChild(PathElement.pathElement("service", "remote"))) {
            // Following restart, these services will be installed by this handler, rather than the ejb remote handler
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
                    context.reloadRequired();
                    context.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER);
                }
            }, OperationContext.Stage.RUNTIME);
            return;
        }
    }
    ServiceTarget target = context.getServiceTarget();
    new ModuleBuilder(CacheContainerComponent.MODULE.getServiceName(address), MODULE).configure(context, model).build(target).install();
    new GlobalConfigurationBuilder(address).configure(context, model).build(target).install();
    CacheContainerBuilder containerBuilder = new CacheContainerBuilder(address).configure(context, model);
    containerBuilder.build(target).install();
    new KeyAffinityServiceFactoryBuilder(address).build(target).install();
    BinderServiceBuilder<?> bindingBuilder = new BinderServiceBuilder<>(InfinispanBindingFactory.createCacheContainerBinding(name), containerBuilder.getServiceName(), CacheContainer.class);
    ModelNodes.optionalString(JNDI_NAME.resolveModelAttribute(context, model)).map(jndiName -> ContextNames.bindInfoFor(JndiNameFactory.parse(jndiName).getAbsoluteName())).ifPresent(aliasBinding -> bindingBuilder.alias(aliasBinding));
    bindingBuilder.build(target).install();
    String defaultCache = containerBuilder.getDefaultCache();
    if (defaultCache != null) {
        DEFAULT_CAPABILITIES.entrySet().forEach(entry -> new AliasServiceBuilder<>(entry.getValue().getServiceName(address), entry.getKey().getServiceName(context, name, defaultCache), entry.getKey().getType()).build(target).install());
        if (!defaultCache.equals(JndiNameFactory.DEFAULT_LOCAL_NAME)) {
            new BinderServiceBuilder<>(InfinispanBindingFactory.createCacheBinding(name, JndiNameFactory.DEFAULT_LOCAL_NAME), DEFAULT_CAPABILITIES.get(InfinispanCacheRequirement.CACHE).getServiceName(address), Cache.class).build(target).install();
            new BinderServiceBuilder<>(InfinispanBindingFactory.createCacheConfigurationBinding(name, JndiNameFactory.DEFAULT_LOCAL_NAME), DEFAULT_CAPABILITIES.get(InfinispanCacheRequirement.CONFIGURATION).getServiceName(address), Configuration.class).build(target).install();
        }
        for (CacheAliasBuilderProvider provider : ServiceLoader.load(CacheAliasBuilderProvider.class, CacheAliasBuilderProvider.class.getClassLoader())) {
            for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> DEFAULT_CLUSTERING_CAPABILITIES.get(requirement).getServiceName(address), name, null, defaultCache)) {
                builder.configure(context).build(target).install();
            }
        }
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) BinderServiceBuilder(org.jboss.as.clustering.naming.BinderServiceBuilder) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ServiceNameProvider(org.wildfly.clustering.service.ServiceNameProvider) Cache(org.infinispan.Cache) CacheContainer(org.wildfly.clustering.infinispan.spi.CacheContainer) ModuleBuilder(org.jboss.as.clustering.controller.ModuleBuilder) OperationContext(org.jboss.as.controller.OperationContext) AliasServiceBuilder(org.wildfly.clustering.service.AliasServiceBuilder) CacheAliasBuilderProvider(org.wildfly.clustering.spi.CacheAliasBuilderProvider) DEFAULT_CLUSTERING_CAPABILITIES(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.DEFAULT_CLUSTERING_CAPABILITIES) CapabilityServiceBuilder(org.jboss.as.clustering.controller.CapabilityServiceBuilder) ServiceTarget(org.jboss.msc.service.ServiceTarget) Attribute(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Attribute) ModelDescriptionConstants(org.jboss.as.controller.descriptions.ModelDescriptionConstants) EnumSet(java.util.EnumSet) BinderServiceBuilder(org.jboss.as.clustering.naming.BinderServiceBuilder) ContextNames(org.jboss.as.naming.deployment.ContextNames) Resource(org.jboss.as.controller.registry.Resource) PathAddress(org.jboss.as.controller.PathAddress) ServiceLoader(java.util.ServiceLoader) PathElement(org.jboss.as.controller.PathElement) ModelNodes(org.jboss.as.clustering.dmr.ModelNodes) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) DEFAULT_CAPABILITIES(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.DEFAULT_CAPABILITIES) Configuration(org.infinispan.configuration.cache.Configuration) InfinispanCacheRequirement(org.wildfly.clustering.infinispan.spi.InfinispanCacheRequirement) ModelNode(org.jboss.dmr.ModelNode) JndiNameFactory(org.jboss.as.clustering.naming.JndiNameFactory) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ServiceTarget(org.jboss.msc.service.ServiceTarget) ModuleBuilder(org.jboss.as.clustering.controller.ModuleBuilder) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) CacheAliasBuilderProvider(org.wildfly.clustering.spi.CacheAliasBuilderProvider) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with AliasServiceBuilder

use of org.wildfly.clustering.service.AliasServiceBuilder in project wildfly by wildfly.

the class InfinispanCacheDeploymentListener method startCache.

@Override
public Wrapper startCache(Classification classification, Properties properties) throws Exception {
    String cache_type = properties.getProperty(CACHE_TYPE);
    String container = properties.getProperty(CONTAINER);
    // TODO Figure out how to access CapabilityServiceSupport from here
    ServiceName containerServiceName = ServiceName.parse(InfinispanRequirement.CONTAINER.resolve(container));
    EmbeddedCacheManager embeddedCacheManager;
    ServiceName serviceName;
    if (CACHE_PRIVATE.equals(cache_type)) {
        // need a private cache for non-jpa application use
        String name = properties.getProperty(NAME);
        serviceName = ServiceName.JBOSS.append(DEFAULT_CACHE_CONTAINER, (name != null) ? name : UUID.randomUUID().toString());
        ServiceContainer target = currentServiceContainer();
        // Create a mock service that represents this session factory instance
        ServiceBuilder<EmbeddedCacheManager> builder = new AliasServiceBuilder<>(serviceName, containerServiceName, EmbeddedCacheManager.class).build(target).setInitialMode(ServiceController.Mode.ACTIVE);
        embeddedCacheManager = ServiceContainerHelper.getValue(builder.install());
    } else {
        // need a shared cache for jpa applications
        serviceName = containerServiceName;
        ServiceRegistry registry = currentServiceContainer();
        embeddedCacheManager = (EmbeddedCacheManager) registry.getRequiredService(serviceName).getValue();
    }
    return new CacheWrapper(embeddedCacheManager, serviceName);
}
Also used : ServiceContainer(org.jboss.msc.service.ServiceContainer) CurrentServiceContainer(org.jboss.as.server.CurrentServiceContainer) ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) AliasServiceBuilder(org.wildfly.clustering.service.AliasServiceBuilder)

Example 3 with AliasServiceBuilder

use of org.wildfly.clustering.service.AliasServiceBuilder in project wildfly by wildfly.

the class SingletonServiceHandler method installServices.

@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
    String defaultPolicy = DEFAULT.resolveModelAttribute(context, model).asString();
    ServiceName serviceName = DEFAULT_POLICY.getServiceName(context.getCurrentAddress());
    ServiceName targetServiceName = SingletonServiceNameFactory.SINGLETON_POLICY.getServiceName(context, defaultPolicy);
    new AliasServiceBuilder<>(serviceName, targetServiceName, SingletonPolicy.class).build(context.getServiceTarget()).install();
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) AliasServiceBuilder(org.wildfly.clustering.service.AliasServiceBuilder)

Example 4 with AliasServiceBuilder

use of org.wildfly.clustering.service.AliasServiceBuilder in project wildfly by wildfly.

the class ChannelServiceHandler method installServices.

@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    String name = context.getCurrentAddressValue();
    String stack = STACK.resolveModelAttribute(context, model).asString();
    ServiceTarget target = context.getServiceTarget();
    new ChannelClusterBuilder(JCHANNEL_CLUSTER.getServiceName(address), name).configure(context, model).build(target).install();
    new ChannelBuilder(JCHANNEL.getServiceName(address), name).statisticsEnabled(STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean()).configure(context, model).build(target).install();
    new AliasServiceBuilder<>(JCHANNEL_FACTORY.getServiceName(address), JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, stack), JGroupsRequirement.CHANNEL_FACTORY.getType()).build(target).install();
    new ForkChannelFactoryBuilder(FORK_CHANNEL_FACTORY.getServiceName(address), name).configure(context, model).build(target).install();
    new ModuleBuilder(JCHANNEL_MODULE.getServiceName(address), MODULE).configure(context, model).build(target).install();
    new BinderServiceBuilder<>(JGroupsBindingFactory.createChannelBinding(name), JGroupsRequirement.CHANNEL.getServiceName(context, name), JGroupsRequirement.CHANNEL.getType()).build(target).install();
    new BinderServiceBuilder<>(JGroupsBindingFactory.createChannelFactoryBinding(name), JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, name), JGroupsRequirement.CHANNEL_FACTORY.getType()).build(target).install();
    // Install group services for channel
    for (GroupBuilderProvider provider : ServiceLoader.load(DistributedGroupBuilderProvider.class, DistributedGroupBuilderProvider.class.getClassLoader())) {
        for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> CLUSTERING_CAPABILITIES.get(requirement).getServiceName(address), name)) {
            JGroupsLogger.ROOT_LOGGER.debugf("Installing %s for channel %s", builder.getServiceName(), name);
            builder.configure(context).build(target).install();
        }
    }
}
Also used : BinderServiceBuilder(org.jboss.as.clustering.naming.BinderServiceBuilder) GroupBuilderProvider(org.wildfly.clustering.spi.GroupBuilderProvider) DistributedGroupBuilderProvider(org.wildfly.clustering.spi.DistributedGroupBuilderProvider) PathAddress(org.jboss.as.controller.PathAddress) ServiceTarget(org.jboss.msc.service.ServiceTarget) ModuleBuilder(org.jboss.as.clustering.controller.ModuleBuilder) DistributedGroupBuilderProvider(org.wildfly.clustering.spi.DistributedGroupBuilderProvider) AliasServiceBuilder(org.wildfly.clustering.service.AliasServiceBuilder)

Example 5 with AliasServiceBuilder

use of org.wildfly.clustering.service.AliasServiceBuilder in project wildfly by wildfly.

the class ForkServiceHandler method installServices.

@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
    super.installServices(context, model);
    PathAddress address = context.getCurrentAddress();
    String name = address.getLastElement().getValue();
    String channel = address.getParent().getLastElement().getValue();
    ServiceTarget target = context.getServiceTarget();
    new AliasServiceBuilder<>(FORK_CHANNEL_SOURCE.getServiceName(address), JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, channel), JGroupsRequirement.CHANNEL_FACTORY.getType()).build(target).install();
    new AliasServiceBuilder<>(FORK_CHANNEL_MODULE.getServiceName(address), JGroupsRequirement.CHANNEL_MODULE.getServiceName(context, channel), JGroupsRequirement.CHANNEL_MODULE.getType()).build(target).install();
    new AliasServiceBuilder<>(FORK_CHANNEL_CLUSTER.getServiceName(address), JGroupsRequirement.CHANNEL_CLUSTER.getServiceName(context, channel), JGroupsRequirement.CHANNEL_CLUSTER.getType()).build(target).install();
    new ChannelBuilder(FORK_CHANNEL.getServiceName(address), name).configure(context, model).build(target).install();
    new BinderServiceBuilder<>(JGroupsBindingFactory.createChannelBinding(name), JGroupsRequirement.CHANNEL.getServiceName(context, name), JGroupsRequirement.CHANNEL.getType()).build(target).install();
    new BinderServiceBuilder<>(JGroupsBindingFactory.createChannelFactoryBinding(name), JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, name), JGroupsRequirement.CHANNEL_FACTORY.getType()).build(target).install();
    for (GroupAliasBuilderProvider provider : ServiceLoader.load(GroupAliasBuilderProvider.class, GroupAliasBuilderProvider.class.getClassLoader())) {
        for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> CLUSTERING_CAPABILITIES.get(requirement).getServiceName(address), name, channel)) {
            builder.configure(context).build(target).install();
        }
    }
}
Also used : BinderServiceBuilder(org.jboss.as.clustering.naming.BinderServiceBuilder) GroupAliasBuilderProvider(org.wildfly.clustering.spi.GroupAliasBuilderProvider) PathAddress(org.jboss.as.controller.PathAddress) ServiceTarget(org.jboss.msc.service.ServiceTarget) AliasServiceBuilder(org.wildfly.clustering.service.AliasServiceBuilder)

Aggregations

AliasServiceBuilder (org.wildfly.clustering.service.AliasServiceBuilder)6 BinderServiceBuilder (org.jboss.as.clustering.naming.BinderServiceBuilder)4 PathAddress (org.jboss.as.controller.PathAddress)4 ServiceTarget (org.jboss.msc.service.ServiceTarget)4 ModuleBuilder (org.jboss.as.clustering.controller.ModuleBuilder)3 ServiceName (org.jboss.msc.service.ServiceName)3 EnumSet (java.util.EnumSet)2 ServiceLoader (java.util.ServiceLoader)2 Cache (org.infinispan.Cache)2 Configuration (org.infinispan.configuration.cache.Configuration)2 CapabilityServiceBuilder (org.jboss.as.clustering.controller.CapabilityServiceBuilder)2 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)2 ModelNodes (org.jboss.as.clustering.dmr.ModelNodes)2 JndiNameFactory (org.jboss.as.clustering.naming.JndiNameFactory)2 OperationContext (org.jboss.as.controller.OperationContext)2 OperationFailedException (org.jboss.as.controller.OperationFailedException)2 ContextNames (org.jboss.as.naming.deployment.ContextNames)2 ModelNode (org.jboss.dmr.ModelNode)2 ServiceNameProvider (org.wildfly.clustering.service.ServiceNameProvider)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1