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