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 */ 017 package org.apache.camel.model.config; 018 019 import javax.xml.bind.annotation.XmlAccessType; 020 import javax.xml.bind.annotation.XmlAccessorType; 021 import javax.xml.bind.annotation.XmlAttribute; 022 import javax.xml.bind.annotation.XmlRootElement; 023 import javax.xml.bind.annotation.XmlTransient; 024 025 import org.apache.camel.Exchange; 026 import org.apache.camel.processor.StreamResequencer; 027 import org.apache.camel.processor.resequencer.DefaultExchangeComparator; 028 import org.apache.camel.processor.resequencer.ExpressionResultComparator; 029 030 /** 031 * Defines the configuration parameters for the {@link StreamResequencer}. 032 * Usage example: 033 * 034 * <pre> 035 * from("direct:start").resequencer(header("seqnum")).stream( 036 * StreamResequencerConfig.getDefault()).to("mock:result") 037 * </pre> 038 * 039 * is equivalent to 040 * 041 * <pre> 042 * from("direct:start").resequencer(header("seqnum")).stream().to("mock:result") 043 * </pre> 044 * 045 * Custom values for <code>capacity</code> and <code>timeout</code> can be 046 * set like in this example: 047 * 048 * <pre> 049 * from("direct:start").resequencer(header("seqnum")).stream( 050 * new StreamResequencerConfig(300, 400L)).to("mock:result") 051 * </pre> 052 * 053 * @version $Revision: 14059 $ 054 */ 055 @XmlRootElement 056 @XmlAccessorType(XmlAccessType.FIELD) 057 public class StreamResequencerConfig { 058 059 @XmlAttribute 060 private Integer capacity; // optional XML attribute requires wrapper object 061 062 @XmlAttribute 063 private Long timeout; // optional XML attribute requires wrapper object 064 065 @XmlTransient 066 private ExpressionResultComparator<Exchange> comparator; 067 068 /** 069 * Creates a new {@link StreamResequencerConfig} instance using default 070 * values for <code>capacity</code> (1000) and <code>timeout</code> 071 * (1000L). Elements of the sequence are compared using the 072 * {@link DefaultExchangeComparator}. 073 */ 074 public StreamResequencerConfig() { 075 this(1000, 1000L); 076 } 077 078 /** 079 * Creates a new {@link BatchResequencerConfig} instance using the given 080 * values for <code>capacity</code> and <code>timeout</code>. Elements 081 * of the sequence are compared using the {@link DefaultExchangeComparator}. 082 * 083 * @param capacity capacity of the resequencer's inbound queue. 084 * @param timeout minimum time to wait for missing elements (messages). 085 */ 086 public StreamResequencerConfig(int capacity, long timeout) { 087 this(capacity, timeout, new DefaultExchangeComparator()); 088 } 089 090 /** 091 * Creates a new {@link BatchResequencerConfig} instance using the given 092 * values for <code>capacity</code> and <code>timeout</code>. Elements 093 * of the sequence are compared with the given 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 */ 099 public StreamResequencerConfig(int capacity, long timeout, ExpressionResultComparator<Exchange> comparator) { 100 this.capacity = capacity; 101 this.timeout = timeout; 102 this.comparator = comparator; 103 } 104 105 /** 106 * Returns a new {@link StreamResequencerConfig} instance using default 107 * values for <code>capacity</code> (1000) and <code>timeout</code> 108 * (1000L). Elements of the sequence are compared using the 109 * {@link DefaultExchangeComparator}. 110 * 111 * @return a default {@link StreamResequencerConfig}. 112 */ 113 public static StreamResequencerConfig getDefault() { 114 return new StreamResequencerConfig(); 115 } 116 117 public int getCapacity() { 118 return capacity; 119 } 120 121 public void setCapacity(int capacity) { 122 this.capacity = capacity; 123 } 124 125 public long getTimeout() { 126 return timeout; 127 } 128 129 public void setTimeout(long timeout) { 130 this.timeout = timeout; 131 } 132 133 public ExpressionResultComparator<Exchange> getComparator() { 134 return comparator; 135 } 136 137 public void setComparator(ExpressionResultComparator<Exchange> comparator) { 138 this.comparator = comparator; 139 } 140 141 }