Search in sources :

Example 1 with TerracottaClientConfiguration

use of net.sf.ehcache.config.TerracottaClientConfiguration in project Gemma by PavlidisLab.

the class CacheMonitorImpl method getStats.

@Override
public String getStats() {
    StringBuilder buf = new StringBuilder();
    String[] cacheNames = cacheManager.getCacheNames();
    Arrays.sort(cacheNames);
    // Terracotta clustered?
    TerracottaClientConfiguration terracottaConfig = cacheManager.getConfiguration().getTerracottaConfiguration();
    buf.append("Distributed caching is ");
    buf.append(terracottaConfig != null ? "enabled" : "disabled");
    buf.append(" in the configuration file");
    buf.append(terracottaConfig != null ? ". The cache server's configuration URL is at [" + terracottaConfig.getUrl() + "]" : "");
    buf.append(".<br/>");
    buf.append(cacheNames.length).append(" caches; only non-empty caches listed below.");
    // FIXME make these sortable.
    buf.append("<br/>&nbsp;To clear all caches click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"clearAllCaches()\" alt='Flush caches' title='Clear caches' />&nbsp;&nbsp;");
    buf.append("<br/>&nbsp;To start statistics collection click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"enableStatistics()\" alt='Enable stats' title='Enable stats' />&nbsp;&nbsp;");
    buf.append("<br/>&nbsp;To stop statistics collection click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"disableStatistics()\" alt='Disable stats' title='Disable stats' />&nbsp;&nbsp;");
    buf.append("<table style='font-size:small'  ><tr>");
    String header = "<th>Name</th><th>HitRate</th><th>Hits</th><th>Misses</th><th>Count</th><th>MemHits</th><th>MemMiss</th><th>DiskHits</th><th>Evicted</th> <th>Eternal?</th><th>UseDisk?</th> <th>MaxInMem</th><th>LifeTime</th><th>IdleTime</th>";
    buf.append(header);
    buf.append("</tr>");
    int count = 0;
    for (String rawCacheName : cacheNames) {
        Cache cache = cacheManager.getCache(rawCacheName);
        Statistics statistics = cache.getStatistics();
        long objectCount = statistics.getObjectCount();
        if (objectCount == 0) {
            continue;
        }
        // a little shorter...
        String cacheName = rawCacheName.replaceFirst("ubic.gemma.model.", "u.g.m.");
        buf.append("<tr><td>").append(this.getClearCacheHtml(rawCacheName)).append(cacheName).append("</td>");
        long hits = statistics.getCacheHits();
        long misses = statistics.getCacheMisses();
        long inMemoryHits = statistics.getInMemoryHits();
        long inMemoryMisses = statistics.getInMemoryMisses();
        long onDiskHits = statistics.getOnDiskHits();
        long evictions = statistics.getEvictionCount();
        if (hits + misses > 0) {
            buf.append(this.makeTableCellForStat(String.format("%.2f", (double) hits / (hits + misses))));
        } else {
            buf.append("<td></td>");
        }
        buf.append(this.makeTableCellForStat(hits));
        buf.append(this.makeTableCellForStat(misses));
        buf.append(this.makeTableCellForStat(objectCount));
        buf.append(this.makeTableCellForStat(inMemoryHits));
        buf.append(this.makeTableCellForStat(inMemoryMisses));
        buf.append(this.makeTableCellForStat(onDiskHits));
        buf.append(this.makeTableCellForStat(evictions));
        CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
        boolean eternal = cacheConfiguration.isEternal();
        buf.append("<td>").append(eternal ? "&bull;" : "").append("</td>");
        Strategy strategy;
        strategy = cacheConfiguration.getPersistenceConfiguration() == null ? null : cacheConfiguration.getPersistenceConfiguration().getStrategy();
        buf.append("<td>").append(strategy == null || strategy.equals(Strategy.NONE) ? "" : "&bull;").append("</td>");
        buf.append("<td>").append(cacheConfiguration.getMaxEntriesLocalHeap()).append("</td>");
        if (eternal) {
            // timeouts are irrelevant.
            buf.append("<td>-</td>");
            buf.append("<td>-</td>");
        } else {
            buf.append("<td>").append(cacheConfiguration.getTimeToIdleSeconds()).append("</td>");
            buf.append("<td>").append(cacheConfiguration.getTimeToLiveSeconds()).append("</td>");
        }
        buf.append("</tr>");
        if (++count % 25 == 0) {
            buf.append("<tr>").append(header).append("</tr>");
        }
    }
    buf.append("</table>");
    return buf.toString();
}
Also used : TerracottaClientConfiguration(net.sf.ehcache.config.TerracottaClientConfiguration) Strategy(net.sf.ehcache.config.PersistenceConfiguration.Strategy) Statistics(net.sf.ehcache.Statistics) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 2 with TerracottaClientConfiguration

use of net.sf.ehcache.config.TerracottaClientConfiguration in project ff4j by ff4j.

the class FeatureStoreTerracottaTestIT method initStore.

/**
 * {@inheritDoc}
 */
@Override
protected FeatureStore initStore() {
    // Configuration to wirk with Terracotta
    Configuration managerConfiguration = new Configuration();
    managerConfiguration.name("config").terracotta(new TerracottaClientConfiguration().url(TERRACOTTA_URL)).defaultCache(new CacheConfiguration().maxBytesLocalHeap(128, MemoryUnit.MEGABYTES).terracotta(new TerracottaConfiguration())).cache(new CacheConfiguration().name(FF4jEhCacheWrapper.CACHENAME_FEATURES).maxBytesLocalHeap(128, MemoryUnit.MEGABYTES).terracotta(new TerracottaConfiguration()));
    FeatureStoreEhCache ehcacheStore = new FeatureStoreEhCache(managerConfiguration);
    ehcacheStore.importFeaturesFromXmlFile("ff4j.xml");
    return ehcacheStore;
}
Also used : TerracottaClientConfiguration(net.sf.ehcache.config.TerracottaClientConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) TerracottaConfiguration(net.sf.ehcache.config.TerracottaConfiguration) Configuration(net.sf.ehcache.config.Configuration) TerracottaClientConfiguration(net.sf.ehcache.config.TerracottaClientConfiguration) TerracottaConfiguration(net.sf.ehcache.config.TerracottaConfiguration) FeatureStoreEhCache(org.ff4j.store.FeatureStoreEhCache) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 3 with TerracottaClientConfiguration

use of net.sf.ehcache.config.TerracottaClientConfiguration in project onebusaway-application-modules by camsys.

the class EhCacheConfigurationFactoryBean method afterPropertiesSet.

public void afterPropertiesSet() throws IOException, CacheException {
    logger.info("Initializing EHCache CacheManager");
    this.configuration = ConfigurationFactory.parseConfiguration(this.configLocation.getInputStream());
    if (this.diskStorePath != null) {
        logger.info("diskStorePath=" + this.diskStorePath);
        DiskStoreConfiguration dsConfig = new DiskStoreConfiguration();
        dsConfig.setPath(this.diskStorePath);
        logger.info("diskStorePath (translated)=" + dsConfig.getPath());
        configuration.addDiskStore(dsConfig);
    }
    if (this.terracottaUrl != null) {
        logger.info("terracottaUrl=" + this.terracottaUrl);
        TerracottaClientConfiguration tcConfig = new TerracottaClientConfiguration();
        tcConfig.setUrl(this.terracottaUrl);
        configuration.addTerracottaConfig(tcConfig);
    }
}
Also used : TerracottaClientConfiguration(net.sf.ehcache.config.TerracottaClientConfiguration) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration)

Aggregations

TerracottaClientConfiguration (net.sf.ehcache.config.TerracottaClientConfiguration)3 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)2 Cache (net.sf.ehcache.Cache)1 Statistics (net.sf.ehcache.Statistics)1 Configuration (net.sf.ehcache.config.Configuration)1 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)1 Strategy (net.sf.ehcache.config.PersistenceConfiguration.Strategy)1 TerracottaConfiguration (net.sf.ehcache.config.TerracottaConfiguration)1 FeatureStoreEhCache (org.ff4j.store.FeatureStoreEhCache)1