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