void removeRuntimeServices(OperationContext context, ModelNode operation, ModelNode model)
      throws OperationFailedException {

    final PathAddress address = getCacheContainerAddressFromOperation(operation);
    final String containerName = address.getLastElement().getValue();

    // need to remove all container-related services started, in reverse order
    context.removeService(KeyAffinityServiceFactoryService.getServiceName(containerName));

    // remove the BinderService entry
    ModelNode resolvedValue = null;
    final String jndiName =
        (resolvedValue =
                    CacheContainerResourceDefinition.JNDI_NAME.resolveModelAttribute(
                        context, model))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    context.removeService(
        createCacheContainerBinding(jndiName, containerName).getBinderServiceName());

    // remove the cache container
    context.removeService(EmbeddedCacheManagerService.getServiceName(containerName));
    context.removeService(EmbeddedCacheManagerConfigurationService.getServiceName(containerName));
    context.removeService(GlobalComponentRegistryService.getServiceName(containerName));

    // check if a channel was installed
    final ServiceName channelServiceName = ChannelService.getServiceName(containerName);
    final ServiceController<?> channelServiceController =
        context.getServiceRegistry(false).getService(channelServiceName);
    if (channelServiceController != null) {
      for (ChannelServiceProvider provider :
          ServiceLoader.load(
              ChannelServiceProvider.class, ChannelServiceProvider.class.getClassLoader())) {
        for (ServiceName name : provider.getServiceNames(containerName)) {
          context.removeService(name);
        }
      }
      // unregister the protocol metrics by adding a step
      ChannelInstanceResourceDefinition.addChannelProtocolMetricsDeregistrationStep(
          context, containerName);

      context.removeService(createChannelBinding(containerName).getBinderServiceName());
      context.removeService(channelServiceName);
    }
  }
Exemple #2
0
  ServiceController<?> installCacheService(
      ServiceTarget target,
      String containerName,
      String cacheName,
      boolean defaultCache,
      ServiceController.Mode initialMode,
      Configuration config,
      ServiceVerificationHandler verificationHandler) {

    final InjectedValue<EmbeddedCacheManager> container = new InjectedValue<EmbeddedCacheManager>();
    final CacheDependencies cacheDependencies = new CacheDependencies(container);
    final Service<Cache<Object, Object>> service =
        new CacheService<Object, Object>(cacheName, cacheDependencies);
    final ServiceBuilder<?> builder =
        AsynchronousService.addService(
                target, CacheService.getServiceName(containerName, cacheName), service)
            .addDependency(GlobalComponentRegistryService.getServiceName(containerName))
            .addDependency(CacheConfigurationService.getServiceName(containerName, cacheName))
            .addDependency(
                EmbeddedCacheManagerService.getServiceName(containerName),
                EmbeddedCacheManager.class,
                container)
            .setInitialMode(initialMode);
    if (config.transaction().recovery().enabled()) {
      builder.addDependency(
          TxnServices.JBOSS_TXN_ARJUNA_RECOVERY_MANAGER,
          XAResourceRecoveryRegistry.class,
          cacheDependencies.getRecoveryRegistryInjector());
    }

    // add an alias for the default cache
    if (defaultCache) {
      builder.addAliases(CacheService.getServiceName(containerName, null));
    }

    if (initialMode == ServiceController.Mode.ACTIVE) {
      builder.addListener(verificationHandler);
    }

    return builder.install();
  }
 ServiceController<?> installGlobalComponentRegistryService(
     ServiceTarget target,
     String containerName,
     Transport transport,
     ServiceVerificationHandler verificationHandler) {
   InjectedValue<CacheContainer> container = new InjectedValue<>();
   ServiceBuilder<?> builder =
       AsynchronousService.addService(
               target,
               GlobalComponentRegistryService.getServiceName(containerName),
               new GlobalComponentRegistryService(container))
           .addDependency(
               EmbeddedCacheManagerService.getServiceName(containerName),
               CacheContainer.class,
               container)
           .setInitialMode(ServiceController.Mode.ON_DEMAND);
   if (transport != null) {
     builder.addDependency(ChannelService.getServiceName(containerName));
   }
   return builder.install();
 }