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
024 import org.apache.camel.processor.Resequencer;
025
026 /**
027 * Defines the configuration parameters for the batch-processing
028 * {@link Resequencer}. Usage example:
029 *
030 * <pre>
031 * from("direct:start").resequencer(body()).batch(
032 * BatchResequencerConfig.getDefault()).to("mock:result")
033 * </pre>
034 * is equivalent to
035 *
036 * <pre>
037 * from("direct:start").resequencer(body()).batch().to("mock:result")
038 * </pre>
039 *
040 * or
041 *
042 * <pre>
043 * from("direct:start").resequencer(body()).to("mock:result")
044 * </pre>
045 *
046 * Custom values for <code>batchSize</code> and <code>batchTimeout</code>
047 * can be set like in this example:
048 *
049 * <pre>
050 * from("direct:start").resequencer(body()).batch(
051 * new BatchResequencerConfig(300, 400L)).to("mock:result")
052 * </pre>
053 *
054 * @author Martin Krasser
055 *
056 * @version $Revision: 630568 $
057 */
058 @XmlRootElement
059 @XmlAccessorType(XmlAccessType.FIELD)
060 public class BatchResequencerConfig {
061
062 @XmlAttribute
063 private Integer batchSize; // optional XML attribute requires wrapper object
064
065 @XmlAttribute
066 private Long batchTimeout; // optional XML attribute requires wrapper object
067
068 /**
069 * Creates a new {@link BatchResequencerConfig} instance using default
070 * values for <code>batchSize</code> (100) and <code>batchTimeout</code>
071 * (1000L).
072 */
073 public BatchResequencerConfig() {
074 this(100, 1000L);
075 }
076
077 /**
078 * Creates a new {@link BatchResequencerConfig} instance using the given
079 * values for <code>batchSize</code> and <code>batchTimeout</code>.
080 *
081 * @param batchSize
082 * size of the batch to be re-ordered.
083 * @param batchTimeout
084 * timeout for collecting elements to be re-ordered.
085 */
086 public BatchResequencerConfig(int batchSize, long batchTimeout) {
087 this.batchSize = batchSize;
088 this.batchTimeout = batchTimeout;
089 }
090
091 /**
092 * Returns a new {@link BatchResequencerConfig} instance using default
093 * values for <code>batchSize</code> (100) and <code>batchTimeout</code>
094 * (1000L).
095 *
096 * @return a default {@link BatchResequencerConfig}.
097 */
098 public static BatchResequencerConfig getDefault() {
099 return new BatchResequencerConfig();
100 }
101
102 public int getBatchSize() {
103 return batchSize;
104 }
105
106 public void setBatchSize(int batchSize) {
107 this.batchSize = batchSize;
108 }
109
110 public long getBatchTimeout() {
111 return batchTimeout;
112 }
113
114 public void setBatchTimeout(long batchTimeout) {
115 this.batchTimeout = batchTimeout;
116 }
117
118 }