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.camel.model.config; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023import javax.xml.bind.annotation.XmlTransient; 024 025import org.apache.camel.processor.resequencer.ExpressionResultComparator; 026import org.apache.camel.spi.Metadata; 027 028/** 029 * Configures stream-processing resequence eip. 030 */ 031@Metadata(label = "eip,routing,resequence") 032@XmlRootElement(name = "stream-config") 033@XmlAccessorType(XmlAccessType.FIELD) 034public class StreamResequencerConfig extends ResequencerConfig { 035 @XmlAttribute 036 @Metadata(defaultValue = "100", javaType = "java.lang.Integer") 037 private String capacity; 038 @XmlAttribute 039 @Metadata(defaultValue = "1s", javaType = "java.time.Duration") 040 private String timeout; 041 @XmlAttribute 042 @Metadata(defaultValue = "1s", javaType = "java.time.Duration") 043 private String deliveryAttemptInterval; 044 @XmlAttribute 045 @Metadata(javaType = "java.lang.Boolean") 046 private String ignoreInvalidExchanges; 047 @XmlTransient 048 private ExpressionResultComparator comparator; 049 @XmlAttribute 050 private String comparatorRef; 051 @XmlAttribute 052 @Metadata(javaType = "java.lang.Boolean") 053 private String rejectOld; 054 055 /** 056 * Creates a new {@link StreamResequencerConfig} instance using default 057 * values for <code>capacity</code> (1000) and <code>timeout</code> (1000L). 058 * Elements of the sequence are compared using the default 059 * {@link ExpressionResultComparator}. 060 */ 061 public StreamResequencerConfig() { 062 this(1000, 1000L); 063 } 064 065 /** 066 * Creates a new {@link StreamResequencerConfig} instance using the given 067 * values for <code>capacity</code> and <code>timeout</code>. Elements of 068 * the sequence are compared using the default 069 * {@link ExpressionResultComparator}. 070 * 071 * @param capacity capacity of the resequencer's inbound queue. 072 * @param timeout minimum time to wait for missing elements (messages). 073 */ 074 public StreamResequencerConfig(int capacity, long timeout) { 075 this(capacity, timeout, null, null); 076 } 077 078 /** 079 * Creates a new {@link StreamResequencerConfig} instance using the given 080 * values for <code>capacity</code> and <code>timeout</code>. Elements of 081 * the sequence are compared with the given 082 * {@link ExpressionResultComparator}. 083 * 084 * @param capacity capacity of the resequencer's inbound queue. 085 * @param timeout minimum time to wait for missing elements (messages). 086 * @param comparator comparator for sequence comparision 087 */ 088 public StreamResequencerConfig(int capacity, long timeout, ExpressionResultComparator comparator) { 089 this(capacity, timeout, null, comparator); 090 } 091 092 /** 093 * Creates a new {@link StreamResequencerConfig} instance using the given 094 * values for <code>capacity</code> and <code>timeout</code>. Elements of 095 * the sequence are compared using the default 096 * {@link ExpressionResultComparator}. 097 * 098 * @param capacity capacity of the resequencer's inbound queue. 099 * @param timeout minimum time to wait for missing elements (messages). 100 * @param rejectOld if true, throws an exception when messages older than 101 * the last delivered message are processed 102 */ 103 public StreamResequencerConfig(int capacity, long timeout, Boolean rejectOld) { 104 this(capacity, timeout, rejectOld, null); 105 } 106 107 /** 108 * Creates a new {@link StreamResequencerConfig} instance using the given 109 * values for <code>capacity</code> and <code>timeout</code>. Elements of 110 * the sequence are compared with the given 111 * {@link ExpressionResultComparator}. 112 * 113 * @param capacity capacity of the resequencer's inbound queue. 114 * @param timeout minimum time to wait for missing elements (messages). 115 * @param rejectOld if true, throws an exception when messages older than 116 * the last delivered message are processed 117 * @param comparator comparator for sequence comparision 118 */ 119 public StreamResequencerConfig(int capacity, long timeout, Boolean rejectOld, ExpressionResultComparator comparator) { 120 this.capacity = Integer.toString(capacity); 121 this.timeout = Long.toString(timeout); 122 this.rejectOld = rejectOld != null ? Boolean.toString(rejectOld) : null; 123 this.comparator = comparator; 124 } 125 126 /** 127 * Returns a new {@link StreamResequencerConfig} instance using default 128 * values for <code>capacity</code> (1000) and <code>timeout</code> (1000L). 129 * Elements of the sequence are compared using the default 130 * {@link ExpressionResultComparator}. 131 * 132 * @return a default {@link StreamResequencerConfig}. 133 */ 134 public static StreamResequencerConfig getDefault() { 135 return new StreamResequencerConfig(); 136 } 137 138 public String getCapacity() { 139 return capacity; 140 } 141 142 /** 143 * Sets the capacity of the resequencer's inbound queue. 144 */ 145 public void setCapacity(String capacity) { 146 this.capacity = capacity; 147 } 148 149 public String getTimeout() { 150 return timeout; 151 } 152 153 /** 154 * Sets minimum time to wait for missing elements (messages). 155 */ 156 public void setTimeout(String timeout) { 157 this.timeout = timeout; 158 } 159 160 public String getDeliveryAttemptInterval() { 161 return deliveryAttemptInterval; 162 } 163 164 /** 165 * Sets the interval in milli seconds the stream resequencer will at most 166 * wait while waiting for condition of being able to deliver. 167 */ 168 public void setDeliveryAttemptInterval(String deliveryAttemptInterval) { 169 this.deliveryAttemptInterval = deliveryAttemptInterval; 170 } 171 172 public String getIgnoreInvalidExchanges() { 173 return ignoreInvalidExchanges; 174 } 175 176 /** 177 * Whether to ignore invalid exchanges 178 */ 179 public void setIgnoreInvalidExchanges(String ignoreInvalidExchanges) { 180 this.ignoreInvalidExchanges = ignoreInvalidExchanges; 181 } 182 183 public ExpressionResultComparator getComparator() { 184 return comparator; 185 } 186 187 /** 188 * To use a custom comparator 189 */ 190 public void setComparator(ExpressionResultComparator comparator) { 191 this.comparator = comparator; 192 } 193 194 public String getComparatorRef() { 195 return comparatorRef; 196 } 197 198 /** 199 * To use a custom comparator 200 */ 201 public void setComparatorRef(String comparatorRef) { 202 this.comparatorRef = comparatorRef; 203 } 204 205 /** 206 * If true, throws an exception when messages older than the last delivered 207 * message are processed 208 */ 209 public void setRejectOld(String value) { 210 this.rejectOld = value; 211 } 212 213 public String getRejectOld() { 214 return rejectOld; 215 } 216 217}