コード例 #1
0
  private static void populate(ModelNode source, ModelNode target) throws OperationFailedException {
    // AS7-3488 make default-cache non required attrinbute
    // target.get(ModelKeys.DEFAULT_CACHE).set(source.get(ModelKeys.DEFAULT_CACHE));

    CacheContainerResourceDefinition.DEFAULT_CACHE.validateAndSet(source, target);
    // TODO: need to handle list types
    if (source.hasDefined(ModelKeys.ALIASES)) {
      target.get(ModelKeys.ALIASES).set(source.get(ModelKeys.ALIASES));
    }
    CacheContainerResourceDefinition.JNDI_NAME.validateAndSet(source, target);
    CacheContainerResourceDefinition.START.validateAndSet(source, target);
    CacheContainerResourceDefinition.LISTENER_EXECUTOR.validateAndSet(source, target);
    CacheContainerResourceDefinition.EVICTION_EXECUTOR.validateAndSet(source, target);
    CacheContainerResourceDefinition.REPLICATION_QUEUE_EXECUTOR.validateAndSet(source, target);
    CacheContainerResourceDefinition.MODULE.validateAndSet(source, target);
    CacheContainerResourceDefinition.STATISTICS_ENABLED.validateAndSet(source, target);
  }
コード例 #2
0
  Collection<ServiceController<?>> installRuntimeServices(
      OperationContext context,
      ModelNode operation,
      ModelNode containerModel,
      ServiceVerificationHandler verificationHandler)
      throws OperationFailedException {

    final PathAddress address = getCacheContainerAddressFromOperation(operation);
    final String name = address.getLastElement().getValue();
    final ServiceTarget target = context.getServiceTarget();

    // pick up the attribute values from the model
    ModelNode resolvedValue = null;
    // make default cache non required (AS7-3488)
    final String defaultCache =
        (resolvedValue =
                    CacheContainerResourceDefinition.DEFAULT_CACHE.resolveModelAttribute(
                        context, containerModel))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final String jndiName =
        (resolvedValue =
                    CacheContainerResourceDefinition.JNDI_NAME.resolveModelAttribute(
                        context, containerModel))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final String listenerExecutor =
        (resolvedValue =
                    CacheContainerResourceDefinition.LISTENER_EXECUTOR.resolveModelAttribute(
                        context, containerModel))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final String evictionExecutor =
        (resolvedValue =
                    CacheContainerResourceDefinition.EVICTION_EXECUTOR.resolveModelAttribute(
                        context, containerModel))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final String replicationQueueExecutor =
        (resolvedValue =
                    CacheContainerResourceDefinition.REPLICATION_QUEUE_EXECUTOR
                        .resolveModelAttribute(context, containerModel))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final ServiceController.Mode initialMode =
        StartMode.valueOf(
                CacheContainerResourceDefinition.START
                    .resolveModelAttribute(context, containerModel)
                    .asString())
            .getMode();
    final boolean statistics =
        CacheContainerResourceDefinition.STATISTICS_ENABLED
            .resolveModelAttribute(context, containerModel)
            .asBoolean();

    ServiceName[] aliases = null;
    if (containerModel.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());
      }
    }

    final ModuleIdentifier moduleId =
        (resolvedValue =
                    CacheContainerResourceDefinition.MODULE.resolveModelAttribute(
                        context, containerModel))
                .isDefined()
            ? ModuleIdentifier.fromString(resolvedValue.asString())
            : null;

    // if we have a transport defined, pick up the transport-related attributes and install a
    // channel
    final Transport transportConfig =
        containerModel.hasDefined(ModelKeys.TRANSPORT)
                && containerModel.get(ModelKeys.TRANSPORT).hasDefined(ModelKeys.TRANSPORT_NAME)
            ? new Transport()
            : null;

    String stack = null;
    String transportExecutor = null;

    Collection<ServiceController<?>> controllers = new LinkedList<>();

    if (transportConfig != null) {
      ModelNode transport = containerModel.get(ModelKeys.TRANSPORT, ModelKeys.TRANSPORT_NAME);

      stack =
          (resolvedValue =
                      TransportResourceDefinition.STACK.resolveModelAttribute(context, transport))
                  .isDefined()
              ? resolvedValue.asString()
              : null;
      // if cluster is not defined, use the cache container name as the default
      final String cluster =
          (resolvedValue =
                      TransportResourceDefinition.CLUSTER.resolveModelAttribute(context, transport))
                  .isDefined()
              ? resolvedValue.asString()
              : name;
      long lockTimeout =
          TransportResourceDefinition.LOCK_TIMEOUT
              .resolveModelAttribute(context, transport)
              .asLong();
      transportExecutor =
          (resolvedValue =
                      TransportResourceDefinition.EXECUTOR.resolveModelAttribute(
                          context, transport))
                  .isDefined()
              ? resolvedValue.asString()
              : null;

      // initialise the Transport
      transportConfig.setClusterName(cluster);
      transportConfig.setLockTimeout(lockTimeout);

      controllers.addAll(
          this.installChannelServices(target, name, cluster, stack, verificationHandler));

      // register the protocol metrics by adding a step
      ChannelInstanceResourceDefinition.addChannelProtocolMetricsRegistrationStep(
          context, cluster, stack);

      for (ChannelServiceProvider provider :
          ServiceLoader.load(
              ChannelServiceProvider.class, ChannelServiceProvider.class.getClassLoader())) {
        log.debugf("Installing %s for channel %s", provider.getClass().getSimpleName(), cluster);
        controllers.addAll(provider.install(target, name, moduleId));
      }
    }

    // install the cache container configuration service
    controllers.add(
        this.installContainerConfigurationService(
            target,
            name,
            defaultCache,
            statistics,
            moduleId,
            stack,
            transportConfig,
            transportExecutor,
            listenerExecutor,
            evictionExecutor,
            replicationQueueExecutor,
            verificationHandler));

    // install a cache container service
    controllers.add(
        this.installContainerService(
            target, name, aliases, transportConfig, initialMode, verificationHandler));

    // install a name service entry for the cache container
    controllers.add(this.installJndiService(target, name, jndiName, verificationHandler));

    controllers.add(
        this.installKeyAffinityServiceFactoryService(target, name, verificationHandler));

    controllers.add(
        this.installGlobalComponentRegistryService(
            target, name, transportConfig, verificationHandler));

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