001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.camel.builder;
019
020 import org.apache.camel.Expression;
021 import org.apache.camel.Processor;
022 import org.apache.camel.Route;
023 import org.apache.camel.Exchange;
024 import org.apache.camel.Service;
025 import org.apache.camel.processor.Resequencer;
026
027 import java.util.List;
028
029 /**
030 * @version $Revision: 1.1 $
031 */
032 public class ResequencerBuilder extends FromBuilder {
033 private final List<Expression<Exchange>> expressions;
034 private long batchTimeout = 1000L;
035 private int batchSize = 100;
036
037 public ResequencerBuilder(FromBuilder builder, List<Expression<Exchange>> expressions) {
038 super(builder);
039 this.expressions = expressions;
040 }
041
042 @Override
043 public Route createRoute() throws Exception {
044 final Processor processor = super.createProcessor();
045 final Resequencer resequencer = new Resequencer(getFrom(), processor, expressions);
046 return new Route<Exchange>(getFrom(), resequencer) {
047
048 @Override
049 public String toString() {
050 return "ResequencerRoute[" + getEndpoint() + " -> " + processor + "]";
051 }
052 };
053 }
054
055 // Builder methods
056 //-------------------------------------------------------------------------
057 public ResequencerBuilder batchSize(int batchSize) {
058 setBatchSize(batchSize);
059 return this;
060 }
061
062 public ResequencerBuilder batchTimeout(int batchTimeout) {
063 setBatchTimeout(batchTimeout);
064 return this;
065 }
066
067 // Properties
068 //-------------------------------------------------------------------------
069 public int getBatchSize() {
070 return batchSize;
071 }
072
073 public void setBatchSize(int batchSize) {
074 this.batchSize = batchSize;
075 }
076
077 public long getBatchTimeout() {
078 return batchTimeout;
079 }
080
081 public void setBatchTimeout(long batchTimeout) {
082 this.batchTimeout = batchTimeout;
083 }
084 }