net.sf.ehcache.Cache.getStatus()方法的使用及代码示例

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

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

Cache.getStatus介绍

[英]Gets the status attribute of the Cache.
[中]获取缓存的状态属性。

代码示例

代码示例来源:origin: Impetus/Kundera

private boolean isAlive()
{
  return ehcache.getStatus().equals(Status.STATUS_ALIVE);
}

代码示例来源:origin: pentaho/pentaho-reporting

public TableModel get( final DataCacheKey key ) {
 final Cache cache = this.cache;
 synchronized ( this ) {
  if ( cache == null ) {
   return null;
  }
  if ( cache.getStatus() != Status.STATUS_ALIVE ) {
   this.cache = null;
   return null;
  }
 }
 final Element element = cache.get( key );
 if ( element == null ) {
  return null;
 }
 return (TableModel) element.getObjectValue();
}

代码示例来源:origin: Jasig/uPortal

/**
 * Call {@link Cache#removeAll()} on the specified cache, if it exists and is alive.
 *
 * @see Status#STATUS_ALIVE
 * @see Cache#getStatus()
 * @param cacheName
 */
public void clearCache(String cacheName) {
  Cache cache = this.cacheManager.getCache(cacheName);
  if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
    cache.removeAll();
    logger.warn("finished removeAll for cache: " + cacheName);
  }
}

代码示例来源:origin: org.jasig.portal/uPortal-utils-core

/**
 * Call {@link Cache#removeAll()} on the specified cache, if it exists and is alive.
 *
 * @see Status#STATUS_ALIVE
 * @see Cache#getStatus()
 * @param cacheName
 */
public void clearCache(String cacheName) {
  Cache cache = this.cacheManager.getCache(cacheName);
  if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
    cache.removeAll();
    logger.warn("finished removeAll for cache: " + cacheName);
  }
}

代码示例来源:origin: org.jasig.portal/uPortal-utils-core

/**
 * @see Status#STATUS_ALIVE
 * @see Cache#getStatus()
 * @see Cache#getStatistics()
 * @param cacheName
 * @return the {@link Statistics} for the specified cache; returns null of cache is not alive or
 *     doesn't exist
 */
public Statistics getCacheStatistics(String cacheName) {
  Cache cache = this.cacheManager.getCache(cacheName);
  if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
    Statistics result = cache.getStatistics();
    return result;
  }
  return null;
}

代码示例来源:origin: Jasig/uPortal

/**
 * @see Status#STATUS_ALIVE
 * @see Cache#getStatus()
 * @see Cache#getStatistics()
 * @param cacheName
 * @return the {@link Statistics} for the specified cache; returns null of cache is not alive or
 *     doesn't exist
 */
public Statistics getCacheStatistics(String cacheName) {
  Cache cache = this.cacheManager.getCache(cacheName);
  if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
    Statistics result = cache.getStatistics();
    return result;
  }
  return null;
}

代码示例来源:origin: uk.ac.ebi.enfin.mi.cluster/micluster

private void shutdownIfActive( Cache cache ) {
     if( Status.STATUS_ALIVE.equals( cache.getStatus() ) ) {
       System.out.println( "Attempting to dispose of: " + cache.getName() + "..." );
       cache.dispose();
     } else {
       System.out.println( "Cache('"+ cache.getName() +"') was not alive. Skipping dispose()..." );
     }
  }
}

代码示例来源:origin: deas/alfresco

@SuppressWarnings("unchecked")
public V get(K key)
{
  try
  {
    Element element = cache.get(key);
    if (element != null)
    {
      return (V) element.getObjectValue();
    }
    else
    {
      return null;
    }
  }
  catch (IllegalStateException ie)
  {
    throw new org.alfresco.wcm.client.impl.cache.CacheException("Failed to get from EhCache as state invalid: \n" +
       "  state: " + cache.getStatus() + "\n" +
       "   key: " + key,
       ie);
  }
  catch (CacheException e)
  {
    throw new org.alfresco.wcm.client.impl.cache.CacheException("Failed to get from EhCache: \n" +
        "   key: " + key,
        e);
  }
}

代码示例来源:origin: uk.ac.ebi.intact.bridges/intact-uniprot

@Override
public void close() {
  if (this.cache != null){
    if( Status.STATUS_ALIVE.equals( cache.getStatus() ) ) {
      System.out.println( "Attempting to dispose of: " + cache.getName() + "..." );
      cache.dispose();
    }
  }
  if (cacheManager != null){
    cacheManager.clearAll();
  }
  service.close();
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
public CacheCompactionResult purgeExpiredCacheEntries()
{
  int cacheCount = 0;
  int totalEntriesCount = 0;
  int purgedEntriesCount = 0;
  for (String name : cacheManager.getCacheNames())
  {
    try
    {
      Cache cache = cacheManager.getCache(name);
      if (cache != null && cache.getStatus().equals(Status.STATUS_ALIVE))
      {
        int before = cache.getSize();
        cache.evictExpiredElements();
        int after = cache.getSize();
        cacheCount++;
        totalEntriesCount += before;
        purgedEntriesCount += (before - after);
      }
    }
    catch (Exception e)
    {
      LOG.warn("Unable to purge expired cache entries for cahe '" + name + "'", e);
    }
  }
  return new CacheCompactionResult(cacheCount, totalEntriesCount, purgedEntriesCount);
}

代码示例来源:origin: pentaho/pentaho-reporting

private synchronized void initialize() {
 if ( manager != null ) {
  if ( manager.getStatus() != Status.STATUS_ALIVE ) {
   initializeCacheManager();
  }
 }
 if ( cache != null ) {
  if ( cache.getStatus() == Status.STATUS_ALIVE ) {
   return;
  }
 }
 if ( manager.cacheExists( CACHE_NAME ) == false ) {
  cache = new Cache( CACHE_NAME, // cache name
    500, // maxElementsInMemory
    false, // overflowToDisk
    false, // eternal
    600, // timeToLiveSeconds
    600, // timeToIdleSeconds
    false, // diskPersistent
    120 ); // diskExpiryThreadIntervalSeconds
  manager.addCache( cache );
 } else {
  cache = manager.getCache( CACHE_NAME );
 }
}

代码示例来源:origin: Jasig/uPortal

public Map<String, CacheStatistics> getAllCacheStatistics() {
  final Map<String, CacheStatistics> allCacheStatistics =
      new TreeMap<>(CaseInsenstivieStringComparator.INSTANCE);
  for (final String cacheName : this.cacheManager.getCacheNames()) {
    final Cache cache = this.cacheManager.getCache(cacheName);
    if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
      final CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
      final Statistics statistics = cache.getStatistics();
      final CacheStatistics cacheStatistics = new CacheStatistics();
      cacheStatistics.hits = statistics.getCacheHits();
      cacheStatistics.misses = statistics.getCacheMisses();
      cacheStatistics.size = statistics.getObjectCount();
      cacheStatistics.maxSize =
          cacheConfiguration.getMaxElementsInMemory()
              + cacheConfiguration.getMaxElementsOnDisk();
      allCacheStatistics.put(cacheName, cacheStatistics);
    }
  }
  return allCacheStatistics;
}

代码示例来源:origin: org.jasig.portal/uPortal-utils-core

public Map<String, CacheStatistics> getAllCacheStatistics() {
  final Map<String, CacheStatistics> allCacheStatistics =
      new TreeMap<>(CaseInsenstivieStringComparator.INSTANCE);
  for (final String cacheName : this.cacheManager.getCacheNames()) {
    final Cache cache = this.cacheManager.getCache(cacheName);
    if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
      final CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
      final Statistics statistics = cache.getStatistics();
      final CacheStatistics cacheStatistics = new CacheStatistics();
      cacheStatistics.hits = statistics.getCacheHits();
      cacheStatistics.misses = statistics.getCacheMisses();
      cacheStatistics.size = statistics.getObjectCount();
      cacheStatistics.maxSize =
          cacheConfiguration.getMaxElementsInMemory()
              + cacheConfiguration.getMaxElementsOnDisk();
      allCacheStatistics.put(cacheName, cacheStatistics);
    }
  }
  return allCacheStatistics;
}

相关文章

Cache类方法