use of org.apache.nifi.distributed.cache.server.EvictionPolicy in project nifi by apache.
the class DistributedMapCacheServer method createCacheServer.
@Override
protected CacheServer createCacheServer(final ConfigurationContext context) {
final int port = context.getProperty(PORT).asInteger();
final String persistencePath = context.getProperty(PERSISTENCE_PATH).getValue();
final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
final int maxSize = context.getProperty(MAX_CACHE_ENTRIES).asInteger();
final String evictionPolicyName = context.getProperty(EVICTION_POLICY).getValue();
final SSLContext sslContext;
if (sslContextService == null) {
sslContext = null;
} else {
sslContext = sslContextService.createSSLContext(ClientAuth.REQUIRED);
}
final EvictionPolicy evictionPolicy;
switch(evictionPolicyName) {
case EVICTION_STRATEGY_FIFO:
evictionPolicy = EvictionPolicy.FIFO;
break;
case EVICTION_STRATEGY_LFU:
evictionPolicy = EvictionPolicy.LFU;
break;
case EVICTION_STRATEGY_LRU:
evictionPolicy = EvictionPolicy.LRU;
break;
default:
throw new IllegalArgumentException("Illegal Eviction Policy: " + evictionPolicyName);
}
try {
final File persistenceDir = persistencePath == null ? null : new File(persistencePath);
return createMapCacheServer(port, maxSize, sslContext, evictionPolicy, persistenceDir);
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
Aggregations