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 * @version $Revision: 14059 $ 055 */ 056 @XmlRootElement 057 @XmlAccessorType(XmlAccessType.FIELD) 058 public class BatchResequencerConfig { 059 060 @XmlAttribute 061 private Integer batchSize; // optional XML attribute requires wrapper object 062 063 @XmlAttribute 064 private Long batchTimeout; // optional XML attribute requires wrapper object 065 066 /** 067 * Creates a new {@link BatchResequencerConfig} instance using default 068 * values for <code>batchSize</code> (100) and <code>batchTimeout</code> 069 * (1000L). 070 */ 071 public BatchResequencerConfig() { 072 this(100, 1000L); 073 } 074 075 /** 076 * Creates a new {@link BatchResequencerConfig} instance using the given 077 * values for <code>batchSize</code> and <code>batchTimeout</code>. 078 * 079 * @param batchSize 080 * size of the batch to be re-ordered. 081 * @param batchTimeout 082 * timeout for collecting elements to be re-ordered. 083 */ 084 public BatchResequencerConfig(int batchSize, long batchTimeout) { 085 this.batchSize = batchSize; 086 this.batchTimeout = batchTimeout; 087 } 088 089 /** 090 * Returns a new {@link BatchResequencerConfig} instance using default 091 * values for <code>batchSize</code> (100) and <code>batchTimeout</code> 092 * (1000L). 093 * 094 * @return a default {@link BatchResequencerConfig}. 095 */ 096 public static BatchResequencerConfig getDefault() { 097 return new BatchResequencerConfig(); 098 } 099 100 public int getBatchSize() { 101 return batchSize; 102 } 103 104 public void setBatchSize(int batchSize) { 105 this.batchSize = batchSize; 106 } 107 108 public long getBatchTimeout() { 109 return batchTimeout; 110 } 111 112 public void setBatchTimeout(long batchTimeout) { 113 this.batchTimeout = batchTimeout; 114 } 115 116 }