Simplified embedded infinispan connection config

This commit is contained in:
Stian Thorgersen 2014-10-16 12:38:18 +02:00
parent a36fd419b5
commit cdcbafa311

View file

@ -78,7 +78,11 @@ public class DefaultInfinispanConnectionProviderFactory implements InfinispanCon
private void initEmbedded() { private void initEmbedded() {
GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder();
if (config.getBoolean("transport", false)) {
boolean clustered = config.getBoolean("clustered", false);
boolean async = config.getBoolean("async", true);
if (clustered) {
gcb.transport().defaultTransport(); gcb.transport().defaultTransport();
} }
cacheManager = new DefaultCacheManager(gcb.build()); cacheManager = new DefaultCacheManager(gcb.build());
@ -86,35 +90,32 @@ public class DefaultInfinispanConnectionProviderFactory implements InfinispanCon
logger.debug("Started embedded Infinispan cache container"); logger.debug("Started embedded Infinispan cache container");
cacheManager.defineConfiguration("sessions", createConfiguration("sessions")); ConfigurationBuilder invalidationConfigBuilder = new ConfigurationBuilder();
cacheManager.defineConfiguration("realms", createConfiguration("realms")); if (clustered) {
} invalidationConfigBuilder.clustering().cacheMode(async ? CacheMode.INVALIDATION_ASYNC : CacheMode.INVALIDATION_SYNC);
}
Configuration invalidationCacheConfiguration = invalidationConfigBuilder.build();
private Configuration createConfiguration(String cacheName) { cacheManager.defineConfiguration("realms", invalidationCacheConfiguration);
Config.Scope cacheConfig = config.scope("caches", cacheName); cacheManager.defineConfiguration("users", invalidationCacheConfiguration);
ConfigurationBuilder cb = new ConfigurationBuilder();
String cacheMode = cacheConfig.get("cacheMode", "local"); ConfigurationBuilder sessionConfigBuilder = new ConfigurationBuilder();
boolean async = cacheConfig.getBoolean("async", false); if (clustered) {
String sessionsMode = config.get("sessionsMode", "distributed");
if (sessionsMode.equalsIgnoreCase("replicated")) {
sessionConfigBuilder.clustering().cacheMode(async ? CacheMode.REPL_ASYNC : CacheMode.REPL_SYNC);
} else if (sessionsMode.equalsIgnoreCase("distributed")) {
sessionConfigBuilder.clustering().cacheMode(async ? CacheMode.DIST_ASYNC : CacheMode.DIST_SYNC);
} else {
throw new RuntimeException("Invalid value for sessionsMode");
}
if (cacheMode.equalsIgnoreCase("replicated")) { sessionConfigBuilder.clustering().hash()
cb.clustering().cacheMode(async ? CacheMode.REPL_ASYNC : CacheMode.REPL_SYNC); .numOwners(config.getInt("sessionsOwners", 2))
} else if (cacheMode.equalsIgnoreCase("distributed")) { .numSegments(config.getInt("sessionsSegments", 60)).build();
cb.clustering().cacheMode(async ? CacheMode.DIST_ASYNC : CacheMode.DIST_SYNC);
int owners = cacheConfig.getInt("owners", 2);
int segments = cacheConfig.getInt("segments", 60);
cb.clustering().hash().numOwners(owners).numSegments(segments);
} else if (cacheMode.equalsIgnoreCase("invalidation")) {
cb.clustering().cacheMode(async ? CacheMode.INVALIDATION_ASYNC : CacheMode.INVALIDATION_SYNC);
} else if (!cacheMode.equalsIgnoreCase("local")) {
throw new RuntimeException("Invalid cache mode " + cacheMode);
} }
logger.debugv("Configured cache {0} with mode={1}, async={2}", cacheName, cacheMode, async); cacheManager.defineConfiguration("sessions", sessionConfigBuilder.build());
return cb.build();
} }
} }