private static ContextNames.BindInfo createCacheContainerBinding(
     String jndiName, String container) {
   JndiName name =
       (jndiName != null)
           ? JndiNameFactory.parse(jndiName)
           : JndiNameFactory.createJndiName(
               JndiNameFactory.DEFAULT_JNDI_NAMESPACE,
               InfinispanExtension.SUBSYSTEM_NAME,
               "container",
               container);
   return ContextNames.bindInfoFor(name.getAbsoluteName());
 }
Esempio n. 2
0
  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);
  }
Esempio n. 3
0
  @SuppressWarnings("rawtypes")
  ServiceController<?> installJndiService(
      ServiceTarget target,
      String containerName,
      String cacheName,
      boolean defaultCache,
      String jndiName,
      ServiceVerificationHandler verificationHandler) {

    final ServiceName cacheServiceName = CacheService.getServiceName(containerName, cacheName);
    final ContextNames.BindInfo binding =
        createCacheBinding(
            (jndiName != null)
                ? JndiNameFactory.parse(jndiName)
                : createJndiName(containerName, cacheName));
    final BinderService binder = new BinderService(binding.getBindName());
    ServiceBuilder<?> builder =
        target
            .addService(binding.getBinderServiceName(), binder)
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(binding.getBindName()))
            .addDependency(
                cacheServiceName,
                Cache.class,
                new ManagedReferenceInjector<Cache>(binder.getManagedObjectInjector()))
            .addDependency(
                binding.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binder.getNamingStoreInjector())
            .setInitialMode(ServiceController.Mode.PASSIVE);
    if (defaultCache) {
      ContextNames.BindInfo defaultBinding =
          createCacheBinding(createJndiName(containerName, CacheContainer.DEFAULT_CACHE_ALIAS));
      builder.addAliases(
          defaultBinding.getBinderServiceName(),
          ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(defaultBinding.getBindName()));
    }
    return builder.install();
  }