}
@SuppressWarnings({"rawtypes", "unchecked"})
private ExoCache<? extends Serializable, ?> createCacheInstance(String region) throws Exception
{
ExoCacheConfig config = configs_.get(region);
if (config == null)
config = defaultConfig_;
// Ensure the configuration integrity
final ExoCacheConfig safeConfig = config.clone();
// Set the region as name
safeConfig.setName(region);
ExoCache simple = null;
if (factory_ != DEFAULT_FACTORY && safeConfig.getClass().isAssignableFrom(ExoCacheConfig.class) //NOSONAR
&& safeConfig.getImplementation() != null)
{
// The implementation exists and the config is not a sub class of ExoCacheConfig
// we assume that we expect to use the default cache factory
try
{
// We check if the given implementation is a known class
Class<?> implClass = ClassLoading.loadClass(safeConfig.getImplementation(), this);
// Implementation is an existing class
if (ExoCache.class.isAssignableFrom(implClass))
{
// The implementation is a sub class of eXo Cache so we use the default factory
simple = DEFAULT_FACTORY.createCache(safeConfig);
}
}
catch (ClassNotFoundException e)
{
if (LOG.isTraceEnabled())
{
LOG.trace("An exception occurred: " + e.getMessage());
}
}
}
if (simple == null)
{
// We use the configured cache factory
simple = factory_.createCache(safeConfig);
}
if (managed != null)
{
managed.registerCache(simple);
}
// If the flag avoid value replication is enabled and the cache is replicated
// or distributed we wrap the eXo cache instance into an InvalidationExoCache
// to enable the invalidation
return safeConfig.avoidValueReplication() && (safeConfig.isRepicated() || safeConfig.isDistributed())
? new InvalidationExoCache(simple) : simple;
}