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(&quot;direct:start&quot;).resequencer(header(&quot;seqnum&quot;)).stream(
034     *         StreamResequencerConfig.getDefault()).to(&quot;mock:result&quot;)
035     * </pre>
036     * 
037     * is equivalent to
038     * 
039     * <pre>
040     * from(&quot;direct:start&quot;).resequencer(header(&quot;seqnum&quot;)).stream().to(&quot;mock:result&quot;)
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(&quot;direct:start&quot;).resequencer(header(&quot;seqnum&quot;)).stream(
048     *         new StreamResequencerConfig(300, 400L)).to(&quot;mock:result&quot;)
049     * </pre>
050     * 
051     * @author Martin Krasser
052     * 
053     * @version $Revision: 751655 $
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 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         * @param comparator comparator for sequence comparision
099         */
100        public StreamResequencerConfig(int capacity, long timeout, ExpressionResultComparator comparator) {
101            this.capacity = capacity;
102            this.timeout = timeout;
103            this.comparator = comparator;
104        }
105    
106        /**
107         * Returns a new {@link StreamResequencerConfig} instance using default
108         * values for <code>capacity</code> (1000) and <code>timeout</code>
109         * (1000L). Elements of the sequence are compared using the
110         * {@link DefaultExchangeComparator}.
111         * 
112         * @return a default {@link StreamResequencerConfig}.
113         */
114        public static StreamResequencerConfig getDefault() {
115            return new StreamResequencerConfig();
116        }
117        
118        public int getCapacity() {
119            return capacity;
120        }
121    
122        public void setCapacity(int capacity) {
123            this.capacity = capacity;
124        }
125    
126        public long getTimeout() {
127            return timeout;
128        }
129    
130        public void setTimeout(long timeout) {
131            this.timeout = timeout;
132        }
133    
134        public ExpressionResultComparator getComparator() {
135            return comparator;
136        }
137    
138        public void setComparator(ExpressionResultComparator comparator) {
139            this.comparator = comparator;
140        }
141        
142    }