Search in sources :

Example 1 with SelectArbiter

use of org.apache.logging.log4j.core.config.arbiters.SelectArbiter 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;
}
Also used : SelectArbiter(org.apache.logging.log4j.core.config.arbiters.SelectArbiter) Node(org.apache.logging.log4j.plugins.Node) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Arbiter(org.apache.logging.log4j.core.config.arbiters.Arbiter) SelectArbiter(org.apache.logging.log4j.core.config.arbiters.SelectArbiter)

Aggregations

ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Arbiter (org.apache.logging.log4j.core.config.arbiters.Arbiter)1 SelectArbiter (org.apache.logging.log4j.core.config.arbiters.SelectArbiter)1 Node (org.apache.logging.log4j.plugins.Node)1