use of org.apache.logging.log4j.core.config.arbiters.Arbiter in project logging-log4j2 by apache.
the class AbstractConfiguration method processSelect.
/**
* Handle Select nodes. This finds the first child condition that returns true and attaches its children
* to the parent of the Select Node. Other Nodes are discarded.
* @param selectNode The Select Node.
* @param type The PluginType of the Select Node.
* @return The list of Nodes to be added to the parent.
*/
protected List<Node> processSelect(final Node selectNode, final PluginType<?> type) {
final List<Node> addList = new ArrayList<>();
final SelectArbiter select = (SelectArbiter) createPluginObject(type, selectNode, null);
final List<Arbiter> conditions = new ArrayList<>();
for (final Node child : selectNode.getChildren()) {
final PluginType<?> nodeType = child.getType();
if (nodeType != null) {
if (Arbiter.class.isAssignableFrom(nodeType.getPluginClass())) {
final Arbiter condition = (Arbiter) createPluginObject(nodeType, child, null);
conditions.add(condition);
child.setObject(condition);
} else {
LOGGER.error("Invalid Node {} for Select. Must be a Condition", child.getName());
}
} else {
LOGGER.error("No PluginType for node {}", child.getName());
}
}
final Arbiter condition = select.evaluateConditions(conditions);
if (condition != null) {
for (final Node child : selectNode.getChildren()) {
if (condition == child.getObject()) {
addList.addAll(child.getChildren());
processConditionals(child);
}
}
}
return addList;
}
use of org.apache.logging.log4j.core.config.arbiters.Arbiter in project logging-log4j2 by apache.
the class AbstractConfiguration method processConditionals.
/**
* Process conditions by evaluating them and including the children of conditions that are true
* and discarding those that are not.
* @param node The node to evaluate.
*/
protected void processConditionals(final Node node) {
try {
final List<Node> addList = new ArrayList<>();
final List<Node> removeList = new ArrayList<>();
for (final Node child : node.getChildren()) {
final PluginType<?> type = child.getType();
if (type != null && Arbiter.ELEMENT_TYPE.equals(type.getElementName())) {
final Class<?> clazz = type.getPluginClass();
if (SelectArbiter.class.isAssignableFrom(clazz)) {
removeList.add(child);
addList.addAll(processSelect(child, type));
} else if (Arbiter.class.isAssignableFrom(clazz)) {
removeList.add(child);
try {
final Arbiter condition = (Arbiter) createPluginObject(type, child, null);
if (condition.isCondition()) {
addList.addAll(child.getChildren());
processConditionals(child);
}
} catch (final Exception inner) {
LOGGER.error("Exception processing {}: Ignoring and including children", type.getPluginClass());
processConditionals(child);
}
} else {
LOGGER.error("Encountered Condition Plugin that does not implement Condition: {}", child.getName());
processConditionals(child);
}
} else {
processConditionals(child);
}
}
if (!removeList.isEmpty()) {
final List<Node> children = node.getChildren();
children.removeAll(removeList);
children.addAll(addList);
for (final Node grandChild : addList) {
grandChild.setParent(node);
}
}
} catch (final Exception ex) {
LOGGER.error("Error capturing node data for node " + node.getName(), ex);
}
}
Aggregations