示例#1
0
  /**
   * Transfer elements common to both operations and models
   *
   * @param fromModel
   * @param toModel
   */
  void populate(ModelNode fromModel, ModelNode toModel) throws OperationFailedException {

    CacheResourceDefinition.START.validateAndSet(fromModel, toModel);
    CacheResourceDefinition.BATCHING.validateAndSet(fromModel, toModel);
    CacheResourceDefinition.INDEXING.validateAndSet(fromModel, toModel);
    CacheResourceDefinition.JNDI_NAME.validateAndSet(fromModel, toModel);
    CacheResourceDefinition.CACHE_MODULE.validateAndSet(fromModel, toModel);
    CacheResourceDefinition.INDEXING_PROPERTIES.validateAndSet(fromModel, toModel);
  }
示例#2
0
  /**
   * Create a Configuration object initialized from the operation ModelNode
   *
   * @param containerName the name of the cache container
   * @param cache ModelNode representing cache configuration
   * @param builder ConfigurationBuilder object to add data to
   * @return initialised Configuration object
   */
  void processModelNode(
      OperationContext context,
      String containerName,
      ModelNode cache,
      ConfigurationBuilder builder,
      List<Dependency<?>> dependencies)
      throws OperationFailedException {

    final Indexing indexing =
        Indexing.valueOf(
            CacheResourceDefinition.INDEXING.resolveModelAttribute(context, cache).asString());
    final boolean batching =
        CacheResourceDefinition.BATCHING.resolveModelAttribute(context, cache).asBoolean();

    // set the cache mode (may be modified when setting up clustering attributes)
    builder.clustering().cacheMode(this.mode);
    final ModelNode indexingPropertiesModel =
        CacheResourceDefinition.INDEXING_PROPERTIES.resolveModelAttribute(context, cache);
    Properties indexingProperties = new Properties();
    if (indexing.isEnabled() && indexingPropertiesModel.isDefined()) {
      for (Property p : indexingPropertiesModel.asPropertyList()) {
        String value = p.getValue().asString();
        indexingProperties.put(p.getName(), value);
      }
    }
    builder
        .indexing()
        .enabled(indexing.isEnabled())
        .indexLocalOnly(indexing.isLocalOnly())
        .withProperties(indexingProperties);

    // locking is a child resource
    if (cache.hasDefined(ModelKeys.LOCKING)
        && cache.get(ModelKeys.LOCKING, ModelKeys.LOCKING_NAME).isDefined()) {
      ModelNode locking = cache.get(ModelKeys.LOCKING, ModelKeys.LOCKING_NAME);

      final IsolationLevel isolationLevel =
          IsolationLevel.valueOf(
              LockingResource.ISOLATION.resolveModelAttribute(context, locking).asString());
      final boolean striping =
          LockingResource.STRIPING.resolveModelAttribute(context, locking).asBoolean();
      final long acquireTimeout =
          LockingResource.ACQUIRE_TIMEOUT.resolveModelAttribute(context, locking).asLong();
      final int concurrencyLevel =
          LockingResource.CONCURRENCY_LEVEL.resolveModelAttribute(context, locking).asInt();

      builder
          .locking()
          .isolationLevel(isolationLevel)
          .useLockStriping(striping)
          .lockAcquisitionTimeout(acquireTimeout)
          .concurrencyLevel(concurrencyLevel);
    }

    TransactionMode txMode = TransactionMode.NONE;
    LockingMode lockingMode = LockingMode.OPTIMISTIC;
    // locking is a child resource
    if (cache.hasDefined(ModelKeys.TRANSACTION)
        && cache.get(ModelKeys.TRANSACTION, ModelKeys.TRANSACTION_NAME).isDefined()) {
      ModelNode transaction = cache.get(ModelKeys.TRANSACTION, ModelKeys.TRANSACTION_NAME);

      final long stopTimeout =
          TransactionResourceDefinition.STOP_TIMEOUT
              .resolveModelAttribute(context, transaction)
              .asLong();
      txMode =
          TransactionMode.valueOf(
              TransactionResourceDefinition.MODE
                  .resolveModelAttribute(context, transaction)
                  .asString());
      lockingMode =
          LockingMode.valueOf(
              TransactionResourceDefinition.LOCKING
                  .resolveModelAttribute(context, transaction)
                  .asString());

      builder.transaction().cacheStopTimeout(stopTimeout);
    }
    builder
        .transaction()
        .transactionMode(txMode.getMode())
        .lockingMode(lockingMode)
        .useSynchronization(!txMode.isXAEnabled())
        .recovery()
        .enabled(txMode.isRecoveryEnabled());
    if (txMode.isRecoveryEnabled()) {
      builder.transaction().syncCommitPhase(true).syncRollbackPhase(true);
    }

    if (batching) {
      builder
          .transaction()
          .transactionMode(org.infinispan.transaction.TransactionMode.TRANSACTIONAL)
          .invocationBatching()
          .enable();
    } else {
      builder.transaction().invocationBatching().disable();
    }

    // eviction is a child resource
    if (cache.hasDefined(ModelKeys.EVICTION)
        && cache.get(ModelKeys.EVICTION, ModelKeys.EVICTION_NAME).isDefined()) {
      ModelNode eviction = cache.get(ModelKeys.EVICTION, ModelKeys.EVICTION_NAME);

      final EvictionStrategy strategy =
          EvictionStrategy.valueOf(
              EvictionResourceDefinition.EVICTION_STRATEGY
                  .resolveModelAttribute(context, eviction)
                  .asString());
      builder.eviction().strategy(strategy);

      if (strategy.isEnabled()) {
        final int maxEntries =
            EvictionResourceDefinition.MAX_ENTRIES.resolveModelAttribute(context, eviction).asInt();
        builder.eviction().maxEntries(maxEntries);
      }
    }
    // expiration is a child resource
    if (cache.hasDefined(ModelKeys.EXPIRATION)
        && cache.get(ModelKeys.EXPIRATION, ModelKeys.EXPIRATION_NAME).isDefined()) {

      ModelNode expiration = cache.get(ModelKeys.EXPIRATION, ModelKeys.EXPIRATION_NAME);

      final long maxIdle =
          ExpirationResourceDefinition.MAX_IDLE.resolveModelAttribute(context, expiration).asLong();
      final long lifespan =
          ExpirationResourceDefinition.LIFESPAN.resolveModelAttribute(context, expiration).asLong();
      final long interval =
          ExpirationResourceDefinition.INTERVAL.resolveModelAttribute(context, expiration).asLong();

      builder.expiration().maxIdle(maxIdle).lifespan(lifespan).wakeUpInterval(interval);
      // Only enable the reaper thread if we need it
      if ((maxIdle > 0) || (lifespan > 0)) {
        builder.expiration().enableReaper();
      } else {
        builder.expiration().disableReaper();
      }
    }

    // stores are a child resource
    String storeKey = this.findStoreKey(cache);
    if (storeKey != null) {
      ModelNode store = this.getStoreModelNode(cache);

      final boolean shared =
          BaseStoreResourceDefinition.SHARED.resolveModelAttribute(context, store).asBoolean();
      final boolean preload =
          BaseStoreResourceDefinition.PRELOAD.resolveModelAttribute(context, store).asBoolean();
      final boolean passivation =
          BaseStoreResourceDefinition.PASSIVATION.resolveModelAttribute(context, store).asBoolean();
      final boolean fetchState =
          BaseStoreResourceDefinition.FETCH_STATE.resolveModelAttribute(context, store).asBoolean();
      final boolean purge =
          BaseStoreResourceDefinition.PURGE.resolveModelAttribute(context, store).asBoolean();
      final boolean singleton =
          BaseStoreResourceDefinition.SINGLETON.resolveModelAttribute(context, store).asBoolean();
      // TODO Fix me
      final boolean async =
          store.hasDefined(ModelKeys.WRITE_BEHIND)
              && store.get(ModelKeys.WRITE_BEHIND, ModelKeys.WRITE_BEHIND_NAME).isDefined();

      LoadersConfigurationBuilder loadersBuilder =
          builder.loaders().shared(shared).preload(preload).passivation(passivation);
      CacheStoreConfigurationBuilder<?, ?> storeBuilder =
          this.buildCacheStore(
                  context, loadersBuilder, containerName, store, storeKey, dependencies)
              .fetchPersistentState(fetchState)
              .purgeOnStartup(purge)
              .purgeSynchronously(true);
      storeBuilder.singletonStore().enabled(singleton);

      if (async) {
        ModelNode writeBehind = store.get(ModelKeys.WRITE_BEHIND, ModelKeys.WRITE_BEHIND_NAME);
        storeBuilder
            .async()
            .enable()
            .flushLockTimeout(
                StoreWriteBehindResourceDefinition.FLUSH_LOCK_TIMEOUT
                    .resolveModelAttribute(context, writeBehind)
                    .asLong())
            .modificationQueueSize(
                StoreWriteBehindResourceDefinition.MODIFICATION_QUEUE_SIZE
                    .resolveModelAttribute(context, writeBehind)
                    .asInt())
            .shutdownTimeout(
                StoreWriteBehindResourceDefinition.SHUTDOWN_TIMEOUT
                    .resolveModelAttribute(context, writeBehind)
                    .asLong())
            .threadPoolSize(
                StoreWriteBehindResourceDefinition.THREAD_POOL_SIZE
                    .resolveModelAttribute(context, writeBehind)
                    .asInt());
      }

      final Properties properties = new TypedProperties();
      if (store.hasDefined(ModelKeys.PROPERTY)) {
        for (Property property : store.get(ModelKeys.PROPERTY).asPropertyList()) {
          // format of properties
          // "property" => {
          //   "property-name" => {"value => "property-value"}
          // }
          String propertyName = property.getName();
          // get the value from ModelNode {"value" => "property-value"}
          ModelNode propertyValue = null;
          propertyValue =
              StorePropertyResourceDefinition.VALUE.resolveModelAttribute(
                  context, property.getValue());
          properties.setProperty(propertyName, propertyValue.asString());
        }
      }
      storeBuilder.withProperties(properties);
    }
  }