Exemple #1
0
  /**
   * Adds all common child elements with the "defaultCache" element in ehcache.xsd
   *
   * @param element
   * @param cacheConfiguration
   */
  public static void addCommonChildElementsWithDefaultCache(
      NodeElement element, CacheConfiguration cacheConfiguration) {
    for (FactoryConfigurationElement child :
        getAllFactoryElements(
            element,
            "cacheEventListenerFactory",
            cacheConfiguration.getCacheEventListenerConfigurations())) {
      CacheEventListenerFactoryConfiguration factoryConfiguration =
          (CacheEventListenerFactoryConfiguration) child.getFactoryConfiguration();
      child.addAttribute(new SimpleNodeAttribute("listenFor", factoryConfiguration.getListenFor()));
      element.addChildElement(child);
    }
    addAllFactoryConfigsAsChildElements(
        element, "cacheExtensionFactory", cacheConfiguration.getCacheExtensionConfigurations());
    addAllFactoryConfigsAsChildElements(
        element, "cacheLoaderFactory", cacheConfiguration.getCacheLoaderConfigurations());

    BootstrapCacheLoaderFactoryConfiguration bootstrapCacheLoaderFactoryConfiguration =
        cacheConfiguration.getBootstrapCacheLoaderFactoryConfiguration();
    if (bootstrapCacheLoaderFactoryConfiguration != null) {
      element.addChildElement(
          new FactoryConfigurationElement(
              element, "bootstrapCacheLoaderFactory", bootstrapCacheLoaderFactoryConfiguration));
    }
    CacheExceptionHandlerFactoryConfiguration cacheExceptionHandlerFactoryConfiguration =
        cacheConfiguration.getCacheExceptionHandlerFactoryConfiguration();
    if (cacheExceptionHandlerFactoryConfiguration != null) {
      element.addChildElement(
          new FactoryConfigurationElement(
              element, "cacheExceptionHandlerFactory", cacheExceptionHandlerFactoryConfiguration));
    }
    CopyStrategyConfiguration copyStrategyConfiguration =
        cacheConfiguration.getCopyStrategyConfiguration();
    if (copyStrategyConfiguration != null
        && !copyStrategyConfiguration.equals(
            CacheConfiguration.DEFAULT_COPY_STRATEGY_CONFIGURATION)) {
      element.addChildElement(
          new CopyStrategyConfigurationElement(element, copyStrategyConfiguration));
    }
    CacheWriterConfiguration cacheWriterConfiguration =
        cacheConfiguration.getCacheWriterConfiguration();
    if (cacheWriterConfiguration != null
        && !CacheConfiguration.DEFAULT_CACHE_WRITER_CONFIGURATION.equals(
            cacheWriterConfiguration)) {
      element.addChildElement(
          new CacheWriterConfigurationElement(element, cacheWriterConfiguration));
    }
    addAllFactoryConfigsAsChildElements(
        element, "cacheDecoratorFactory", cacheConfiguration.getCacheDecoratorConfigurations());
    TerracottaConfiguration terracottaConfiguration =
        cacheConfiguration.getTerracottaConfiguration();
    if (terracottaConfiguration != null) {
      element.addChildElement(new TerracottaConfigurationElement(element, terracottaConfiguration));
    }
  }
Exemple #2
0
  public String createValueForAttribute(
      NodeElement element, NodeAttribute attribute, XSDAttributeValueType xsdAttributeValueType) {
    if ("terracotta".equals(element.getName())) {
      if ("coherent".equals(attribute.getName())) {
        // returning null will skip this attribute
        // can skip "coherent" attribute as its deprecated by consistency attribute
        return null;
      }
      if ("clustered".equals(attribute.getName())) {
        return "false";
      }
    }
    if ("pinning".equals(element.getName())) {
      if ("storage".equals(attribute.getName())) {
        return "inMemory";
      }
    }
    if ("sizeOfPolicy".equals(element.getName())) {
      if ("maxDepth".equals(attribute.getName())) {
        return "100";
      } else if ("maxDepthExceededBehavior".equals(attribute.getName())) {
        return "continue";
      }
    }
    // always generate with eternal=false
    if ("defaultCache".equals(element.getName()) || "cache".equals(element.getName())) {
      if ("eternal".equals(attribute.getName())) {
        return "false";
      }
      if ("transactionalMode".equals(attribute.getName())) {
        return "off";
      }
      // these are deprecated
      if ("maxElementsInMemory".equals(attribute.getName())
          || "maxMemoryOffHeap".equals(attribute.getName())
          || "diskPersistent".equals(attribute.getName())
          || "overflowToDisk".equals(attribute.getName())) {
        return null;
      }
      if ("maxElementsOnDisk".equals(attribute.getName())
          || "maxBytesLocalHeap".equals(attribute.getName())
          || "maxBytesLocalOffHeap".equals(attribute.getName())
          || "maxBytesLocalDisk".equals(attribute.getName())) {
        return null;
      }
      if ("maxEntriesLocalHeap".equals(attribute.getName())
          || "maxEntriesLocalOffHeap".equals(attribute.getName())
          || "maxEntriesLocalDisk".equals(attribute.getName())) {
        return "10000";
      }
    }
    if ("ehcache".equals(element.getName())) {
      if ("maxBytesLocalHeap".equals(attribute.getName())
          || "maxBytesLocalOffHeap".equals(attribute.getName())
          || "maxBytesLocalDisk".equals(attribute.getName())) {
        return null;
      }
    }
    if ("searchAttribute".equals(element.getName())) {
      if ("expression".equals(attribute.getName())) {
        return "value.toString()";
      } else if ("name".equals(attribute.getName())) {
        return "name";
      } else {
        return null;
      }
    }

    return xsdAttributeValueType.getRandomAllowedValue();
  }
Exemple #3
0
 /**
  * Adds all attributes which are common with the "defaultCache" element in ehcache.xsd
  *
  * @param element
  * @param cacheConfiguration
  */
 public static void addCommonAttributesWithDefaultCache(
     NodeElement element, CacheConfiguration cacheConfiguration) {
   element.addAttribute(
       new SimpleNodeAttribute("eternal", cacheConfiguration.isEternal()).optional(false));
   element.addAttribute(
       new SimpleNodeAttribute("maxElementsInMemory", cacheConfiguration.getMaxElementsInMemory())
           .optional(false));
   element.addAttribute(
       new SimpleNodeAttribute("overflowToDisk", cacheConfiguration.isOverflowToDisk())
           .optional(false));
   element.addAttribute(
       new SimpleNodeAttribute("clearOnFlush", cacheConfiguration.isClearOnFlush())
           .optional(true)
           .defaultValue(String.valueOf(CacheConfiguration.DEFAULT_CLEAR_ON_FLUSH)));
   element.addAttribute(
       new SimpleNodeAttribute("diskAccessStripes", cacheConfiguration.getDiskAccessStripes())
           .optional(true)
           .defaultValue(CacheConfiguration.DEFAULT_DISK_ACCESS_STRIPES));
   element.addAttribute(
       new SimpleNodeAttribute("diskPersistent", cacheConfiguration.isDiskPersistent())
           .optional(true)
           .defaultValue(CacheConfiguration.DEFAULT_DISK_PERSISTENT));
   element.addAttribute(
       new SimpleNodeAttribute(
               "diskSpoolBufferSizeMB", cacheConfiguration.getDiskSpoolBufferSizeMB())
           .optional(true)
           .defaultValue(CacheConfiguration.DEFAULT_SPOOL_BUFFER_SIZE));
   element.addAttribute(
       new SimpleNodeAttribute(
               "diskExpiryThreadIntervalSeconds",
               cacheConfiguration.getDiskExpiryThreadIntervalSeconds())
           .optional(true)
           .defaultValue(CacheConfiguration.DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS));
   element.addAttribute(
       new SimpleNodeAttribute("copyOnWrite", cacheConfiguration.isCopyOnWrite())
           .optional(true)
           .defaultValue(CacheConfiguration.DEFAULT_COPY_ON_WRITE));
   element.addAttribute(
       new SimpleNodeAttribute("copyOnRead", cacheConfiguration.isCopyOnRead())
           .optional(true)
           .defaultValue(CacheConfiguration.DEFAULT_COPY_ON_READ));
   element.addAttribute(
       new SimpleNodeAttribute("timeToIdleSeconds", cacheConfiguration.getTimeToIdleSeconds())
           .optional(true)
           .defaultValue(CacheConfiguration.DEFAULT_TTI));
   element.addAttribute(
       new SimpleNodeAttribute("timeToLiveSeconds", cacheConfiguration.getTimeToLiveSeconds())
           .optional(true)
           .defaultValue(CacheConfiguration.DEFAULT_TTL));
   element.addAttribute(
       new SimpleNodeAttribute("maxElementsOnDisk", cacheConfiguration.getMaxElementsOnDisk())
           .optional(true)
           .defaultValue(CacheConfiguration.DEFAULT_MAX_ELEMENTS_ON_DISK));
   element.addAttribute(
       new SimpleNodeAttribute("maxMemoryOffHeap", cacheConfiguration.getMaxMemoryOffHeap())
           .optional(true)
           .defaultValue((String) null));
   element.addAttribute(
       new SimpleNodeAttribute("overflowToOffHeap", cacheConfiguration.isOverflowToOffHeap())
           .optional(true)
           .defaultValue(false));
   element.addAttribute(
       new SimpleNodeAttribute(
               "cacheLoaderTimeoutMillis", cacheConfiguration.getCacheLoaderTimeoutMillis())
           .optional(true)
           .defaultValue(0L));
   element.addAttribute(
       new SimpleNodeAttribute("transactionalMode", cacheConfiguration.getTransactionalMode())
           .optional(true)
           .defaultValue(CacheConfiguration.DEFAULT_TRANSACTIONAL_MODE));
   element.addAttribute(
       new SimpleNodeAttribute("statistics", cacheConfiguration.getStatistics())
           .optional(true)
           .defaultValue(CacheConfiguration.DEFAULT_STATISTICS));
   element.addAttribute(
       new SimpleNodeAttribute(
               "memoryStoreEvictionPolicy",
               MemoryStoreEvictionPolicyEnum.valueOf(
                   cacheConfiguration.getMemoryStoreEvictionPolicy().toString()))
           .optional(true)
           .defaultValue(
               CacheConfiguration.DEFAULT_MEMORY_STORE_EVICTION_POLICY.toString().toLowerCase()));
 }