use of net.sf.ehcache.config.PersistenceConfiguration.Strategy 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/> To clear all caches click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"clearAllCaches()\" alt='Flush caches' title='Clear caches' /> ");
buf.append("<br/> To start statistics collection click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"enableStatistics()\" alt='Enable stats' title='Enable stats' /> ");
buf.append("<br/> To stop statistics collection click here: <img src='" + Settings.getRootContext() + "/images/icons/arrow_rotate_anticlockwise.png' onClick=\"disableStatistics()\" alt='Disable stats' title='Disable stats' /> ");
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 ? "•" : "").append("</td>");
Strategy strategy;
strategy = cacheConfiguration.getPersistenceConfiguration() == null ? null : cacheConfiguration.getPersistenceConfiguration().getStrategy();
buf.append("<td>").append(strategy == null || strategy.equals(Strategy.NONE) ? "" : "•").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();
}
use of net.sf.ehcache.config.PersistenceConfiguration.Strategy in project qi4j-sdk by Qi4j.
the class EhCachePoolMixin method createCacheConfiguration.
private CacheConfiguration createCacheConfiguration(String cacheId) {
EhCacheConfiguration conf = config.get();
Integer maxElementsInMemory = conf.maxElementsInMemory().get();
if (maxElementsInMemory <= 0) {
maxElementsInMemory = 10000;
}
CacheConfiguration cacheConfig = new CacheConfiguration(cacheId, maxElementsInMemory);
String transactionalMode = conf.transactionalMode().get();
if (transactionalMode.length() > 0) {
cacheConfig.transactionalMode(transactionalMode);
}
Long timeToLiveSeconds = conf.timeToLiveSeconds().get();
if (timeToLiveSeconds > 0) {
cacheConfig.timeToLiveSeconds(timeToLiveSeconds);
}
Long timeToIdleSeconds = conf.timeToIdleSeconds().get();
if (timeToIdleSeconds > 0) {
cacheConfig.timeToIdleSeconds(timeToIdleSeconds);
}
String name = conf.name().get();
if (name.length() > 0) {
cacheConfig.name(name);
}
String memoryStoreEvictionPolicy = conf.memoryStoreEvictionPolicy().get();
if (memoryStoreEvictionPolicy.length() > 0) {
cacheConfig.memoryStoreEvictionPolicy(memoryStoreEvictionPolicy);
}
Integer maxElementsOnDisk = conf.maxElementsOnDisk().get();
if (maxElementsOnDisk > 0) {
cacheConfig.maxElementsOnDisk(maxElementsOnDisk);
}
Boolean loggingEnabled = conf.loggingEnabled().get();
if (loggingEnabled != null) {
cacheConfig.logging(loggingEnabled);
}
Boolean eternal = conf.eternal().get();
cacheConfig.eternal(eternal);
Integer diskSpoolBufferSizeMB = conf.diskSpoolBufferSizeMB().get();
if (diskSpoolBufferSizeMB > 0) {
cacheConfig.diskSpoolBufferSizeMB(diskSpoolBufferSizeMB);
}
Long diskExpiryThreadIntervalSeconds = conf.diskExpiryThreadIntervalSeconds().get();
if (diskExpiryThreadIntervalSeconds > 0) {
cacheConfig.diskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds);
}
Integer diskAccessStripes = conf.diskAccessStripes().get();
if (diskAccessStripes > 0) {
cacheConfig.diskAccessStripes(diskAccessStripes);
}
Boolean clearOnFlush = conf.clearOnFlush().get();
if (clearOnFlush != null) {
cacheConfig.clearOnFlush(clearOnFlush);
}
// Persistence Configuration
PersistenceConfiguration persistenceConfig = new PersistenceConfiguration();
Strategy strategy = conf.persistenceStrategy().get();
if (strategy == null) {
persistenceConfig.strategy(Strategy.NONE);
} else {
persistenceConfig.strategy(strategy);
}
cacheConfig.persistence(persistenceConfig);
return cacheConfig;
}
Aggregations