001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017package org.apache.logging.log4j.core.config.arbiters; 018 019import java.util.List; 020import java.util.Optional; 021 022import org.apache.logging.log4j.core.config.Node; 023import org.apache.logging.log4j.core.config.plugins.Plugin; 024import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; 025 026/** 027 * Class Description goes here. 028 */ 029@Plugin(name = "Select", category = Node.CATEGORY, elementType = Arbiter.ELEMENT_TYPE, deferChildren = true, 030 printObject = true) 031public class SelectArbiter { 032 033 public Arbiter evaluateConditions(List<Arbiter> conditions) { 034 Optional<Arbiter> opt = conditions.stream().filter((c) -> c instanceof DefaultArbiter) 035 .reduce((a, b) -> { 036 throw new IllegalStateException("Multiple elements: " + a + ", " + b); 037 }); 038 for (Arbiter condition : conditions) { 039 if (condition instanceof DefaultArbiter) { 040 continue; 041 } 042 if (condition.isCondition()) { 043 return condition; 044 } 045 } 046 return opt.orElse(null); 047 } 048 049 @PluginBuilderFactory 050 public static Builder newBuilder() { 051 return new Builder(); 052 } 053 054 public static class Builder implements org.apache.logging.log4j.core.util.Builder<SelectArbiter> { 055 056 public Builder asBuilder() { 057 return this; 058 } 059 060 public SelectArbiter build() { 061 return new SelectArbiter(); 062 } 063 } 064}