예제 #1
0
  ServiceController<?> installContainerService(
      ServiceTarget target,
      String containerName,
      ServiceName[] aliases,
      Transport transport,
      ServiceController.Mode initialMode,
      ServiceVerificationHandler verificationHandler) {

    final ServiceName containerServiceName =
        EmbeddedCacheManagerService.getServiceName(containerName);
    final ServiceName configServiceName =
        EmbeddedCacheManagerConfigurationService.getServiceName(containerName);
    final InjectedValue<EmbeddedCacheManagerConfiguration> config = new InjectedValue<>();
    final Service<EmbeddedCacheManager> service = new EmbeddedCacheManagerService(config);
    ServiceBuilder<EmbeddedCacheManager> builder =
        target
            .addService(containerServiceName, service)
            .addDependency(configServiceName, EmbeddedCacheManagerConfiguration.class, config)
            .addAliases(aliases)
            .setInitialMode(initialMode);
    if (transport != null) {
      builder.addDependency(ChannelService.getServiceName(containerName));
    }
    return builder.install();
  }
예제 #2
0
  Collection<ServiceController<?>> installChannelServices(
      ServiceTarget target,
      String containerName,
      String cluster,
      String stack,
      ServiceVerificationHandler verificationHandler) {

    ServiceName name = ChannelService.getServiceName(containerName);
    ContextNames.BindInfo bindInfo = createChannelBinding(containerName);
    BinderService binder = new BinderService(bindInfo.getBindName());
    ServiceController<?> binderService =
        target
            .addService(bindInfo.getBinderServiceName(), binder)
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(bindInfo.getBindName()))
            .addDependency(
                name,
                Channel.class,
                new ManagedReferenceInjector<Channel>(binder.getManagedObjectInjector()))
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binder.getNamingStoreInjector())
            .setInitialMode(ServiceController.Mode.PASSIVE)
            .install();

    InjectedValue<ChannelFactory> channelFactory = new InjectedValue<>();
    ServiceController<?> channelService =
        AsynchronousService.addService(target, name, new ChannelService(cluster, channelFactory))
            .addDependency(
                ChannelFactoryService.getServiceName(stack), ChannelFactory.class, channelFactory)
            .setInitialMode(ServiceController.Mode.ON_DEMAND)
            .install();

    return Arrays.asList(binderService, channelService);
  }
예제 #3
0
  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);
    }
  }
예제 #4
0
  ServiceController<?> installCacheService(
      ServiceTarget target,
      String containerName,
      String cacheName,
      String 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(CacheConfigurationService.getServiceName(containerName, cacheName))
            .addDependency(
                EmbeddedCacheManagerService.getServiceName(containerName),
                EmbeddedCacheManager.class,
                container)
            .addDependency(
                config.clustering().cacheMode().isClustered()
                    ? DependencyType.REQUIRED
                    : DependencyType.OPTIONAL,
                ChannelService.getServiceName(containerName))
            .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 (cacheName.equals(defaultCache)) {
      builder.addAliases(CacheService.getServiceName(containerName, null));
    }

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

    return builder.install();
  }
예제 #5
0
 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();
 }
예제 #6
0
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    // Because we use child resources in a read-only manner to configure the cache container,
    // replace the local model with the full model
    model = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));

    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String name = address.getLastElement().getValue();

    String defaultCache = model.require(ModelKeys.DEFAULT_CACHE).asString();

    boolean hasTransport =
        model.hasDefined(ModelKeys.TRANSPORT)
            && model.get(ModelKeys.TRANSPORT).hasDefined(ModelKeys.TRANSPORT_NAME);
    Transport transportConfig = hasTransport ? new Transport() : null;
    EmbeddedCacheManagerDependencies dependencies =
        new EmbeddedCacheManagerDependencies(transportConfig);

    ServiceName[] aliases = null;
    if (model.hasDefined(ModelKeys.ALIASES)) {
      List<ModelNode> list = operation.get(ModelKeys.ALIASES).asList();
      aliases = new ServiceName[list.size()];
      for (int i = 0; i < list.size(); i++) {
        aliases[i] = EmbeddedCacheManagerService.getServiceName(list.get(i).asString());
      }
    }

    ServiceTarget target = context.getServiceTarget();
    ServiceName serviceName = EmbeddedCacheManagerService.getServiceName(name);
    ServiceBuilder<EmbeddedCacheManager> containerBuilder =
        target
            .addService(
                serviceName, new EmbeddedCacheManagerService(name, defaultCache, dependencies))
            .addDependency(
                DependencyType.OPTIONAL,
                ServiceName.JBOSS.append("mbean", "server"),
                MBeanServer.class,
                dependencies.getMBeanServerInjector())
            .addAliases(aliases)
            .setInitialMode(ServiceController.Mode.ON_DEMAND);

    String jndiName =
        (model.hasDefined(ModelKeys.JNDI_NAME)
                ? InfinispanJndiName.toJndiName(model.get(ModelKeys.JNDI_NAME).asString())
                : InfinispanJndiName.defaultCacheContainerJndiName(name))
            .getAbsoluteName();
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);

    BinderService binder = new BinderService(bindInfo.getBindName());
    ServiceBuilder<ManagedReferenceFactory> binderBuilder =
        target
            .addService(bindInfo.getBinderServiceName(), binder)
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(jndiName))
            .addDependency(
                serviceName,
                CacheContainer.class,
                new ManagedReferenceInjector<CacheContainer>(binder.getManagedObjectInjector()))
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binder.getNamingStoreInjector())
            .setInitialMode(ServiceController.Mode.ON_DEMAND);
    newControllers.add(binderBuilder.install());

    if (hasTransport) {
      String stack = null;
      ModelNode transport = model.get(ModelKeys.TRANSPORT, ModelKeys.TRANSPORT_NAME);
      if (transport.hasDefined(ModelKeys.STACK)) {
        stack = transport.get(ModelKeys.STACK).asString();
      }
      if (transport.hasDefined(ModelKeys.LOCK_TIMEOUT)) {
        transportConfig.setLockTimeout(transport.get(ModelKeys.LOCK_TIMEOUT).asLong());
      }
      addExecutorDependency(
          containerBuilder, transport, ModelKeys.EXECUTOR, transportConfig.getExecutorInjector());

      ServiceName channelServiceName = ChannelService.getServiceName(name);
      containerBuilder.addDependency(
          channelServiceName, Channel.class, transportConfig.getChannelInjector());

      InjectedValue<ChannelFactory> channelFactory = new InjectedValue<ChannelFactory>();
      ServiceBuilder<Channel> channelBuilder =
          target
              .addService(channelServiceName, new ChannelService(name, channelFactory))
              .addDependency(
                  ChannelFactoryService.getServiceName(stack), ChannelFactory.class, channelFactory)
              .setInitialMode(ServiceController.Mode.ON_DEMAND);
      newControllers.add(channelBuilder.install());
    }

    addExecutorDependency(
        containerBuilder,
        model,
        ModelKeys.LISTENER_EXECUTOR,
        dependencies.getListenerExecutorInjector());
    addScheduledExecutorDependency(
        containerBuilder,
        model,
        ModelKeys.EVICTION_EXECUTOR,
        dependencies.getEvictionExecutorInjector());
    addScheduledExecutorDependency(
        containerBuilder,
        model,
        ModelKeys.REPLICATION_QUEUE_EXECUTOR,
        dependencies.getReplicationQueueExecutorInjector());

    newControllers.add(containerBuilder.install());

    log.debugf("%s cache container installed", name);
  }