use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXmlParser method createDeclarable.
/**
* Creates and initializes an instance of {@link Declarable} from the contents of the stack.
*
* @throws CacheXmlException Something goes wrong while instantiating or initializing the
* declarable
*/
private Declarable createDeclarable() {
Properties props = new Properties();
Object top = stack.pop();
while (top instanceof Parameter) {
Parameter param = (Parameter) top;
props.put(param.getName(), param.getValue());
top = stack.pop();
}
logger.trace(LogMarker.CACHE_XML_PARSER, LocalizedMessage.create(LocalizedStrings.CacheXmlParser_XML_PARSER_CREATEDECLARABLE_PROPERTIES__0, props));
Assert.assertTrue(top instanceof String);
String className = (String) top;
logger.trace(LogMarker.CACHE_XML_PARSER, LocalizedMessage.create(LocalizedStrings.CacheXmlParser_XML_PARSER_CREATEDECLARABLE_CLASS_NAME_0, className));
Object o;
try {
Class c = InternalDataSerializer.getCachedClass(className);
o = c.newInstance();
} catch (Exception ex) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_WHILE_INSTANTIATING_A_0.toLocalizedString(className), ex);
}
if (!(o instanceof Declarable)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_CLASS_0_IS_NOT_AN_INSTANCE_OF_DECLARABLE.toLocalizedString(className));
}
Declarable d = (Declarable) o;
d.init(props);
this.cache.addDeclarableProperties(d, props);
return d;
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXmlParser method endCacheLoader.
/**
* When a <code>cache-loader</code> element is finished, the {@link Parameter}s and class names
* are popped off the stack. The cache loader is instantiated and initialized with the parameters,
* if appropriate. When the loader is being created in a dynamic-region-factory, there may be a
* disk-dir element on the stack, represented by a File object. Otherwise, dynamic-region-factory
* uses a RegionAttributesCreation, just like a region, and is treated the same.<p) The loader may
* also be created in the context of partition-attributes.
*/
private void endCacheLoader() {
Declarable d = createDeclarable();
if (!(d instanceof CacheLoader)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_CACHELOADER.toLocalizedString(d.getClass().getName()));
}
// Two peeks required to handle dynamic region context
Object a = stack.peek();
// check for disk-dir
if ((a instanceof File)) {
Object sav = stack.pop();
a = stack.peek();
if (!(a instanceof RegionAttributesCreation)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_CACHELOADER_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_REGIONATTRIBUTES.toLocalizedString());
}
stack.push(sav);
RegionAttributesCreation attrs = (RegionAttributesCreation) a;
attrs.setCacheLoader((CacheLoader) d);
} else // check for normal region-attributes
if (a instanceof RegionAttributesCreation) {
RegionAttributesCreation attrs = (RegionAttributesCreation) a;
attrs.setCacheLoader((CacheLoader) d);
} else {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_REGIONATTRIBUTES_OR_1.toLocalizedString(new Object[] { CACHE_LOADER, DYNAMIC_REGION_FACTORY }));
}
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXmlParser method endLRUHeapPercentage.
/**
* Complete the configuration of a <code>lru-heap-percentage</code> eviction controller. Check for
* the declaration of an {@link ObjectSizer}. Assign the attributes to the enclosed
* <code>region-attributes</code>
*/
private void endLRUHeapPercentage() {
Object declCheck = stack.peek();
Declarable d = null;
if (declCheck instanceof String || declCheck instanceof Parameter) {
d = createDeclarable();
if (!(d instanceof ObjectSizer)) {
String s = "A " + d.getClass().getName() + " is not an instance of a ObjectSizer";
throw new CacheXmlException(s);
}
}
EvictionAttributesImpl eai = (EvictionAttributesImpl) stack.pop();
if (d != null) {
eai.setObjectSizer((ObjectSizer) d);
}
RegionAttributesCreation regAttrs = peekRegionAttributesContext(LRU_HEAP_PERCENTAGE);
regAttrs.setEvictionAttributes(eai);
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXmlParser method endLoadProbe.
/**
* When a <code>load-probe</code> element is encountered, create a new probe for the current
* <code>CacheServer</code>.
*
* @since GemFire 5.7
*/
private void endLoadProbe() {
Declarable d = createDeclarable();
if (!(d instanceof ServerLoadProbe)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_1.toLocalizedString(new Object[] { d.getClass().getName(), "BridgeLoadProbe" }));
}
stack.push(d);
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXmlParser method endPartitionResolver.
/**
* When a <code>partition-resolver</code> element is finished, the {@link Parameter}s and class
* names are popped off the stack. The <code>PartitionResolver</code> is instantiated and
* initialized with the parameters, if appropriate.
*/
private void endPartitionResolver() {
Declarable d = createDeclarable();
if (!(d instanceof PartitionResolver)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_1.toLocalizedString(new Object[] { d.getClass().getName(), "PartitionResolver" }));
}
PartitionAttributesImpl pai = peekPartitionAttributesImpl(PARTITION_ATTRIBUTES);
pai.setPartitionResolver((PartitionResolver) d);
}
Aggregations