Merge pull request #768 from stianst/master
Simplified embedded infinispan connection config
This commit is contained in:
commit
a882f95749
1 changed files with 26 additions and 25 deletions
|
@ -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();
|
||||||
|
|
||||||
|
cacheManager.defineConfiguration("realms", invalidationCacheConfiguration);
|
||||||
|
cacheManager.defineConfiguration("users", invalidationCacheConfiguration);
|
||||||
|
|
||||||
|
ConfigurationBuilder sessionConfigBuilder = new ConfigurationBuilder();
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Configuration createConfiguration(String cacheName) {
|
sessionConfigBuilder.clustering().hash()
|
||||||
Config.Scope cacheConfig = config.scope("caches", cacheName);
|
.numOwners(config.getInt("sessionsOwners", 2))
|
||||||
ConfigurationBuilder cb = new ConfigurationBuilder();
|
.numSegments(config.getInt("sessionsSegments", 60)).build();
|
||||||
|
|
||||||
String cacheMode = cacheConfig.get("cacheMode", "local");
|
|
||||||
boolean async = cacheConfig.getBoolean("async", false);
|
|
||||||
|
|
||||||
if (cacheMode.equalsIgnoreCase("replicated")) {
|
|
||||||
cb.clustering().cacheMode(async ? CacheMode.REPL_ASYNC : CacheMode.REPL_SYNC);
|
|
||||||
} else if (cacheMode.equalsIgnoreCase("distributed")) {
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue