use of net.sf.ehcache.config.CacheConfiguration in project LogHub by fbacchella.
the class NameResolver method configure.
@Override
public boolean configure(Properties properties) {
CacheConfiguration config = properties.getDefaultCacheConfig("NameResolver", this).eternal(false).maxEntriesLocalHeap(cacheSize).timeToLiveSeconds(ttl);
hostCache = properties.getCache(config);
return super.configure(properties);
}
use of net.sf.ehcache.config.CacheConfiguration 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.CacheConfiguration in project core by craftercms.
the class EhCacheStoreAdapter method addScope.
/**
* Adds a new scope. The scope is an instance of EhCache's {@link Cache}.
*
* @param scope the name of the scope
* @param maxItemsInMemory the maximum number of items in memory, before they are evicted
* @throws Exception
*/
@Override
public void addScope(String scope, int maxItemsInMemory) throws Exception {
CacheConfiguration scopeConfig = new CacheConfiguration(scope, maxItemsInMemory);
scopeManager.addCache(new Cache(scopeConfig));
}
use of net.sf.ehcache.config.CacheConfiguration in project activemq-artemis by apache.
the class InMemoryDirectoryServiceFactory method init.
/**
* {@inheritDoc}
*/
@Override
public void init(String name) throws Exception {
if ((directoryService == null) || directoryService.isStarted()) {
return;
}
directoryService.setInstanceId(name);
// instance layout
InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + name);
if (instanceLayout.getInstanceDirectory().exists()) {
try {
FileUtils.deleteDirectory(instanceLayout.getInstanceDirectory());
} catch (IOException e) {
LOG.warn("couldn't delete the instance directory before initializing the DirectoryService", e);
}
}
directoryService.setInstanceLayout(instanceLayout);
// EhCache in disabled-like-mode
Configuration ehCacheConfig = new Configuration();
CacheConfiguration defaultCache = new CacheConfiguration("default", 1).eternal(false).timeToIdleSeconds(30).timeToLiveSeconds(30).overflowToDisk(false);
ehCacheConfig.addDefaultCache(defaultCache);
CacheService cacheService = new CacheService(new CacheManager(ehCacheConfig));
directoryService.setCacheService(cacheService);
// Init the schema
// SchemaLoader loader = new SingleLdifSchemaLoader();
SchemaLoader loader = new JarLdifSchemaLoader();
SchemaManager schemaManager = new DefaultSchemaManager(loader);
schemaManager.loadAllEnabled();
ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry();
for (LdapComparator<?> comparator : comparatorRegistry) {
if (comparator instanceof NormalizingComparator) {
((NormalizingComparator) comparator).setOnServer();
}
}
directoryService.setSchemaManager(schemaManager);
InMemorySchemaPartition inMemorySchemaPartition = new InMemorySchemaPartition(schemaManager);
SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
schemaPartition.setWrappedPartition(inMemorySchemaPartition);
directoryService.setSchemaPartition(schemaPartition);
List<Throwable> errors = schemaManager.getErrors();
if (errors.size() != 0) {
throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
}
// Init system partition
Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), directoryService.getDnFactory(), "system", ServerDNConstants.SYSTEM_DN, 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "system"));
systemPartition.setSchemaManager(directoryService.getSchemaManager());
partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
directoryService.setSystemPartition(systemPartition);
directoryService.startup();
}
use of net.sf.ehcache.config.CacheConfiguration 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