001/* 002 * (C) Copyright 2017-2018 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * 017 * Contributors: 018 * bdelbosc 019 */ 020package org.nuxeo.runtime.stream; 021 022import java.util.ArrayList; 023import java.util.HashMap; 024import java.util.List; 025import java.util.Map; 026import java.util.stream.Collectors; 027 028import org.nuxeo.common.xmap.annotation.XNode; 029import org.nuxeo.common.xmap.annotation.XNodeList; 030import org.nuxeo.common.xmap.annotation.XNodeMap; 031import org.nuxeo.common.xmap.annotation.XObject; 032import org.nuxeo.runtime.model.Descriptor; 033 034@XObject("logConfig") 035public class LogConfigDescriptor implements Descriptor { 036 // @since 11.1 037 public static final String SEP = ":"; 038 039 // @since 11.1 040 @XNode("@enabled") 041 protected boolean isEnabled = true; 042 043 // @since 11.1 044 @XNode("@default") 045 protected boolean isDefault = false; 046 047 @XObject(value = "log") 048 public static class LogDescriptor implements Descriptor { 049 050 public static final Integer DEFAULT_PARTITIONS = 4; 051 052 @XNode("@name") 053 public String name; 054 055 @XNode("@size") 056 public Integer size = DEFAULT_PARTITIONS; 057 058 @Override 059 public String getId() { 060 return name; 061 } 062 } 063 064 // @since 11.1 065 @XObject(value = "match") 066 public static class LogMatchDescriptor implements Descriptor { 067 068 @XNode("@name") 069 public String name; 070 071 @XNode("@group") 072 public String group; 073 074 @Override 075 public String getId() { 076 return (group != null && !group.isBlank()) ? name + SEP + group : name; 077 } 078 } 079 080 @XNode("@name") 081 public String name; 082 083 @XNode("@type") 084 public String type; 085 086 @XNodeMap(value = "option", key = "@name", type = HashMap.class, componentType = String.class) 087 public Map<String, String> options = new HashMap<>(); 088 089 @XNodeList(value = "log", type = ArrayList.class, componentType = LogDescriptor.class) 090 public List<LogDescriptor> logs = new ArrayList<>(); 091 092 // @since 11.1 093 @XNodeList(value = "match", type = ArrayList.class, componentType = LogMatchDescriptor.class) 094 public List<LogMatchDescriptor> matches = new ArrayList<>(); 095 096 @Override 097 public String getId() { 098 return name; 099 } 100 101 // @since 11.1 102 public boolean isEnabled() { 103 return isEnabled; 104 } 105 106 // @since 11.1 107 public void setEnabled(boolean isEnabled) { 108 this.isEnabled = isEnabled; 109 } 110 111 // @since 11.1 112 public boolean isDefault() { 113 return isDefault; 114 } 115 116 // @since 11.1 117 public boolean onlyLogDeclaration() { 118 return name == null && type == null; 119 } 120 121 // @since 11.1 122 public List<String> getPatterns() { 123 return matches.stream().map(match -> match.getId()).collect(Collectors.toList()); 124 } 125 126}