net.sf.ehcache.config.Configuration.isMaxBytesLocalHeapSet()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(208)

本文整理了Java中net.sf.ehcache.config.Configuration.isMaxBytesLocalHeapSet()方法的一些代码示例,展示了Configuration.isMaxBytesLocalHeapSet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.isMaxBytesLocalHeapSet()方法的具体详情如下:
包路径:net.sf.ehcache.config.Configuration
类名称:Configuration
方法名:isMaxBytesLocalHeapSet

Configuration.isMaxBytesLocalHeapSet介绍

[英]Checks whether the user explicitly set the maxBytesOnHeap
[中]检查用户是否显式设置maxBytesOnHeap

代码示例

代码示例来源:origin: net.sf.ehcache/ehcache

private void warnMaxEntriesLocalHeap(final boolean register, CacheManager cacheManager) {
  if (getMaxEntriesLocalHeap() == 0 && register) {
    if (getMaxBytesLocalHeap() == 0 && (!cacheManager.getConfiguration().isMaxBytesLocalHeapSet())) {
    LOG.warn("Cache: " + getName() +
        " has a maxElementsInMemory of 0. This might lead to performance degradation or OutOfMemoryError at Terracotta client." +
        "From Ehcache 2.0 onwards this has been changed to mean a store" +
        " with no capacity limit. Set it to 1 if you want" +
        " no elements cached in memory");
    }
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

if (maxEntriesLocalHeap == null && !configuration.isMaxBytesLocalHeapSet() && maxBytesLocalHeap == null) {
  errors.add(new CacheConfigError("If your CacheManager has no maxBytesLocalHeap set, you need to either set " +
      "maxEntriesLocalHeap or maxBytesLocalHeap at the Cache level", getName()));
if (configuration.isMaxBytesLocalHeapSet() && Runtime.getRuntime().maxMemory() - configuration.getMaxBytesLocalHeap() < 0) {
  errors.add(new ConfigError("You've assigned more memory to the on-heap than the VM can sustain, " +
                      "please adjust your -Xmx setting accordingly"));

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
@Override
public boolean isLocalHeapCountBased() {
 return cache.getCacheConfiguration()
       .getMaxBytesLocalHeap() <= 0 && !(cache.getCacheManager() != null && cache.getCacheManager()
   .getConfiguration()
   .isMaxBytesLocalHeapSet());
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Validates the CacheConfiguration against the CacheManager's Configuration
 * @param configuration The CacheManager Configuration
 * @return the list of errors encountered, or an empty list
 */
List<CacheConfigError> validateCachePools(final Configuration configuration) {
  List<CacheConfigError> errors = new ArrayList<CacheConfigError>();
  if (configuration.isMaxBytesLocalHeapSet()
    && getMaxEntriesLocalHeap() > 0) {
    errors.add(new CacheConfigError("maxEntriesLocalHeap is not compatible with " +
                    "maxBytesLocalHeap set on cache manager", getName()));
  }
  if (getMaxBytesLocalHeap() > 0 && getMaxEntriesLocalHeap() > 0) {
    errors.add(new CacheConfigError("maxEntriesLocalHeap is not compatible with " +
                    "maxBytesLocalHeap set on cache", getName()));
  }
  if (isMaxBytesLocalHeapPercentageSet() && !configuration.isMaxBytesLocalHeapSet()) {
    errors.add(new CacheConfigError("Defines a percentage maxBytesOnHeap value but no CacheManager " +
                    "wide value was configured", getName()));
  }
  if (isMaxBytesLocalOffHeapPercentageSet() && !configuration.isMaxBytesLocalOffHeapSet()) {
    errors.add(new CacheConfigError("Defines a percentage maxBytesOffHeap value but no CacheManager " +
                    "wide value was configured", getName()));
  }
  if (isMaxBytesLocalDiskPercentageSet() && !configuration.isMaxBytesLocalDiskSet()) {
    errors.add(new CacheConfigError("Defines a percentage maxBytesOnDisk value but no CacheManager " +
                    "wide value was configured", getName()));
  }
  return errors;
}

代码示例来源:origin: net.sf.ehcache/ehcache

@Override
public void maxBytesLocalHeapChanged(final long oldValue, final long newValue) {
  if (getMaxBytesLocalHeap() > 0
    && cacheManager.getConfiguration().getCacheConfigurations().keySet().contains(getName())
    && cacheManager.getConfiguration().isMaxBytesLocalHeapSet()) {
    long oldCacheManagerPoolSize = cacheManager.getOnHeapPool().getMaxSize();
    long newPoolFreeSize = oldCacheManagerPoolSize + oldValue - newValue;
    //handle case of overallocation of cache
    //Only resize the cache manager pool cache pool resizing will be handled by cache
    if (newPoolFreeSize >= 0) {
      cacheManager.getOnHeapPool().setMaxSize(newPoolFreeSize);
    } else {
      maxBytesLocalHeap = oldValue;
      throw new InvalidConfigurationException("Cannot allocate heap size more " +
          "than the cache pool size reverting to previous size " + maxBytesLocalHeap);
    }
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
@Override
public void setMaxBytesLocalHeap(long maxBytes) {
  try {
    if (cache.getCacheManager().getConfiguration().isMaxBytesLocalHeapSet()) {
      long heapPoolSize = cache.getCacheManager().getConfiguration().getMaxBytesLocalHeap();
      if (maxBytes > heapPoolSize) {
        throw new IllegalArgumentException("Requested maxBytesLocalHeap (" + maxBytes
            + ") greater than available CacheManager heap pool size (" + heapPoolSize + ")");
      }
    }
    cache.getCacheConfiguration().setMaxBytesLocalHeap(maxBytes);
  } catch (RuntimeException e) {
    throw Utils.newPlainException(e);
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

private boolean skipUpdateAccessStatistics(Element element) {
 if (configuration.isFrozen()) {
  boolean forLifetime = element.isEternal();
  boolean forHeap =  configuration.getMaxEntriesLocalHeap() > 0 || configuration.getMaxBytesLocalHeap() > 0
      || getCacheManager().getConfiguration().isMaxBytesLocalHeapSet();
  boolean forDisk = configuration.isOverflowToDisk() && (configuration.getMaxEntriesLocalDisk() > 0 || configuration.getMaxBytesLocalDisk() > 0
      || getCacheManager().getConfiguration().isMaxBytesLocalDiskSet());
  return !(forLifetime || forHeap || forDisk);
 } else {
  return false;
 }
}

代码示例来源:origin: net.sf.ehcache/ehcache

private void freezePoolUsages(final CacheManager cacheManager) {
  if (getMaxBytesLocalHeap() > 0) {
    onHeapPoolUsage = CacheConfiguration.PoolUsage.Cache;
  } else if (cacheManager.getConfiguration().isMaxBytesLocalHeapSet()) {
    onHeapPoolUsage = CacheConfiguration.PoolUsage.CacheManager;
  } else {
    onHeapPoolUsage = CacheConfiguration.PoolUsage.None;
  }
  if (getMaxBytesLocalOffHeap() > 0) {
    offHeapPoolUsage = CacheConfiguration.PoolUsage.Cache;
  } else if (cacheManager.getConfiguration().isMaxBytesLocalOffHeapSet()) {
    offHeapPoolUsage = CacheConfiguration.PoolUsage.CacheManager;
  } else {
    offHeapPoolUsage = CacheConfiguration.PoolUsage.None;
  }
  if (isTerracottaClustered()) {
    onDiskPoolUsage = CacheConfiguration.PoolUsage.None;
  } else {
    if (getMaxBytesLocalDisk() > 0) {
      onDiskPoolUsage = CacheConfiguration.PoolUsage.Cache;
    } else if (cacheManager.getConfiguration().isMaxBytesLocalDiskSet()) {
      onDiskPoolUsage = CacheConfiguration.PoolUsage.CacheManager;
    } else {
      onDiskPoolUsage = CacheConfiguration.PoolUsage.None;
    }
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

if (configuration.isMaxBytesLocalHeapSet()) {
  PoolEvictor evictor = new BalancedAccessEvictor();
  SizeOfEngine sizeOfEngine = createSizeOfEngine(null);

代码示例来源:origin: net.sf.ehcache/ehcache

registerCacheConfiguration(cacheManager);
if (cacheManager.getConfiguration().isMaxBytesLocalHeapSet() || cacheManager.getConfiguration().isMaxBytesLocalDiskSet()) {

代码示例来源:origin: net.sf.ehcache/ehcache

SizeOfEngine sizeOfEngine = cacheManager.createSizeOfEngine(this);
  onHeapPool = new BoundedPool(configuration.getMaxBytesLocalHeap(), evictor, sizeOfEngine);
} else if (getCacheManager() != null && getCacheManager().getConfiguration().isMaxBytesLocalHeapSet()) {
  onHeapPool = getCacheManager().getOnHeapPool();
} else {

代码示例来源:origin: org.sonatype.nexus.bundles/org.sonatype.nexus.bundles.ehcache

private void warnMaxEntriesLocalHeap(final boolean register, CacheManager cacheManager) {
  if (getMaxEntriesLocalHeap() == 0 && register) {
    if (getMaxBytesLocalHeap() == 0 && (!cacheManager.getConfiguration().isMaxBytesLocalHeapSet())) {
    LOG.warn("Cache: " + getName() +
        " has a maxElementsInMemory of 0. This might lead to performance degradation or OutOfMemoryError at Terracotta client." +
        "From Ehcache 2.0 onwards this has been changed to mean a store" +
        " with no capacity limit. Set it to 1 if you want" +
        " no elements cached in memory");
    }
  }
}

代码示例来源:origin: net.sf.ehcache.internal/ehcache-core

private void warnMaxEntriesLocalHeap(final boolean register, CacheManager cacheManager) {
  if (getMaxEntriesLocalHeap() == 0 && register) {
    if (getMaxBytesLocalHeap() == 0 && (!cacheManager.getConfiguration().isMaxBytesLocalHeapSet())) {
    LOG.warn("Cache: " + getName() +
        " has a maxElementsInMemory of 0. This might lead to performance degradation or OutOfMemoryError at Terracotta client." +
        "From Ehcache 2.0 onwards this has been changed to mean a store" +
        " with no capacity limit. Set it to 1 if you want" +
        " no elements cached in memory");
    }
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.ehcache

private void warnMaxEntriesLocalHeap(final boolean register, CacheManager cacheManager) {
  if (getMaxEntriesLocalHeap() == 0 && register) {
    if (getMaxBytesLocalHeap() == 0 && (!cacheManager.getConfiguration().isMaxBytesLocalHeapSet())) {
    LOG.warn("Cache: " + getName() +
        " has a maxElementsInMemory of 0. This might lead to performance degradation or OutOfMemoryError at Terracotta client." +
        "From Ehcache 2.0 onwards this has been changed to mean a store" +
        " with no capacity limit. Set it to 1 if you want" +
        " no elements cached in memory");
    }
  }
}

代码示例来源:origin: org.sonatype.nexus.bundles/org.sonatype.nexus.bundles.ehcache

/**
 * {@inheritDoc}
 */
@Override
public boolean isLocalHeapCountBased() {
 return cache.getCacheConfiguration()
       .getMaxBytesLocalHeap() <= 0 && !(cache.getCacheManager() != null && cache.getCacheManager()
   .getConfiguration()
   .isMaxBytesLocalHeapSet());
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.ehcache

@Override
public void maxBytesLocalHeapChanged(final long oldValue, final long newValue) {
  if (getMaxBytesLocalHeap() > 0
    && cacheManager.getConfiguration().getCacheConfigurations().keySet().contains(getName())
    && cacheManager.getConfiguration().isMaxBytesLocalHeapSet()) {
    long previous = cacheManager.getOnHeapPool().getMaxSize();
    cacheManager.getOnHeapPool().setMaxSize(previous + oldValue - newValue);
  }
}

代码示例来源:origin: net.sf.ehcache.internal/ehcache-core

/**
 * {@inheritDoc}
 */
@Override
public boolean isLocalHeapCountBased() {
 return cache.getCacheConfiguration()
       .getMaxBytesLocalHeap() <= 0 && !(cache.getCacheManager() != null && cache.getCacheManager()
   .getConfiguration()
   .isMaxBytesLocalHeapSet());
}

代码示例来源:origin: net.sf.ehcache.internal/ehcache-core

private boolean skipUpdateAccessStatistics(Element element) {
 if (configuration.isFrozen()) {
  boolean forLifetime = element.isEternal();
  boolean forHeap =  configuration.getMaxEntriesLocalHeap() > 0 || configuration.getMaxBytesLocalHeap() > 0
      || getCacheManager().getConfiguration().isMaxBytesLocalHeapSet();
  boolean forDisk = configuration.isOverflowToDisk() && (configuration.getMaxEntriesLocalDisk() > 0 || configuration.getMaxBytesLocalDisk() > 0
      || getCacheManager().getConfiguration().isMaxBytesLocalDiskSet());
  return !(forLifetime || forHeap || forDisk);
 } else {
  return false;
 }
}

代码示例来源:origin: org.sonatype.nexus.bundles/org.sonatype.nexus.bundles.ehcache

private boolean skipUpdateAccessStatistics(Element element) {
 if (configuration.isFrozen()) {
  boolean forLifetime = element.isEternal();
  boolean forHeap =  configuration.getMaxEntriesLocalHeap() > 0 || configuration.getMaxBytesLocalHeap() > 0
      || getCacheManager().getConfiguration().isMaxBytesLocalHeapSet();
  boolean forDisk = configuration.isOverflowToDisk() && (configuration.getMaxEntriesLocalDisk() > 0 || configuration.getMaxBytesLocalDisk() > 0
      || getCacheManager().getConfiguration().isMaxBytesLocalDiskSet());
  return !(forLifetime || forHeap || forDisk);
 } else {
  return false;
 }
}

代码示例来源:origin: org.ehcache/jcache

private CacheConfiguration toEhcacheConfig(final String name, final Configuration configuration) {
  final int maxSize = cacheManager.getConfiguration().isMaxBytesLocalHeapSet() ? 0 : DEFAULT_SIZE;
  CacheConfiguration cfg = new CacheConfiguration(name, maxSize);
  cfg.setClassLoader(cacheManager.getConfiguration().getClassLoader());
  if(configuration.isStoreByValue()) {
    final CopyStrategyConfiguration copyStrategyConfiguration = new CopyStrategyConfiguration();
    copyStrategyConfiguration.setCopyStrategyInstance(new JCacheCopyOnWriteStrategy());
    cfg.copyOnRead(true).copyOnWrite(true)
      .addCopyStrategy(copyStrategyConfiguration);
  }
  if(configuration instanceof CompleteConfiguration) {
    if(((CompleteConfiguration)configuration).isWriteThrough()) {
      cfg.addCacheWriter(new CacheWriterConfiguration().writeMode(CacheWriterConfiguration.WriteMode.WRITE_THROUGH));
    }
  }
  return cfg;
}

相关文章

微信公众号

最新文章

更多

Configuration类方法