void removeRuntimeServices( OperationContext context, ModelNode operation, ModelNode containerModel, ModelNode cacheModel) throws OperationFailedException { // get container and cache addresses final PathAddress cacheAddress = getCacheAddressFromOperation(operation); final PathAddress containerAddress = getCacheContainerAddressFromOperation(operation); // get container and cache names final String cacheName = cacheAddress.getLastElement().getValue(); final String containerName = containerAddress.getLastElement().getValue(); // remove all services started by CacheAdd, in reverse order // remove the binder service ModelNode resolvedValue = null; final String jndiName = (resolvedValue = CacheResourceDefinition.JNDI_NAME.resolveModelAttribute(context, cacheModel)) .isDefined() ? resolvedValue.asString() : null; String defaultCacheName = CacheContainerResourceDefinition.DEFAULT_CACHE .resolveModelAttribute(context, containerModel) .asString(); boolean defaultCache = cacheName.equals(defaultCacheName); ContextNames.BindInfo binding = createCacheBinding( (jndiName != null) ? JndiNameFactory.parse(jndiName) : createJndiName(containerName, cacheName)); context.removeService(binding.getBinderServiceName()); // remove the CacheService instance context.removeService(CacheService.getServiceName(containerName, cacheName)); // remove the cache configuration service context.removeService(CacheConfigurationService.getServiceName(containerName, cacheName)); for (CacheServiceProvider provider : ServiceLoader.load( CacheServiceProvider.class, CacheServiceProvider.class.getClassLoader())) { for (ServiceName name : provider.getServiceNames(containerName, cacheName, defaultCache)) { context.removeService(name); } } log.debugf("cache %s removed for container %s", cacheName, containerName); }
Collection<ServiceController<?>> installRuntimeServices( OperationContext context, ModelNode operation, ModelNode containerModel, ModelNode cacheModel, ServiceVerificationHandler verificationHandler) throws OperationFailedException { // get all required addresses, names and service names PathAddress cacheAddress = getCacheAddressFromOperation(operation); PathAddress containerAddress = getCacheContainerAddressFromOperation(operation); String cacheName = cacheAddress.getLastElement().getValue(); String containerName = containerAddress.getLastElement().getValue(); // get model attributes ModelNode resolvedValue = null; final String jndiName = ((resolvedValue = CacheResourceDefinition.JNDI_NAME.resolveModelAttribute(context, cacheModel)) .isDefined()) ? resolvedValue.asString() : null; final ServiceController.Mode initialMode = StartMode.valueOf( CacheResourceDefinition.START.resolveModelAttribute(context, cacheModel).asString()) .getMode(); final ModuleIdentifier moduleId = (resolvedValue = CacheResourceDefinition.CACHE_MODULE.resolveModelAttribute(context, cacheModel)) .isDefined() ? ModuleIdentifier.fromString(resolvedValue.asString()) : null; // create a list for dependencies which may need to be added during processing List<Dependency<?>> dependencies = new LinkedList<Dependency<?>>(); // Infinispan Configuration to hold the operation data ConfigurationBuilder builder = new ConfigurationBuilder().read(getDefaultConfiguration(this.mode)); // process cache configuration ModelNode describing overrides to defaults processModelNode(context, containerName, cacheModel, builder, dependencies); // get container Model to pick up the value of the default cache of the container // AS7-3488 make default-cache no required attribute String defaultCacheName = CacheContainerResourceDefinition.DEFAULT_CACHE .resolveModelAttribute(context, containerModel) .asString(); boolean defaultCache = cacheName.equals(defaultCacheName); ServiceTarget target = context.getServiceTarget(); Configuration config = builder.build(); Collection<ServiceController<?>> controllers = new ArrayList<ServiceController<?>>(3); // install the cache configuration service (configures a cache) controllers.add( this.installCacheConfigurationService( target, containerName, cacheName, defaultCache, moduleId, builder, config, dependencies, verificationHandler)); log.debugf( "Cache configuration service for %s installed for container %s", cacheName, containerName); // now install the corresponding cache service (starts a configured cache) controllers.add( this.installCacheService( target, containerName, cacheName, defaultCache, initialMode, config, verificationHandler)); // install a name service entry for the cache controllers.add( this.installJndiService( target, containerName, cacheName, defaultCache, jndiName, verificationHandler)); log.debugf("Cache service for cache %s installed for container %s", cacheName, containerName); if (config.clustering().cacheMode().isClustered()) { for (CacheServiceProvider provider : ServiceLoader.load( CacheServiceProvider.class, CacheServiceProvider.class.getClassLoader())) { log.debugf( "Installing %s for cache %s/%s", provider.getClass().getSimpleName(), containerName, cacheName); controllers.addAll( provider.install(target, containerName, cacheName, defaultCache, moduleId)); } } return controllers; }