}
@SuppressWarnings("unchecked")
private EvictionRegionConfig getEvictionRegionConfig(Element element, EvictionRegionConfig defaultRegion, boolean isDefault)
{
EvictionRegionConfig erc = new EvictionRegionConfig();
erc.setRegionName(getAttributeValue(element, "name"));
String queueSize = getAttributeValue(element, "eventQueueSize");
if (existsAttribute(queueSize))
{
erc.setEventQueueSize(getInt(queueSize));
}
else if (defaultRegion == null)
{
erc.setEventQueueSize(EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
}
String algorithmClassName = getAttributeValue(element, "algorithmClass");
EvictionAlgorithmConfig algorithmConfig = null; // every eviction region config needs an algorithm config.
if (existsAttribute(algorithmClassName))
{
EvictionAlgorithm algorithm;
Class<? extends EvictionAlgorithm> algorithmClass;
// try using a 'getInstance()' factory.
try
{
algorithmClass = Util.loadClass(algorithmClassName);
}
catch (Exception e)
{
throw new RuntimeException("Unable to load eviction algorithm class [" + algorithmClassName + "]", e);
}
try
{
algorithm = Util.getInstance(algorithmClass);
}
catch (Exception e)
{
throw new ConfigurationException("Unable to construct eviction algorithm class [" + algorithmClassName + "]", e);
}
try
{
algorithmConfig = Util.getInstance(algorithm.getConfigurationClass());
}
catch (Exception e)
{
throw new RuntimeException("Failed to instantiate eviction algorithm configuration class [" +
algorithm.getConfigurationClass() + "]", e);
}
}
else
{
if (!isDefault)
{
if (defaultRegion == null || defaultRegion.getEvictionAlgorithmConfig() == null)
{
throw new MissingPolicyException("There is no Eviction Algorithm Class specified on the region or for the entire cache!");
}
else
{
try
{
algorithmConfig = defaultRegion.getEvictionAlgorithmConfig().clone();
}
catch (CloneNotSupportedException e)
{
throw new ConfigurationException("Unable to clone eviction algorithm configuration from default", e);
}
}
}
}
if (algorithmConfig != null)
{
parseEvictionPolicyConfig(element, algorithmConfig);
erc.setEvictionAlgorithmConfig(algorithmConfig);
}
String actionPolicyClass = getAttributeValue(element, "actionPolicyClass");
if (existsAttribute(actionPolicyClass))
{
erc.setEvictionActionPolicyClassName(actionPolicyClass);
}
else if (defaultRegion == null)
{
// this is the default region. Make sure we set the default EvictionActionPolicyClass.
erc.setEvictionActionPolicyClassName(EvictionConfig.EVICTION_ACTION_POLICY_CLASS_DEFAULT);
}
return erc;
}