public ExoCache<Serializable, Object> createCache(final ExoCacheConfig config) throws ExoCacheInitException
{
final String region = config.getName();
final String customConfig = mappingCacheNameConfig.get(region);
final ExoCache<Serializable, Object> eXoCache;
final DefaultCacheManager cacheManager;
try
{
final ConfigurationBuilder confBuilder = new ConfigurationBuilder();
if (customConfig != null)
{
try
{
cacheManager =
SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<DefaultCacheManager>()
{
public DefaultCacheManager run() throws Exception
{
// A custom configuration has been set
if (LOG.isInfoEnabled())
LOG.info("A custom configuration has been set for the cache '" + region + "'.");
Parser parser = new Parser(Thread.currentThread().getContextClassLoader());
// Load the configuration
ConfigurationBuilderHolder holder = parser.parse(configManager.getInputStream(customConfig));
GlobalConfigurationBuilder configBuilder = holder.getGlobalConfigurationBuilder();
// Configure JGroups and JMX since it could affect the state of the Global Config
configureCacheManager(configBuilder);
GlobalConfiguration gc = configBuilder.build();
// Check if a CacheManager with the same GlobalConfiguration exists
DefaultCacheManager currentCacheManager =
mappingGlobalConfigCacheManager.get(gc.transport().clusterName());
if (currentCacheManager == null)
{
// Use a different cache manager name to prevent naming conflict
configBuilder.globalJmxStatistics().cacheManagerName(
gc.globalJmxStatistics().cacheManagerName() + "_" + region + "_" + ctx.getName());
// No cache manager has been defined so far for this Cache Configuration
currentCacheManager =
new DefaultCacheManager(configBuilder.build(), holder.getDefaultConfigurationBuilder()
.build(), false);
for (Entry<String, ConfigurationBuilder> entry : holder.getNamedConfigurationBuilders().entrySet())
{
currentCacheManager.defineConfiguration(entry.getKey(), entry.getValue().build());
}
currentCacheManager.start();
// We register this new cache manager
mappingGlobalConfigCacheManager.put(gc.transport().clusterName(), currentCacheManager);
}
return currentCacheManager;
}